]> granicus.if.org Git - python/commitdiff
Issue #4606: Passing 'None' if ctypes argtype is set to POINTER(...)
authorThomas Heller <theller@ctypes.org>
Fri, 18 Sep 2009 20:05:44 +0000 (20:05 +0000)
committerThomas Heller <theller@ctypes.org>
Fri, 18 Sep 2009 20:05:44 +0000 (20:05 +0000)
does now always result in NULL.

Lib/ctypes/test/test_parameters.py
Misc/NEWS
Modules/_ctypes/_ctypes.c
Modules/_ctypes/callproc.c

index 69db14fd4ef0ac5744f3c8a5c7f0516d22f75e1b..82704d5f3a98fa9c56966182b659b5a76605a1ce 100644 (file)
@@ -97,7 +97,7 @@ class SimpleTypesTestCase(unittest.TestCase):
         self.assertEqual(x.contents.value, 42)
         self.assertEqual(LPINT(c_int(42)).contents.value, 42)
 
-        self.assertEqual(LPINT.from_param(None), 0)
+        self.assertEqual(LPINT.from_param(None), None)
 
         if c_int != c_long:
             self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
index 12815a8e9aa19604d58d7c8517facb59350e7cd4..0ce1168035a145750d8e59d9aaa33ac91ecfe6db 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -376,8 +376,11 @@ Core and Builtins
 Library
 -------
 
-- Issue #5042: Structure sub-subclass does now initialize correctly
-  with base class positional arguments.
+- Issue #4606: Passing 'None' if ctypes argtype is set to POINTER(...)
+  does now always result in NULL.
+
+- Issue #5042: ctypes Structure sub-subclass does now initialize
+  correctly with base class positional arguments.
 
 - Issue #6938: Fix a TypeError in string formatting of a multiprocessing
   debug message.
index a5c00cd2208f7c68f0e288eb99b6287ea5b39483..25cf956f030b933959ae0712692bc7a878df4f36 100644 (file)
@@ -972,8 +972,11 @@ PyCPointerType_from_param(PyObject *type, PyObject *value)
 {
        StgDictObject *typedict;
 
-       if (value == Py_None)
-               return PyInt_FromLong(0); /* NULL pointer */
+       if (value == Py_None) {
+               /* ConvParam will convert to a NULL pointer later */
+               Py_INCREF(value);
+               return value;
+       }
 
        typedict = PyType_stgdict(type);
        assert(typedict); /* Cannot be NULL for pointer types */
index ec6d05bfdb5426da8d405c010e453bc876efc77c..cf17e3aa9df6d2e69d94f0e2db1ec4700c043ffb 100644 (file)
@@ -542,6 +542,7 @@ PyTypeObject PyCArg_Type = {
  * C function call.
  *
  * 1. Python integers are converted to C int and passed by value.
+ *    Py_None is converted to a C NULL pointer.
  *
  * 2. 3-tuples are expected to have a format character in the first
  *    item, which must be 'i', 'f', 'd', 'q', or 'P'.