Author: thomas.heller
Date: Thu Jul 12 21:19:43 2007
New Revision: 56326

Modified:
   python/branches/py3k-struni/Lib/ctypes/test/test_slicing.py
   python/branches/py3k-struni/Modules/_ctypes/callproc.c
Log:
Accept bytes as parameter to foreign functions without prototype.
These are passed as byte strings (unicode strings are passed as wide
character strings).


Modified: python/branches/py3k-struni/Lib/ctypes/test/test_slicing.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/test/test_slicing.py (original)
+++ python/branches/py3k-struni/Lib/ctypes/test/test_slicing.py Thu Jul 12 
21:19:43 2007
@@ -37,7 +37,7 @@
     from ctypes.test import is_resource_enabled
     if is_resource_enabled("struni-crash"):
         def test_char_ptr(self):
-            s = "abcdefghijklmnopqrstuvwxyz"
+            s = b"abcdefghijklmnopqrstuvwxyz"
 
             dll = CDLL(_ctypes_test.__file__)
             dll.my_strdup.restype = POINTER(c_char)
@@ -57,7 +57,7 @@
 
         def test_char_ptr_with_free(self):
             dll = CDLL(_ctypes_test.__file__)
-            s = "abcdefghijklmnopqrstuvwxyz"
+            s = b"abcdefghijklmnopqrstuvwxyz"
 
             class allocated_c_char_p(c_char_p):
                 pass

Modified: python/branches/py3k-struni/Modules/_ctypes/callproc.c
==============================================================================
--- python/branches/py3k-struni/Modules/_ctypes/callproc.c      (original)
+++ python/branches/py3k-struni/Modules/_ctypes/callproc.c      Thu Jul 12 
21:19:43 2007
@@ -512,6 +512,7 @@
                return 0;
        }
 
+       /* XXX struni remove later */
        if (PyString_Check(obj)) {
                pa->ffi_type = &ffi_type_pointer;
                pa->value.p = PyString_AS_STRING(obj);
@@ -520,6 +521,14 @@
                return 0;
        }
 
+       if (PyBytes_Check(obj)) {
+               pa->ffi_type = &ffi_type_pointer;
+               pa->value.p = PyBytes_AsString(obj);
+               Py_INCREF(obj);
+               pa->keep = obj;
+               return 0;
+       }
+
 #ifdef CTYPES_UNICODE
        if (PyUnicode_Check(obj)) {
 #ifdef HAVE_USABLE_WCHAR_T
_______________________________________________
Python-3000-checkins mailing list
Python-3000-checkins@python.org
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to