Issue 5203: ctypes segfaults when passing a unicode string to a function without argtypes
Issue5203
Created on 2009-02-10 12:48 by amaury.forgeotdarc, last changed 2022-04-11 14:56 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg81544 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * ![]() |
Date: 2009-02-10 12:48 | |
The following code segfaults on platforms where HAVE_USABLE_WCHAR_T is
not defined (for example: narrow unicode build and sizeof(wchar_t)==4)
>>> from ctypes import *
>>> import ctypes.util
>>> CDLL(ctypes.util.find_library('c')).wcslen(u'text')
(it works if the argtypes member is defined)
The reason is a non initialized structure, and the correction is trivial:
--- Modules/_ctypes/callproc.c~ 2007-06-15 19:10:41.000000000 +0200
+++ Modules/_ctypes/callproc.c 2009-02-10 13:28:10.000000000 +0100
@@ -538,6 +538,7 @@
int size = PyUnicode_GET_SIZE(obj);
size += 1; /* terminating NUL */
size *= sizeof(wchar_t);
+ pa->ffi_type = &ffi_type_pointer;
pa->value.p = PyMem_Malloc(size);
if (!pa->value.p) {
PyErr_NoMemory();
|
|||
| msg81582 - (view) | Author: Thomas Heller (theller) * ![]() |
Date: 2009-02-10 19:07 | |
Fixed in trunk (rev 69505) and release26-maint (rev 69506). The bug was already fixed in a different way in py3k and release30-maint although in a different way, I merged this exact fix anyway (rev 69507 and rev 69508). Thanks. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:56:45 | admin | set | github: 49453 |
| 2009-02-10 19:07:27 | theller | set | status: open -> closed resolution: fixed messages: + msg81582 versions: + Python 2.7 |
| 2009-02-10 12:48:03 | amaury.forgeotdarc | create | |
