Issue 4867: crash in ctypes when passing a string to a function without defining argtypes (original) (raw)

This code works in python 2.5 & 2.6 :

import ctypes lib=ctypes.cdll['./libtcod.so'] lib.TCOD_console_init_root(80,50,'test',0) 1

In python 3.0, it crashes in _CallProc (callproc.c, line 1136) : if (atypes[i]->type == FFI_TYPE_STRUCT atypes[i] == NULL here because when there is no argtypes, the default converter (ConvParam) does not set ffi_type for string parameters if HAVE_USABLE_WCHAR_T is FALSE.

To make it work, I have to define the argtypes for the function :

import ctypes lib=ctypes.cdll['./libtcod.so'] from ctypes import * lib.TCOD_console_init_root.argtypes=[c_int,c_int,c_char_p,c_uint] lib.TCOD_console_init_root(80,50,'test',0) 1

I've compiled python 3.0 on a standard Ubuntu 8.04 and the test_ctypes unit test works fine.