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

Skip to content

Commit 3821e31

Browse files
author
Thomas Heller
committed
c_void_p.from_param accepts bytes. Fix test_prototypes.
1 parent 3d79dd9 commit 3821e31

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lib/ctypes/test/test_prototypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_c_void_p_arg(self):
104104
func.argtypes = c_void_p,
105105

106106
self.failUnlessEqual(None, func(None))
107-
self.failUnlessEqual("123", func("123"))
107+
self.failUnlessEqual("123", func(b"123"))
108108
self.failUnlessEqual("123", func(c_char_p("123")))
109109
self.failUnlessEqual(None, func(c_char_p(None)))
110110

Modules/_ctypes/_ctypes.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,11 +1268,29 @@ c_void_p_from_param(PyObject *type, PyObject *value)
12681268
}
12691269
return (PyObject *)parg;
12701270
}
1271+
/* XXX struni: remove later */
12711272
/* string */
12721273
if (PyString_Check(value)) {
12731274
PyCArgObject *parg;
12741275
struct fielddesc *fd = getentry("z");
12751276

1277+
parg = new_CArgObject();
1278+
if (parg == NULL)
1279+
return NULL;
1280+
parg->pffi_type = &ffi_type_pointer;
1281+
parg->tag = 'z';
1282+
parg->obj = fd->setfunc(&parg->value, value, 0);
1283+
if (parg->obj == NULL) {
1284+
Py_DECREF(parg);
1285+
return NULL;
1286+
}
1287+
return (PyObject *)parg;
1288+
}
1289+
/* bytes */
1290+
if (PyBytes_Check(value)) {
1291+
PyCArgObject *parg;
1292+
struct fielddesc *fd = getentry("z");
1293+
12761294
parg = new_CArgObject();
12771295
if (parg == NULL)
12781296
return NULL;

0 commit comments

Comments
 (0)