From: Thomas Heller Date: Thu, 12 Jul 2007 19:38:33 +0000 (+0000) Subject: c_void_p.from_param accepts bytes. Fix test_prototypes. X-Git-Tag: v3.0a1~657 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3821e31d19343ff8694f6e2c86c12c0dcd127527;p=python c_void_p.from_param accepts bytes. Fix test_prototypes. --- diff --git a/Lib/ctypes/test/test_prototypes.py b/Lib/ctypes/test/test_prototypes.py index b14d2d8690..91b7e0da7d 100644 --- a/Lib/ctypes/test/test_prototypes.py +++ b/Lib/ctypes/test/test_prototypes.py @@ -104,7 +104,7 @@ class CharPointersTestCase(unittest.TestCase): func.argtypes = c_void_p, self.failUnlessEqual(None, func(None)) - self.failUnlessEqual("123", func("123")) + self.failUnlessEqual("123", func(b"123")) self.failUnlessEqual("123", func(c_char_p("123"))) self.failUnlessEqual(None, func(c_char_p(None))) diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index d6a435d614..5b114804e5 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -1268,11 +1268,29 @@ c_void_p_from_param(PyObject *type, PyObject *value) } return (PyObject *)parg; } + /* XXX struni: remove later */ /* string */ if (PyString_Check(value)) { PyCArgObject *parg; struct fielddesc *fd = getentry("z"); + parg = new_CArgObject(); + if (parg == NULL) + return NULL; + parg->pffi_type = &ffi_type_pointer; + parg->tag = 'z'; + parg->obj = fd->setfunc(&parg->value, value, 0); + if (parg->obj == NULL) { + Py_DECREF(parg); + return NULL; + } + return (PyObject *)parg; + } +/* bytes */ + if (PyBytes_Check(value)) { + PyCArgObject *parg; + struct fielddesc *fd = getentry("z"); + parg = new_CArgObject(); if (parg == NULL) return NULL;