]> granicus.if.org Git - python/commitdiff
Do not accept str8 type in function calls any longer.
authorThomas Heller <theller@ctypes.org>
Fri, 13 Jul 2007 12:07:59 +0000 (12:07 +0000)
committerThomas Heller <theller@ctypes.org>
Fri, 13 Jul 2007 12:07:59 +0000 (12:07 +0000)
Accept bytes instead of str8 in the (unexposed in ctypes) BSTR type.

Lib/ctypes/test/test_bytes.py
Modules/_ctypes/callproc.c
Modules/_ctypes/cfield.c

index e6e047a82e33ccdd0371a5a69a9c27db4b7c3d32..db2824da1f98eb1b4b8319ae2ee4d7d977b52dc5 100644 (file)
@@ -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()
index 35453d569013e1769b593ef3969799c11f5c66a4..61be77b680edfd92f0e10b70b513328f4b39c37a 100644 (file)
@@ -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);
index da7e0fcd281f439e0571a68960918853481f6485..1b18879d2c7f0da5b26bcf1f4d72aaad4a22ca89 100644 (file)
@@ -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);