summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/ctypes/test/test_parameters.py2
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_ctypes/_ctypes.c7
-rw-r--r--Modules/_ctypes/callproc.c1
4 files changed, 10 insertions, 3 deletions
diff --git a/Lib/ctypes/test/test_parameters.py b/Lib/ctypes/test/test_parameters.py
index 10eddd4..6a3f33d 100644
--- a/Lib/ctypes/test/test_parameters.py
+++ b/Lib/ctypes/test/test_parameters.py
@@ -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)))
diff --git a/Misc/NEWS b/Misc/NEWS
index 1a9bda8..3c4c67b 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -72,6 +72,9 @@ C-API
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.
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 41264d3..40cf480 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -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 */
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index cbc5cf8..f5eaa0d 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -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'.