@@ -69,6 +69,14 @@ sp_handle_new(HANDLE handle)
6969 return (PyObject * ) self ;
7070}
7171
72+ #if defined(MS_WIN32 ) && !defined(MS_WIN64 )
73+ #define HANDLE_TO_PYNUM (handle ) PyInt_FromLong((long) handle)
74+ #define PY_HANDLE_PARAM "l"
75+ #else
76+ #define HANDLE_TO_PYNUM (handle ) PyLong_FromLongLong((long long) handle)
77+ #define PY_HANDLE_PARAM "L"
78+ #endif
79+
7280static PyObject *
7381sp_handle_detach (sp_handle_object * self , PyObject * args )
7482{
@@ -82,7 +90,7 @@ sp_handle_detach(sp_handle_object* self, PyObject* args)
8290 self -> handle = NULL ;
8391
8492 /* note: return the current handle, as an integer */
85- return PyInt_FromLong (( long ) handle );
93+ return HANDLE_TO_PYNUM ( handle );
8694}
8795
8896static PyObject *
@@ -122,7 +130,7 @@ sp_handle_getattr(sp_handle_object* self, char* name)
122130static PyObject *
123131sp_handle_as_int (sp_handle_object * self )
124132{
125- return PyInt_FromLong (( long ) self -> handle );
133+ return HANDLE_TO_PYNUM ( self -> handle );
126134}
127135
128136static PyNumberMethods sp_handle_as_number ;
@@ -168,7 +176,7 @@ sp_GetStdHandle(PyObject* self, PyObject* args)
168176 }
169177
170178 /* note: returns integer, not handle object */
171- return PyInt_FromLong (( long ) handle );
179+ return HANDLE_TO_PYNUM ( handle );
172180}
173181
174182static PyObject *
@@ -186,14 +194,16 @@ sp_DuplicateHandle(PyObject* self, PyObject* args)
186194 HANDLE target_handle ;
187195 BOOL result ;
188196
189- long source_process_handle ;
190- long source_handle ;
191- long target_process_handle ;
197+ HANDLE source_process_handle ;
198+ HANDLE source_handle ;
199+ HANDLE target_process_handle ;
192200 int desired_access ;
193201 int inherit_handle ;
194202 int options = 0 ;
195203
196- if (! PyArg_ParseTuple (args , "lllii|i:DuplicateHandle" ,
204+ if (! PyArg_ParseTuple (args ,
205+ PY_HANDLE_PARAM PY_HANDLE_PARAM PY_HANDLE_PARAM
206+ "ii|i:DuplicateHandle" ,
197207 & source_process_handle ,
198208 & source_handle ,
199209 & target_process_handle ,
@@ -204,9 +214,9 @@ sp_DuplicateHandle(PyObject* self, PyObject* args)
204214
205215 Py_BEGIN_ALLOW_THREADS
206216 result = DuplicateHandle (
207- ( HANDLE ) source_process_handle ,
208- ( HANDLE ) source_handle ,
209- ( HANDLE ) target_process_handle ,
217+ source_process_handle ,
218+ source_handle ,
219+ target_process_handle ,
210220 & target_handle ,
211221 desired_access ,
212222 inherit_handle ,
@@ -436,13 +446,13 @@ sp_TerminateProcess(PyObject* self, PyObject* args)
436446{
437447 BOOL result ;
438448
439- long process ;
449+ HANDLE process ;
440450 int exit_code ;
441- if (! PyArg_ParseTuple (args , "li :TerminateProcess", & process ,
442- & exit_code ))
451+ if (! PyArg_ParseTuple (args , PY_HANDLE_PARAM "i :TerminateProcess" ,
452+ & process , & exit_code ))
443453 return NULL ;
444454
445- result = TerminateProcess (( HANDLE ) process , exit_code );
455+ result = TerminateProcess (process , exit_code );
446456
447457 if (! result )
448458 return PyErr_SetFromWindowsErr (GetLastError ());
@@ -457,11 +467,11 @@ sp_GetExitCodeProcess(PyObject* self, PyObject* args)
457467 DWORD exit_code ;
458468 BOOL result ;
459469
460- long process ;
461- if (! PyArg_ParseTuple (args , "l :GetExitCodeProcess" , & process ))
470+ HANDLE process ;
471+ if (! PyArg_ParseTuple (args , PY_HANDLE_PARAM " :GetExitCodeProcess" , & process ))
462472 return NULL ;
463473
464- result = GetExitCodeProcess (( HANDLE ) process , & exit_code );
474+ result = GetExitCodeProcess (process , & exit_code );
465475
466476 if (! result )
467477 return PyErr_SetFromWindowsErr (GetLastError ());
@@ -474,15 +484,15 @@ sp_WaitForSingleObject(PyObject* self, PyObject* args)
474484{
475485 DWORD result ;
476486
477- long handle ;
487+ HANDLE handle ;
478488 int milliseconds ;
479- if (! PyArg_ParseTuple (args , "li :WaitForSingleObject" ,
489+ if (! PyArg_ParseTuple (args , PY_HANDLE_PARAM "i :WaitForSingleObject" ,
480490 & handle ,
481491 & milliseconds ))
482492 return NULL ;
483493
484494 Py_BEGIN_ALLOW_THREADS
485- result = WaitForSingleObject (( HANDLE ) handle , (DWORD ) milliseconds );
495+ result = WaitForSingleObject (handle , (DWORD ) milliseconds );
486496 Py_END_ALLOW_THREADS
487497
488498 if (result == WAIT_FAILED )
@@ -504,13 +514,14 @@ static PyObject *
504514sp_GetModuleFileName (PyObject * self , PyObject * args )
505515{
506516 BOOL result ;
507- long module ;
517+ HMODULE module ;
508518 TCHAR filename [MAX_PATH ];
509519
510- if (! PyArg_ParseTuple (args , "l:GetModuleFileName" , & module ))
520+ if (! PyArg_ParseTuple (args , PY_HANDLE_PARAM ":GetModuleFileName" ,
521+ & module ))
511522 return NULL ;
512523
513- result = GetModuleFileName (( HMODULE ) module , filename , MAX_PATH );
524+ result = GetModuleFileName (module , filename , MAX_PATH );
514525 filename [MAX_PATH - 1 ] = '\0' ;
515526
516527 if (! result )
0 commit comments