]> granicus.if.org Git - python/commitdiff
Merged revisions 74921 via svnmerge from
authorThomas Heller <theller@ctypes.org>
Fri, 18 Sep 2009 20:12:29 +0000 (20:12 +0000)
committerThomas Heller <theller@ctypes.org>
Fri, 18 Sep 2009 20:12:29 +0000 (20:12 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74921 | thomas.heller | 2009-09-18 22:05:44 +0200 (Fr, 18 Sep 2009) | 3 lines

  Issue #4606: Passing 'None' if ctypes argtype is set to POINTER(...)
  does now always result in NULL.
........

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

index 1b7f0dc86b464cead82bfdb4fbf894b7a29eac5e..d477a8cbe8e9f38f0a0e1065dcaecd1c4dcf565a 100644 (file)
@@ -97,7 +97,7 @@ class SimpleTypesTestCase(unittest.TestCase):
         self.failUnlessEqual(x.contents.value, 42)
         self.failUnlessEqual(LPINT(c_int(42)).contents.value, 42)
 
-        self.failUnlessEqual(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 170cde7b6e843162300d938e10766d6d91942bcc..5848fb3157cd9eaeb3ef96ff80882e4897637aad 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -82,8 +82,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 b6937a87c8c82e77c7ffd4f58609fcd3a4fed324..9840c8c5d612090cc8e2627a52570129ab8e8a77 100644 (file)
@@ -972,8 +972,11 @@ PointerType_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 8988c127b3f4383aa9ad1ef0aca175fbba4cad52..0c51f84122f3f550c342be75fd7d398bc4549332 100644 (file)
@@ -546,6 +546,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'.