From: Thomas Heller Date: Fri, 13 Jul 2007 12:07:59 +0000 (+0000) Subject: Do not accept str8 type in function calls any longer. X-Git-Tag: v3.0a1~646 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=27384da6e863b35fcee3e773c71c497406056458;p=thirdparty%2FPython%2Fcpython.git Do not accept str8 type in function calls any longer. Accept bytes instead of str8 in the (unexposed in ctypes) BSTR type. --- diff --git a/Lib/ctypes/test/test_bytes.py b/Lib/ctypes/test/test_bytes.py index e6e047a82e33..db2824da1f98 100644 --- a/Lib/ctypes/test/test_bytes.py +++ b/Lib/ctypes/test/test_bytes.py @@ -1,5 +1,6 @@ """Test where byte objects are accepted""" import unittest +import sys from ctypes import * class BytesTest(unittest.TestCase): @@ -37,5 +38,14 @@ class BytesTest(unittest.TestCase): X("abc") X(b"abc") + if sys.platform == "win32": + def test_BSTR(self): + from _ctypes import _SimpleCData + class BSTR(_SimpleCData): + _type_ = "X" + + BSTR("abc") + BSTR(b"abc") + if __name__ == '__main__': unittest.main() diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 35453d569013..61be77b680ed 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -507,15 +507,6 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa) return 0; } - /* XXX struni remove later */ - if (PyString_Check(obj)) { - pa->ffi_type = &ffi_type_pointer; - pa->value.p = PyString_AS_STRING(obj); - Py_INCREF(obj); - pa->keep = obj; - return 0; - } - if (PyBytes_Check(obj)) { pa->ffi_type = &ffi_type_pointer; pa->value.p = PyBytes_AsString(obj); diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index da7e0fcd281f..1b18879d2c7f 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1501,7 +1501,7 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size) /* convert value into a PyUnicodeObject or NULL */ if (Py_None == value) { value = NULL; - } else if (PyString_Check(value)) { + } else if (PyBytes_Check(value)) { value = PyUnicode_FromEncodedObject(value, conversion_mode_encoding, conversion_mode_errors);