Repository navigation
Conversation
OpenHarmony (musl) exports qsort_r() with the GNU signature but its headers do not declare it, so stableSort() compiles as an implicit function declaration and fails under -Werror=implicit-function-declaration (OHOS SDK clang 15 defaults). Declare it locally when __OHOS__ is defined so cover.c keeps using the re-entrant GNU variant instead of falling back to the thread-unsafe C90 qsort() path.
|
Hi @bfs2021! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Problem
lib/dictBuilder/cover.cfails to compile on OpenHarmony (musl libc): the OHOS libc exportsqsort_r()with the GNU signature, but its headers do not declare it, so the call instableSort()is an implicit function declaration, which newer OHOS SDK clang treats as an error. Fixes #4872.Root cause
On OpenHarmony
__linux__is defined, socover.cdefines_GNU_SOURCEand theZDICT_QSORT_GNUpath is selected, but the OHOS musl headers omit theqsort_r()prototype. Unlike Android (which is excluded from the GNU path and falls back), there is no handling for this platform, and the C90 fallback (qsort()with a global context) would be a thread-safety regression.Fix
Declare
qsort_r()locally under#if defined(__OHOS__), right after the system includes. This is the Option B from the issue, which the reporter already validated on-device: OHOS'sqsort_ris the GNU variant, so the re-entrant sort keeps being used and no behavior changes on any other platform.__OHOS__is the macro predefined by the OHOS SDK toolchain.Testing
qsort_r:gcc -c -Ilib -D__linux__ -D__OHOS__ lib/dictBuilder/cover.cfails witherror: implicit declaration of function 'qsort_r'before the change and compiles cleanly after it (also with-Wall -Wextra), same as the OHOS clang error class.gcc -c -Ilib lib/dictBuilder/cover.cclean before/after.zstd --train-cover --split=4096(which exercisesstableSort()incover.c) plus a compress/decompress round-trip with the trained dictionary: all pass.