[Python-3000] Heaptypes

Thomas Heller theller at ctypes.org
Wed Jul 11 16:08:47 CEST 2007


ctypes creates heaptypes with this call, in _ctypes.c, line 3986 (slightly simplified):

	result = PyObject_CallFunction((PyObject *)&ArrayType_Type,
				       "s(O){s:n,s:O}",
				       name,
				       &Array_Type,
				       "_length_",
				       length,
				       "_type_",
				       itemtype
		);

The call succeeds.  Printing the type fails with an assertion:

theller at tubu:~/devel/py3k-struni$ ./python
Python 3.0x (py3k-struni:56268M, Jul 11 2007, 15:56:43)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import c_int
[54751 refs]
>>> atype = c_int * 3
[54762 refs]
>>> atype.__name__
s'c_int_Array_3'
[55278 refs]
>>> repr(atype)
python: Objects/unicodeobject.c:630: PyUnicodeUCS2_FromFormatV: Assertion `obj && ((((obj)->ob_type)->tp_flags & ((1L<<28))) != 0)' failed.
Abgebrochen
theller at tubu:~/devel/py3k-struni$

As one can see, the __name__ is a byte string (or how is this called now?).
The fix is probably to use an 'U' format character in the PyObject_CallFunction format string,
but I assume the call should have failed in the first place?  And what about the dictionary that
is constructed for the call '{s:n,s:O}', should it use 'U' format chars also?

Thomas



More information about the Python-3000 mailing list