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

................
  r74922 | thomas.heller | 2009-09-18 22:08:39 +0200 (Fr, 18 Sep 2009) | 10 lines

  Merged revisions 74921 via svnmerge from
  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 10eddd4cb4f9afad6c16cdab853f75effaef47ae..6a3f33d19c68b8d9dd88a09ab088e95c9bad50b9 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 7296042f59379f8b709b2bd2c7c767c228802a91..5236a9e5991ddbeb5987cd118dc3830f8ac90538 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #4606: Passing 'None' if ctypes argtype is set to POINTER(...)
+  does now always result in NULL.
+
 - Issue #5042: Structure sub-subclass does now initialize correctly
   with base class positional arguments.
 
index 41264d33ad2008664f3b94ca12d3c23790c7b628..40cf480f7e724258ab0a3bf70e0cc0f7ee393327 100644 (file)
@@ -936,8 +936,11 @@ PyCPointerType_from_param(PyObject *type, PyObject *value)
 {
        StgDictObject *typedict;
 
-       if (value == Py_None)
-               return PyLong_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 cbc5cf86fecacc147ccc41841018fb57ade7659a..f5eaa0d0babec8fe835eb918d8087117815e9fef 100644 (file)
@@ -547,6 +547,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'.