]> granicus.if.org Git - python/commitdiff
(The fix has been slightly adjusted.)
authorThomas Heller <theller@ctypes.org>
Tue, 10 Feb 2009 18:59:04 +0000 (18:59 +0000)
committerThomas Heller <theller@ctypes.org>
Tue, 10 Feb 2009 18:59:04 +0000 (18:59 +0000)
Merged revisions 69505 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r69505 | thomas.heller | 2009-02-10 19:43:01 +0100 (Di, 10 Feb 2009) | 3 lines

  Issue#5203: ctypes segfaults when passing a unicode string to a
  function without argtypes, if HAVE_USABLE_WCHAR_T is false.
........

Misc/NEWS
Modules/_ctypes/callproc.c

index 44a893ff0ecd59a85b809d993eaa882ce672cf5f..185e5cf4c79292efb4910ce79e0bad8a685cfe68 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -163,6 +163,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #5203: Fixed ctypes segfaults when passing a unicode string to a
+  function without argtypes (only occurs if HAVE_USABLE_WCHAR_T is false).
+
 - Issue #3386: distutils.sysconfig.get_python_lib prefix argument was ignored
   under NT and OS2. Patch by Philip Jenvey.
 
index 3bd6d664ef583ee22e387b8ea8732d4475117e30..c153ae2c1962ddff0eb87b1c99717644b9ae4fae 100644 (file)
@@ -645,14 +645,15 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
 
 #ifdef CTYPES_UNICODE
        if (PyUnicode_Check(obj)) {
-               pa->ffi_type = &ffi_type_pointer;
 #ifdef HAVE_USABLE_WCHAR_T
+               pa->ffi_type = &ffi_type_pointer;
                pa->value.p = PyUnicode_AS_UNICODE(obj);
                Py_INCREF(obj);
                pa->keep = obj;
                return 0;
 #else
                int size = PyUnicode_GET_SIZE(obj);
+               pa->ffi_type = &ffi_type_pointer;
                size += 1; /* terminating NUL */
                size *= sizeof(wchar_t);
                pa->value.p = PyMem_Malloc(size);