classification
Title: AIX POLLNVAL definition causes problems
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, john_marshall
Priority: normal Keywords:

Created on 2004-03-25 18:06 by john_marshall, last changed 2004-08-07 17:22 by akuchling. This issue is now closed.

Files
File name Uploaded Description Edit
j3.c john_marshall, 2004-03-25 18:06 test program in C
Messages (2)
msg20316 - (view) Author: John Marshall (john_marshall) Date: 2004-03-25 18:06
Under AIX (5.1 at least), POLLNVAL (from sys/poll.h) 
is 0x8000. This causes a problem because it is stored 
in a (signed) short (e.g., revents): 
 
----- 
struct  pollfd 
{ 
  int    fd;      /* file descriptor or file ptr */ 
  short  events;  /* requested events */ 
  short  revents; /* returned events */ 
}; 
----- 
 
As such, the following tests and results are given: 
----- 
ashort (%hx)   = 8000, ashort (%x)   = ffff8000 
POLLNVAL (%hx) = 8000, POLLNVAL (%x) = 8000 
 
ashort == POLLNVAL        => 0 
ashort == (short)POLLNVAL => 1 
----- 
 
Note that the 'ashort == POLLNVAL' test is 0 rather 
than 1 because (I believe) POLLNVAL is treated as a 
signed integer, the ashort value is then promoted to 
signed integer thus giving 0xffff8000, not 0x8000. 
 
The problem arises because IBM has chosen to use a 
negative short value (0x8000) in a signed short 
variable. Neither Linux or IRIX have this problem 
because they use POLLNVAL=0x20 which promotes to 
0x20. 
 
This situation will cause the test_poll to fail and 
will certainly be a gotcha for AIX users. 
 
I have added the following code to the selectmodule.c 
to address the problem (mask out the upper 32 bits): 
 
-----~ line 513:selectmodule.c 
num = PyInt_FromLong(self->ufds[i].revents & 0xffff); 
----- 
 
John 
msg20317 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-08-07 17:22
Logged In: YES 
user_id=11375

Applied to 2.4 HEAD; thanks!
History
Date User Action Args
2004-03-25 18:06:51john_marshallcreate