| Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10742/win32/src
Modified Files:
	PyHANDLE.cpp 
Log Message:
Let PyWinObject_AsHANDLE accept any object that can be converted to an int - for subclasses of PyHANDLE that don't use PyHANDLEType
Index: PyHANDLE.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyHANDLE.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** PyHANDLE.cpp	7 Nov 2003 03:58:17 -0000	1.8
--- PyHANDLE.cpp	5 Sep 2004 15:43:17 -0000	1.9
***************
*** 26,34 ****
  		PyHANDLE *pH = (PyHANDLE *)ob;
  		*pHANDLE = (HANDLE)(*pH);
! 	} else if (PyInt_Check(ob)) { // Support integer objects for b/w compat.
  		*pHANDLE = (HANDLE)PyInt_AsLong(ob);
! 	} else {
! 		PyErr_SetString(PyExc_TypeError, "The object is not a PyHANDLE object");
! 		return FALSE;
  	}
  	return TRUE;
--- 26,35 ----
  		PyHANDLE *pH = (PyHANDLE *)ob;
  		*pHANDLE = (HANDLE)(*pH);
! 	} else{ // Support integer objects for b/w compat.
  		*pHANDLE = (HANDLE)PyInt_AsLong(ob);
! 		if ((*pHANDLE==(HANDLE)-1)&&PyErr_Occurred()){
! 			PyErr_SetString(PyExc_TypeError, "The object is not a PyHANDLE object");
! 			return FALSE;
! 		}
  	}
  	return TRUE;
***************
*** 42,57 ****
  BOOL PyWinObject_CloseHANDLE(PyObject *obHandle)
  {
! 	BOOL ok;
  	if (PyHANDLE_Check(obHandle))
! 		// Python error already set.
! 		ok = ((PyHANDLE *)obHandle)->Close();
! 	else if PyInt_Check(obHandle) {
! 		ok = ::CloseHandle((HANDLE)PyInt_AsLong(obHandle));
! 		if (!ok)
! 			PyWin_SetAPIError("CloseHandle");
! 	} else {
! 		PyErr_Format(PyExc_TypeError, "A handle must be a HANDLE object or an integer (got %s)", obHandle->ob_type->tp_name);
  		return FALSE;
! 	}
  	return ok;
  }
--- 43,57 ----
  BOOL PyWinObject_CloseHANDLE(PyObject *obHandle)
  {
! 	// PyWinObject_AsHANDLE checks this also, but need to make sure an override Close method is called
  	if (PyHANDLE_Check(obHandle))
! 		return ((PyHANDLE *)obHandle)->Close(); // Python error already set.
! 
! 	HANDLE h;
! 	BOOL ok;
! 	if (!PyWinObject_AsHANDLE(obHandle, &h, FALSE))
  		return FALSE;
! 	ok=::CloseHandle(h);  // This can still trigger an Invalid Handle exception in debug mode
! 	if (!ok)
! 		PyWin_SetAPIError("CloseHandle");
  	return ok;
  }
***************
*** 242,247 ****
--- 242,249 ----
  {
  	long result = ((PyHANDLE *)ob)->asLong();
+ 	/* PyHANDLE::asLong sets no errors 
  	if ( result == -1 )
  		return NULL;
+ 	*/
  	return PyInt_FromLong(result);
  }
 |