r5242: Check that argument is an integer or a long for uint32_t input
authorTim Potter <tpot@samba.org>
Sun, 6 Feb 2005 00:34:44 +0000 (00:34 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:09:33 +0000 (13:09 -0500)
typemap.

The uint32_t output typemap must return a Python long as an unsigned
uint32_t cannot be fully represented by a Python int.

Likewise for the NTSTATUS typemap.

source/scripting/swig/samba.i

index 6cdf4240956c15da97ae97e61a8f94462fcf4f9a..db48b3c4ba9f8f699a1a7cc54108a6ba17127864 100644 (file)
 %apply char { int8_t };
 %apply unsigned int { uint16_t };
 %apply int { int16_t };
-%apply unsigned long { uint32_t };
-%apply long { int32_t };
 %apply unsigned long long { uint64_t };
 %apply long long { int64_t };
 
+%typemap(in) uint32_t {
+       if (PyLong_Check($input))
+               $1 = PyLong_AsUnsignedLong($input);
+       else if (PyInt_Check($input))
+               $1 = PyInt_AsLong($input);
+       else {
+               PyErr_SetString(PyExc_TypeError,"Expected a long or an int");
+               return NULL;
+       }
+}
+
+%typemap(out) uint32_t {
+       $result = PyLong_FromUnsignedLong($1);
+}
+
 %typemap(out) NTSTATUS {
-        $result = PyLong_FromLong(NT_STATUS_V($1));
+        $result = PyLong_FromUnsignedLong(NT_STATUS_V($1));
 }