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

Fix bugzilla issue 24517: druntime tests crash on FreeBSD 14 #16405

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

jmdavis
Copy link
Member

@jmdavis jmdavis commented Apr 22, 2024

FreeBSD 14 changed the signature of qsort_r to be POSIX-compliant with POSIX, making it so that our binding for it no longer matches, resulting in a crash when it's used.

This implements a fix similar to what the FreeBSD headers do to avoid breaking code (they provide a static inline extern(C++) overload for the old signature). This provides a deprecated extern(D) overload for the old signature. The extern(C) overload now matches the new signature. The changes have been versioned so that they only affect FreeBSD 14 and newer.

Technically, if someone used Cmp when declaring their function for qsort_r, this would still break them (though with a compilation error that should be easy to fix rather than silent breakage or a crash), but I don't really see a way around that, and Cmp is not part of the POSIX API, so no one would have a clue that it was a thing without digging through the bindings. Arguably, we should make it private, since it's not part of POSIX, but I haven't done anything with that in this commit. My guess is that in reality, no D programs are both written to use qsort_r and run on FreeBSD (outside of the druntime tests), but this way, they won't break unless they use Cmp to declare their comparator function. They'll just get a deprecation message that they should update their code.

Regardless, we have to change the signature for FreeBSD 14 for it to work, and this does that.

FreeBSD 14 changed the signature of qsort_r to be POSIX-compliant with
POSIX, making it so that our binding for it no longer matches, resulting
in a crash when it's used.

This implements a fix similar to what the FreeBSD headers do to avoid
breaking code (they provide a static inline extern(C++) overload for the
old signature). This provides a deprecated extern(D) overload for the
old signature. The extern(C) overload now matches the new signature. The
changes have been versioned so that they only affect FreeBSD 14 and
newer.

Technically, if someone used Cmp when declaring their function for
qsort_r, this would still break them (though with a compilation error
that should be easy to fix rather than silent breakage or a crash), but
I don't really see a way around that, and Cmp is not part of the POSIX
API, so no one would have a clue that it was a thing without digging
through the bindings. Arguably, we should make it private, since it's
not part of POSIX, but I haven't done anything with that in this commit.
My guess is that in reality, no D programs are both written to use
qsort_r and run on FreeBSD (outside of the druntime tests), but this
way, they won't break unless they use Cmp to declare their comparator
function. They'll just get a deprecation message that they should update
their code.

Regardless, we have to change the signature for FreeBSD 14 for it to
work, and this does that.
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @jmdavis!

Bugzilla references

Auto-close Bugzilla Severity Description
24517 normal druntime tests fail on FreeBSD 14

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#16405"

@dlang-bot dlang-bot merged commit 757ba61 into dlang:master Apr 22, 2024
46 of 48 checks passed
@jmdavis jmdavis deleted the issue_24517 branch April 22, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants