[New-bugs-announce] [issue4867] crash in ctypes when passing a string to a function without defining argtypes

jice report at bugs.python.org
Wed Jan 7 15:41:22 CET 2009


New submission from jice <jice.nospam at gmail.com>:

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.

----------
assignee: theller
components: ctypes
messages: 79334
nosy: jice, theller
severity: normal
status: open
title: crash in ctypes when passing a string to a function without defining argtypes
type: crash
versions: Python 3.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4867>
_______________________________________


More information about the New-bugs-announce mailing list