-
Notifications
You must be signed in to change notification settings - Fork 51
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
Improvements for cplusplus #1223
Improvements for cplusplus #1223
Conversation
Move includes that are only used by the implementation and not the interface from the .h file to the .c file. Remove unused includes.
Remove the definiton of _FLUX_CORE_KEEPALIVE_H to 1. This just makes it the same as all of the other headers in the directory.
Add 'extern "C"' linkage directive to all of the headers used by the externally accessible flux headers: core.h and optparse.h. It is conditionally added when __cplusplus is defined. These headers should cover the needs of most flux modules. The directive can be added to additional headers as needed. In order to accomodate the new directive, the python "make_binding.py" script needed work. The python CFFI (C Foreign Function Interface) is only able to compile straight C code; it does not have a C preprocessor, nor does it understand the 'extern "C"' linkage directive. make_binding.py preprocesses the headers itself. It honors '#include ""' statements (but intentionally avoids '#include <>') by inlining the requested file. All other macros are simply discarded, including conditionals. Ignoring conditional statements means that the contents of preprocessor conditionals are always included. Potentional two conflicting definitions could appear if there is an #else statement. Code is added to make_binding.py to recognize and handle #ifdef and #ifndef (with or without #else) only when the condition is '__cplusplus'. If this problem arises again we may need to figure out how to save the real C preprocessor output of all of our headers at normal flux compile time, and then feed that to CFFI instead of our quick-and-dirty manual preprocessing. Fixes #1199
C++ is more strict than C about maintaining const correctness. The C++ compiler reports this warning when using the struct flux_msg_handler_spec with flux_msg_handler_addvev(). job-ingest.cpp:50:1: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings] }; We add const to the topic_glob to avoid the warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice cleanup. Thanks for cleaning up extraneous #include in API headers, and for figuring out the python binding issue!
LGTM too. I don't understand why CI failed with Clang though... |
Codecov Report
@@ Coverage Diff @@
## master #1223 +/- ##
==========================================
+ Coverage 78.21% 78.25% +0.03%
==========================================
Files 158 158
Lines 29298 29298
==========================================
+ Hits 22916 22926 +10
+ Misses 6382 6372 -10
|
Looks great, thanks @morrone! |
Some improvements to make flux more friendly to linking with a C++ compiler:
Also some simple header cleanups found along the way.