[Python-bugs-list] [ python-Bugs-465342 ] PyUnicode_GetSize/PyUnicode_GET_SIZE

noreply@sourceforge.net noreply@sourceforge.net
Thu, 27 Sep 2001 07:09:21 -0700


Bugs item #465342, was opened at 2001-09-26 12:31
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=465342&group_id=5470

Category: Unicode
Group: Python 2.1.1
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Andreas Jung (ajung)
Assigned to: M.-A. Lemburg (lemburg)
Summary: PyUnicode_GetSize/PyUnicode_GET_SIZE

Initial Comment:
While rewriting Zopes splitter to understand
I run into the following problem:
PyUnicode_GetSize() returns -1 for Py_Unicode 
object. PyUnicode_GET_SIZE() returns 7536745
for the same object. 

 PyUnicode *doc;
 PyArg_ParseTuple(args,"u", &doc);

 printf("%ld\n", PyUnicode_GetSize(doc));
 printf("%ld\n", PyUnicode_GET_SIZE(doc));

Env: Linux i386, gcc-2.96, Python-2.1.1

Andreas

----------------------------------------------------------------------

>Comment By: M.-A. Lemburg (lemburg)
Date: 2001-09-27 07:09

Message:
Logged In: YES 
user_id=38388

Guido van Rossum wrote:
> 
> (SourceForge is down.)
> 
> > While rewriting Zopes splitter to understand
> > I run into the following problem:
> > PyUnicode_GetSize() returns -1 for Py_Unicode
> > object. PyUnicode_GET_SIZE() returns 7536745
> > for the same object.
> >
> >  PyUnicode *doc;
> >  PyArg_ParseTuple(args,"u", &doc);
> >
> >  printf("%ld\n", PyUnicode_GetSize(doc));
> >  printf("%ld\n", PyUnicode_GET_SIZE(doc));
> >
> > Env: Linux i386, gcc-2.96, Python-2.1.1
> 
> You misunderstand the 'u' format code.  It returns a pointer to a raw
> array of Py_UNICODE characters, not a Python object.  But
> PyUnicode_GetSize() and PyUnicode_GET_SIZE() expect a Python (Unicode)
> object (which has an object header etc.).

Right.
 
> You can use "u#" in the format to get the size in a second (int) argument.

... or the "U" parser marker to actually get at the PyUnicodeObject
and then your code should work.
 
> BTW I can't find a typedef for PyUnicode.  Are you sure you ran this
> code?

... closing the bug report.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=465342&group_id=5470