Avoid includes within extern C namespace #960
Labels
No labels
announcement
bug
build
CI
dependencies
documentation
duplicate
enhancement
experience feedback
feature request
github_actions
help wanted
install
invalid
Long-term
optimization
portability
question
target-specific
test issue
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-Cyan4973/xxHash#960
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Line 244 of xxhash.h has a:
that is followed up by includes of system-provided headers, that are not guaranteed to work within an
extern Clinkage rules.In particular, while compiling apache-arrow with Emscripten, I get:
that make compilation fail.
Current workaround, very much ad-hoc, is explicitly including
<emscripten.h>(conditionally on EMSCRIPTEN being defined) before includingxxhash.h. This works, but it's not great and solves only this specific case. PR is at https://github.com/duckdb/duckdb-wasm/pull/1803.Would it be possible to move the includes outside of the
extern Cnamespace, given I believe not to be compliant with C++ compilers?Thanks a lot.
possibly ?
The "generic" headers (like
<stddef.h>) can most likely be pushed outside,but the "specific" ones (like
<emscriptem.h>) are only included if some specific conditions are met, and it would be necessary to replicate these conditions outside ofextern "C"block, which now becomes must less desirable for code maintenance.To be investigated.
What would make sense is to fold this objective into the planned effort to separate the source code into multiple small units.
There it will be easier to pay attention to
#includeoutside of theextern "C"blockThanks for the reply!
Possibly a way out, altought very verbose, is closing and then reopening the
extern Cbrackets, something like:to
unsure if doing this via macro or something would make sense.
There are limits (one cannot generate macros with macros), but yeah, something like that is indeed possible.
It just will fit more naturally in a multi-units design, from which a single amalgamated
xxhash.hcould still be generated.As another possible solution, we'll be able to use the following inline extern C style
We can also define it as a macro
Msvc's dllexport is able to be supported in the same style.
I was wondering if there was some kind of relatively easy scenario that could be played locally in order to produce this issue ?
It's not super trivial, I have not been able to reproduce locally now, possibly this has been fixed in Emscripten headers (I tried 3.1.71 and 3.1.61).
I would say it's not safe to include headers that might be implemented arbitrarily within
extern Cnamespaces, since those headers might have branches on cplusplus being there for feature detection or so.But given I can't provide a reproduction AND this might be very minor, your call on whether this makes sense looking into or not.
I understand that it's generally preferable to avoid using
#include "..."statements within anextern "C"block, and I would prefer to eliminate such cases.The challenge, however, lies in the current structure of the code. Attempting this change would be a significant undertaking, deeply affecting the source code and potentially introducing new risks in the process.
Additionally, without any testing framework in place, there's no way to confirm that the change would actually address any tangible issue. This introduces considerable uncertainty, as the benefits are unclear and it's difficult to identify or reproduce scenarios where this modification would make a meaningful difference.
Of course, if the change were straightforward, it would be an entirely different matter, and I would simply implement it. I believe that, in the future, as the source code is refactored into smaller, more manageable units, this goal will naturally become more feasible and much easier to achieve.
Agree, then probably closing this, if this pops back for some other weird libc implementation then maybe there will be a better shot at reproducing.
I ran into this issue but I was able to solve it by adding this at the top of
xxhash.h:This issue is presumed fixed in #1129