changeset 196b2bf6a4ce in /hgroot/pywin32/pywin32
details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=196b2bf6a4ce
summary: Allow NSI_DWORD members of set structs to accept python longs
diffstat:
win32/src/win32net/win32netmodule.cpp | 34 +++++++++++++++++++---------------
1 files changed, 19 insertions(+), 15 deletions(-)
diffs (59 lines):
diff -r e7d21102da8d -r 196b2bf6a4ce win32/src/win32net/win32netmodule.cpp
--- a/win32/src/win32net/win32netmodule.cpp Fri Aug 24 10:50:19 2012 -0400
+++ b/win32/src/win32net/win32netmodule.cpp Fri Aug 24 13:09:08 2012 -0400
@@ -121,28 +121,32 @@
*((WCHAR **)(buf+pItem->off)) = wsz;
break;
case NSI_DWORD:
- if (!PyInt_Check(subob)) {
+ *((DWORD *)(buf+pItem->off)) = PyInt_AsUnsignedLongMask(subob);
+ if (*((DWORD *)(buf+pItem->off)) == -1 && PyErr_Occurred()){
+ PyErr_Clear();
+ PyErr_Format(PyExc_TypeError, "The mapping attribute '%s' must be an unsigned 32 bit int", pItem->attrname);
+ Py_DECREF(subob);
+ goto done;
+ }
+ break;
+ case NSI_LONG:
+ *((LONG *)(buf+pItem->off)) = PyInt_AsLong(subob);
+ if (*((LONG *)(buf+pItem->off)) == -1 && PyErr_Occurred()){
+ PyErr_Clear();
PyErr_Format(PyExc_TypeError, "The mapping attribute '%s' must be an integer", pItem->attrname);
Py_DECREF(subob);
goto done;
}
- *((DWORD *)(buf+pItem->off)) = (DWORD)PyInt_AsLong(subob);
break;
- case NSI_LONG:
- if (!PyInt_Check(subob)) {
- PyErr_Format(PyExc_TypeError, "The mapping attribute '%s' must be an integer", pItem->attrname);
+ case NSI_BOOL:
+ *((BOOL *)(buf+pItem->off)) = PyObject_IsTrue(subob);
+ if (*((BOOL *)(buf+pItem->off)) == -1 && PyErr_Occurred()){
+ PyErr_Clear();
+ PyErr_Format(PyExc_TypeError, "The mapping attribute '%s' must be boolean", pItem->attrname);
Py_DECREF(subob);
goto done;
}
- *((LONG *)(buf+pItem->off)) = (LONG)PyInt_AsLong(subob);
- break;
- case NSI_BOOL:
- if (!PyInt_Check(subob)) {
- PyErr_Format(PyExc_TypeError, "The mapping attribute '%s' must be an integer", pItem->attrname);
- Py_DECREF(subob);
- goto done;
- }
- *((BOOL *)(buf+pItem->off)) = (BOOL)PyInt_AsLong(subob);
+
break;
case NSI_HOURS:
if (subob != Py_None) {
@@ -213,7 +217,7 @@
newObj = PyWinObject_FromWCHAR(*((WCHAR **)(buf+pItem->off)));
break;
case NSI_DWORD:
- newObj = PyInt_FromLong(*((DWORD *)(buf+pItem->off)));
+ newObj = PyLong_FromUnsignedLong(*((DWORD *)(buf+pItem->off)));
break;
case NSI_LONG:
newObj = PyInt_FromLong(*((LONG *)(buf+pItem->off)));
|