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
AIX POLLNVAL definition causes problems #62119
Comments
I encounted exactly the same issue http://bugs.python.org/issue923315 with test_asyncore, test_asynchat and test_poll. On AIX6.1, POLLNVAL=0x8000=SHRT_MIN=SHRT_MAX+1 (on 2 bytes) and parsing events with PyArg_ParseTuple as a signed short 'h' do not work, i.e I changed 'h' to 'H' in the attached patch, and delete associated Overflow test. Perhaps, they're a better way to handle that ? |
That's the way AIX allocated the bits. It's nice to check for overflow, but I think the test is imposing more semantics on the mask bits than POSIX requires. It just happens that the GLibc allocation of bits works out okay. |
This is a regression since 2.7.4 because of http://bugs.python.org/issue15989. As the 'events' and 'revents' members of 'struct pollfd' both are bitfields, the question actually is why they need to be signed at all. Additionally: I'm wondering why poll_modify() and internal_devpoll_register() haven't been updated along issue#15989, as both still have 'i' for the 'events' arg. Attached patch (for hg-tip) changes the 'events' for 'struct pollfd' to be generally treated as unsigned short bitfield. Not that I know of one, but the &0xffff hack may break on platforms where 'short' is not 16bits - casting to (unsigned short) instead feels more save. Additional question: Would it make sense to have the 'BHIkK' types check for overflow? Thank you! |
The disadvantage of 'H' is that it never raises OverflowError. The simplest solution is just revert a part of the patch for bpo-15989. |
New changeset 08c95dd68cfc by Serhiy Storchaka in branch '3.3': New changeset e78743e03c8f by Serhiy Storchaka in branch 'default': New changeset 64f32a31cd49 by Serhiy Storchaka in branch '2.7': |
The correct fix is to write a new parser just for this function. See for example uint_converter() in Modules/zlibmodule.c. I would prefer to add such new parser to Python/getargs.c directly, but I was not motivated when I fixed bpo-18294 (integer overflow in the zlib module). |
The revert reintroduced the integer overflow:
|
Here is a patch which uses special converter. |
+ if (uval > USHRT_MAX) { The message should be "C unsigned short". The unit tests don't check that USHRT_MAX value is accepted. |
With poll_events_mask_overflow.patch, the following hack can maybe be removed?
|
Thanks.
And shouldn't. Not all values make sense. Meaning of USHRT_MAX is platform depended.
No. Otherwise the result can be negative. |
New changeset 9bee6cc30db7 by Serhiy Storchaka in branch '2.7': New changeset 87bbe810e4e7 by Serhiy Storchaka in branch '3.3': New changeset 2fbb3c77f157 by Serhiy Storchaka in branch 'default': |
Thank you Delhallt for your report. |
Hi, this happens on the OpenIndiana bot: http://buildbot.python.org/all/builders/x86%20OpenIndiana%203.3/builds/1259/steps/test/logs/stdio test_devpoll1 (test.test_devpoll.DevPollTests) ... ok ====================================================================== Traceback (most recent call last):
File "/export/home/buildbot/32bits/3.3.cea-indiana-x86/build/Lib/test/test_devpoll.py", line 96, in test_events_mask_overflow
self.assertRaises(OverflowError, pollster.register, 0, USHRT_MAX + 1)
NameError: global name 'USHRT_MAX' is not defined Ran 3 tests in 0.006s FAILED (errors=1) |
I have fixed the issue in http://hg.python.org/cpython/rev/039306b45230 |
You forget 2.7 and 3.3 branches. |
New changeset c42647d76bd1 by Christian Heimes in branch '3.3': New changeset 1f3f4147c35e by Christian Heimes in branch 'default': |
Thank you Christian. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: