-
Notifications
You must be signed in to change notification settings - Fork 140
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
[FIXED] C++ compiler errors #832
Conversation
Fixes the case where C++ compiler errors with C2079 on C style struct definitions. Also added a simple cpp file to make sure future changes won't cause the same issue.
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.
There are lot of build failures in GA (some may be unrelated and a temporary issue). But regardless, I think that the changes are not necessary since no application (cpp or c) should include natsp.h
directly.
examples/check_cpp.cpp
Outdated
@@ -0,0 +1,3 @@ | |||
// Check if the C++ compiler is working | |||
// against C style struct definitions. | |||
#include "natsp.h" |
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.
This file is private: the p
is for private. No application should include this file directly. Actually, it should not even be available if the make install
since they would have access only to the nats.h
file (not the private version).
So I would remove this file (which by the way does not compile - see Windows GA failure) and undo the change in examples/CMakeLists.txt
.
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.
no you're right when the library is installed natsp.h isn't available. I guess it's only affecting the source copy builds.
Do you think having a some form of cpp file for at least making sure C++ compiler will be happy in these kinds of scenarios is a good thing? if so how would you go about adding a cpp file to the build?
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.
No, because again, we should not have an app include nastp.h
, so there is no need to have that "work". See the other comment I just posted regarding the extraction of the js option.
* | ||
* Part of #jsOptions. | ||
*/ | ||
typedef struct jsOptionsPullSubscribeAsync |
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.
I have no issue making the jsOptionsPullSubscribeAsync
a typedef structure, instead of being "embedded" in jsOpts
, but if the issue is only because a user tries to include natsp.h
, then I would not consider changing anything.
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.
yes I think that is the case. do you think moving to typedefs is still worth while for future proofing?
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.
At this point no (seeing all the build failures).
At the very least, what you could do is update the PR by removing the cpp file and changes to examples' make file. Keep the changes in nats.h. Assuming there is no build issue, this PR should still be updated because then we would need to require a new version here because the header is changed.
If there is still build failures, have a new branch that is just pointing to main and push to see if CI still has build issues. If not, then let's close this PR. If there is still build issues, they may be temporary and I would feel better wait for those issues to be resolved with the main branch before trying to include this modified PR.
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.
We got into the current state because we include natsp.h
because we wrote our own watcher around the kvWatcher
. We did that so we could invoke a callback on the data. This is all before I got here. I will be looking into the NATS API around this private data structure as soon as I post this, so I haven't yet looked at the API as it exists. Is there an API that would invoke a callback per message that we either missed, or you added after this implementation?
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.
ok removed the cpp and reverted cmake. build seems fine now apart from couple of flappers presumably.
edit: should I move rest of the nested definitions for consistency?
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.
@mtmk Then we should still update the main make file as I mentioned earlier. That being said, it could be done as part of the next release. Also, we need to make sure that this PR does not end-up in the patch release. @levb can confirm.
Also, @PhilBarila does that mean that you are using other internals? That would not be too good, but regardless, if the change in this PR is enough to "fix" your issue, then fine.
In that case, @mtmk, the check.cpp may instead be in the test directory. It could be a subdirectory, similar to this. It would also need to be added to the tests to run like we do it here.
If this is confusing, I could do that as a separate PR later. Let me know.
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.
The kvWatcher
is the only thing we used from the natsp.h
. If you have an alternative to writing our own jet-stream watcher, we'll take a very serious look at it ...
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.
Is there an API that would invoke a callback per message that we either missed, or you added after this implementation?
@PhilBarila, you can create a watcher, but they are sync by nature, so you need to call their "next" API. I am not sure what you did exactly using the internal structure, so it is difficult for me to say if there is equivalent or not (if it is just to be a callback instead of a sync call, it sounds like a thread calling kvWatcher_Next() and invoking your callback with the result may be enough)
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.
And pull the data out of it with kvEntry_Value
... I'll have to do more digging, but that might work. I am only just wading in, so there's lots more to learn before we have a clean path forward to stop depending on your private data ... But we'll get it done as soon as is practical with all the other competing priorities ...
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #832 +/- ##
==========================================
+ Coverage 68.71% 70.47% +1.76%
==========================================
Files 39 47 +8
Lines 15207 15367 +160
Branches 3143 3149 +6
==========================================
+ Hits 10449 10830 +381
+ Misses 1700 1501 -199
+ Partials 3058 3036 -22 ☔ View full report in Codecov by Sentry. |
As the one who brought this up, I appreciate your prompt attention. It looks just like what I would have offered. Thank you very kindly. |
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.
It fails to compile on Travis for some build runs, so I wonder if that would work if we statically link, you could give it a try.
test/check_cpp/check_cpp.cpp
Outdated
@@ -0,0 +1,29 @@ | |||
// Copyright 2017-2018 The NATS Authors |
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.
Change date to 2025.
if(NOT BUILD_TESTING) | ||
return() | ||
endif() | ||
|
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.
There are failures on Travis for clang with sanitize. Not exactly sure why. So maybe try to build statically, so add this to this make file.
test/check_cpp/CMakeLists.txt
Outdated
# Build the test program | ||
add_executable(check_cpp check_cpp.cpp) | ||
|
||
target_link_libraries(check_cpp nats ${NATS_EXTRA_LIB}) |
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.
Replace nats
with nats_static
.
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.
👍 that worked - current failures seem to be flappers although both travis builds failed on ReconnectFailsPendingRequest
src/nats.h
Outdated
} Info; ///< Optional stream information retrieval options. | ||
|
||
} Stream; ///< Optional stream options. | ||
jsOptionsPublishAsync PublishAsync; ///< extra options for #js_PublishAsync |
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.
nit: If you could align PublishAsync;
, PullSubscribeAsync;
and Stream
fields, that would be nice.
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.
LGTM
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.
LGTM, ack that this is not for the patch release
Fixes the case where C++ compiler errors with C2079 on C style struct definitions. Also added a simple cpp file to make sure future changes won't cause the same issue.
Error happens when
natsp.h
is included in a.cpp
file: