Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/c api #57

Merged
merged 21 commits into from
Mar 25, 2025
Merged

Feature/c api #57

merged 21 commits into from
Mar 25, 2025

Conversation

ChrisspyB
Copy link
Member

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 88.70968% with 35 lines in your changes missing coverage. Please review.

Project coverage is 62.67%. Comparing base (5156af4) to head (3597d60).

Files with missing lines Patch % Lines
src/metkit/api/metkit_c.cc 83.24% 30 Missing ⚠️
src/metkit/metkit_version.c 25.00% 3 Missing ⚠️
tests/test_c_api.cc 98.36% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #57      +/-   ##
===========================================
+ Coverage    61.31%   62.67%   +1.35%     
===========================================
  Files          102      106       +4     
  Lines         6414     6725     +311     
  Branches       611      634      +23     
===========================================
+ Hits          3933     4215     +282     
- Misses        2481     2510      +29     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChrisspyB ChrisspyB requested a review from tbkr December 16, 2024 09:43
@ChrisspyB ChrisspyB marked this pull request as ready for review December 16, 2024 09:43
Copy link

@tbkr tbkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the changes. Code and Documentation was extraordinarily clean. I was a bit nitpicky. Bear with me in case some of my suggestions are not compatible with modern C; it has been a while since I programmed in C ;)

/// @comment: (maby)
/// Not sure if there is much value in having a param iterator. We could just return an array of
/// strings (char**) using metkit_marsrequest_params.
/// I think we should metkit_paramiterator_t.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the comment is lacking some words. Do this need to be addressed before merging?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a todo left for me by me

Copy link

@Ozaq Ozaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need an extra test where you use the API and compile the test with a C compiler

* @param it RequestIterator instance
* @return int Error code
*/
int metkit_requestiterator_next(metkit_requestiterator_t* it);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would make for a nicer API if we could use it like this:

while((res = metkit_paramiterator_next(it))) {
   //...
}

Ofc this would only work if the iteration cannot create errors. But return a nullptr on end of iteration makes for a more natural api imo.

/// Not sure if there is much value in having a param iterator. We could just return an array of
/// strings (char**) using metkit_marsrequest_params.
/// I think we should metkit_paramiterator_t.
struct metkit_paramiterator_t {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lifetimes of returned values in this iterator differ from the metkit_requestiterator_t iterator. For itself the lifetime is ok (if documented) but a subtle difference in lifetime handling with both types imply symmetrical behavior is a nasty trap. metkit_requestiterator_t result lifetimes exceed the iterator due to the move out of the iterator, while the char* from this iterator dangle as soon as the iterator is freed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially resolved this by simply getting rid of the paramiterator. But it turns out it's not so straight forward as the C++ marsrequest object does not provide a nice way to iterate over the params so I need to revisit this.

@ChrisspyB
Copy link
Member Author

ChrisspyB commented Dec 20, 2024

You need an extra test where you use the API and compile the test with a C compiler

Maybe we should rewrite test_metkit_c.cc in C? For the time being I'll add a simple test that at least uses a C compiler

@ChrisspyB
Copy link
Member Author

Re: error handling, if we're going to do similar across the stack, it might make sense to centralise this somewhere (eckit). All of the caught exceptions are in fact eckit::exceptions

@ChrisspyB ChrisspyB requested a review from simondsmart January 27, 2025 16:00
@ChrisspyB
Copy link
Member Author

Note:
Because FDB takes a marsrequest_t (opaque C pointer) from metkit and casts it to a MarsRequest C++ object both libraries must share a compatible C++ ABI. e.g., we'd have problems if metkit is compiled with Intel and FDB with gnu.

This may not be what a user expects when using the C APIs.

@ChrisspyB ChrisspyB mentioned this pull request Mar 12, 2025
@ChrisspyB ChrisspyB requested a review from tbkr March 25, 2025 13:57
@@ -4,7 +4,7 @@ ecbuild_generate_config_headers( DESTINATION ${INSTALL_INCLUDE_DIR}/metkit )

configure_file( metkit_config.h.in metkit_config.h )
configure_file( metkit_version.h.in metkit_version.h )
configure_file( metkit_version.cc.in metkit_version.cc )
configure_file( metkit_version.c.in ${CMAKE_CURRENT_BINARY_DIR}/metkit_version.c )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the .c configuration

@simondsmart simondsmart merged commit 55dda63 into develop Mar 25, 2025
152 checks passed
@simondsmart simondsmart deleted the feature/c-api branch March 25, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants