[Python-3000] Heaptypes

Guido van Rossum guido at python.org
Wed Jul 11 16:15:41 CEST 2007


There are currently three "string" types, here shown with there repr styles:

- str = 'same as unicode in 2.x'
- bytes = b'new, mutable list of small ints'
- str8 = s'same as str in 2.x'

The s'...' notation means it's an 8-bit string (not a bytes array).
This is not supported in the syntax; it's just used on output. (Use
str8(b'...') to create one of these.) I'm still hoping to remove this
type before the release, but it appears to be still necessary so far.

I don't know enouch about ...CallFunction to help you with the rest.

--Guido

On 7/11/07, Thomas Heller <theller at ctypes.org> wrote:
> 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
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list