classification
Title: SIZEOF_SOCKET_T used in longobject.h but undefined
Type: behavior Stage: needs patch
Components: Extension Modules Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: SIZEOF_SOCKET_T not defined
View: 4835
Assigned To: Nosy List: brian.curtin, christian.heimes, dmalcolm, pitrou, tim.golden
Priority: normal Keywords:

Created on 2010-08-17 18:50 by pitrou, last changed 2010-08-17 19:17 by dmalcolm. This issue is now closed.

Messages (3)
msg114144 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-17 18:50
longobject.h uses SIZEOF_SOCKET_T:

#if SIZEOF_SOCKET_T <= SIZEOF_LONG
#define PyLong_FromSocket_t(fd) PyLong_FromLong((SOCKET_T)(fd))
#define PyLong_AsSocket_t(fd) (SOCKET_T)PyLong_AsLong(fd)
#else
#define PyLong_FromSocket_t(fd) PyLong_FromLongLong(((SOCKET_T)(fd));
#define PyLong_AsSocket_t(fd) (SOCKET_T)PyLong_AsLongLong(fd)
#endif

but SIZEOF_SOCKET_T doesn't exist at that point since it is defined in Modules/socketmodule.h which isn't part of Include/Python.h. As a result, PyLong_FromSocket_t is always aliased to PyLong_FromLong, which is wrong under 64-bit Windows (a SOCKET is 64-bit there, while a long is 32-bit).
msg114145 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-17 18:55
This is witnessed in MSVC warning messages such as:

2>..\Modules\socketmodule.c(1611) : warning C4244: 'function' : conversion from 'SOCKET_T' to 'long', possible loss of data
msg114147 - (view) Author: Dave Malcolm (dmalcolm) (Python committer) Date: 2010-08-17 19:15
Looks like a dup of issue 4835
History
Date User Action Args
2010-08-17 19:17:23dmalcolmsetstatus: open -> closed
resolution: duplicate
superseder: SIZEOF_SOCKET_T not defined
2010-08-17 19:15:59dmalcolmsetnosy: + dmalcolm
messages: + msg114147
2010-08-17 18:55:51pitrousetmessages: + msg114145
2010-08-17 18:50:11pitroucreate