Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69b639f

Browse files
author
Thomas Heller
committed
Merged revisions 74921 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent d7cb1b9 commit 69b639f

4 files changed

Lines changed: 10 additions & 3 deletions

File tree

Lib/ctypes/test/test_parameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_int_pointers(self):
9797
self.assertEqual(x.contents.value, 42)
9898
self.assertEqual(LPINT(c_int(42)).contents.value, 42)
9999

100-
self.assertEqual(LPINT.from_param(None), 0)
100+
self.assertEqual(LPINT.from_param(None), None)
101101

102102
if c_int != c_long:
103103
self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ C-API
7272
Library
7373
-------
7474

75+
- Issue #4606: Passing 'None' if ctypes argtype is set to POINTER(...)
76+
does now always result in NULL.
77+
7578
- Issue #5042: Structure sub-subclass does now initialize correctly
7679
with base class positional arguments.
7780

Modules/_ctypes/_ctypes.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,11 @@ PyCPointerType_from_param(PyObject *type, PyObject *value)
936936
{
937937
StgDictObject *typedict;
938938

939-
if (value == Py_None)
940-
return PyLong_FromLong(0); /* NULL pointer */
939+
if (value == Py_None) {
940+
/* ConvParam will convert to a NULL pointer later */
941+
Py_INCREF(value);
942+
return value;
943+
}
941944

942945
typedict = PyType_stgdict(type);
943946
assert(typedict); /* Cannot be NULL for pointer types */

Modules/_ctypes/callproc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ PyTypeObject PyCArg_Type = {
547547
* C function call.
548548
*
549549
* 1. Python integers are converted to C int and passed by value.
550+
* Py_None is converted to a C NULL pointer.
550551
*
551552
* 2. 3-tuples are expected to have a format character in the first
552553
* item, which must be 'i', 'f', 'd', 'q', or 'P'.

0 commit comments

Comments
 (0)