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 broken poll and nfds_t bindings #24331

Merged
merged 1 commit into from
Oct 20, 2024
Merged

Fix broken poll and nfds_t bindings #24331

merged 1 commit into from
Oct 20, 2024

Conversation

bptato
Copy link
Contributor

@bptato bptato commented Oct 20, 2024

This fixes several cases of the Nim binding of nfds_t being inconsistent with the target platform signedness and/or size.

Additionally, it fixes poll's third argument (timeout) being set to Nim "int" when it should have been "cint".

The former is the same issue that #23045 had attempted to fix, but failed because it only considered Linux. (Also, it was only applied to version 2.0, so the two branches now have incompatible versions of the same bug.)

Notes:

  • SVR4's original "unsigned long" definition is cloned by Linux and Haiku. Nim got this right for Haiku and Linux-amd64, but it was wrong on non-amd64 Linux.
  • Zephyr does not have nfds_t, but simply uses (signed) "int". This was already correctly reflected by Nim.
  • OpenBSD poll.h uses "unsigned int", and other BSD derivatives follow suit. This being the most commonly copied definition, the fallback case now returns cuint. (This also seems to be correct for the OS X headers I could find on the web.)
  • This changes Nintendo Switch nfds_t to cuint from culong. It is purportedly a FreeBSD derivative, so I think this is correct, but I can't tell because I don't have access to the Nintendo Switch headers.

I have also moved the platform-specific Tnfds to posix.nim so that we can reuse the fallback logic on all platforms. (e.g. specifying the size in posix_linux_amd64 only to then use when defined(linux) in posix_other seems redundant.)

This fixes several cases of the Nim binding of nfds_t being inconsistent
with the target platform signedness and/or size.

Additionally, it fixes poll's third argument (timeout) being set to
Nim "int" when it should have been "cint".

The former is the same issue that nim-lang#23045 had attempted to fix, but
failed because it only considered Linux. (Also, it was only applied to
version 2.0, so the two branches now have incompatible versions of the
same bug.)

Notes:

* SVR4's original "unsigned long" definition is cloned by Linux and
  Haiku. Nim got this right for Haiku and Linux-amd64, but it was wrong
  on non-amd64 Linux.
* Zephyr does not have nfds_t, but simply uses (signed) "int". This
  was already correctly reflected by Nim.
* OpenBSD poll.h uses "unsigned int", and other BSD derivatives follow
  suit.
  This being the most commonly copied definition, the fallback case now
  returns cuint. (This also seems to be correct for the OS X headers I
  could find on the web.)
* This changes Nintendo Switch nfds_t to cuint from culong. It is
  purportedly a FreeBSD derivative, so I *think* this is correct, but I
  can't tell because I don't have access to the Nintendo Switch headers.

I have also moved the platform-specific Tnfds to posix.nim so that we
can reuse the fallback logic on all platforms. (e.g. specifying the size
in posix_linux_amd64 only to then use when defined(linux) in posix_other
seems redundant.)
@Araq Araq merged commit 6744247 into nim-lang:devel Oct 20, 2024
19 checks passed
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 6744247

Hint: mm: orc; opt: speed; options: -d:release
175292 lines; 8.506s; 655.328MiB peakmem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants