Mailing List Archive

PyString_GET_SIZE() (was: CVS: python/dist/src/Objects classobject.c,2.89,2.90 object.c,2.72,2.73)
On Wed, Jun 28, 2000 at 02:57:20PM -0700, Guido van Rossum wrote:
> Update of /cvsroot/python/python/dist/src/Objects
> In directory slayer.i.sourceforge.net:/tmp/cvs-serv5838
>
> Modified Files:
> classobject.c object.c
> Log Message:
> Trent Mick: change a few casts for Win64 compatibility.
>
>
> Index: classobject.c
> ===================================================================
> RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
> retrieving revision 2.89
> retrieving revision 2.90
> diff -C2 -r2.89 -r2.90
> *** classobject.c 2000/06/23 19:37:01 2.89
> --- classobject.c 2000/06/28 21:57:18 2.90
> ***************
> *** 284,288 ****
> if (v == NULL || !PyString_Check(v))
> return "__name__ must be a string object";
> ! if ((long)strlen(PyString_AS_STRING(v)) != PyString_GET_SIZE(v))
> return "__name__ must not contain null bytes";
> set_slot(&c->cl_name, v);
> --- 284,288 ----
> if (v == NULL || !PyString_Check(v))
> return "__name__ must be a string object";
> ! if (strlen(PyString_AS_STRING(v)) != (size_t)PyString_GET_SIZE(v))
> return "__name__ must not contain null bytes";
> set_slot(&c->cl_name, v);

Actually, it would seem to make more sense to place the cast *inside* the
PyString_GET_SIZE() macro. That is the "true" semantic for GET_SIZE.

May as well start some ANSI-fication while we can...

Guido: any problem with my changing the macro?

Cheers,
-g

--
Greg Stein, http://www.lyra.org/
Re: PyString_GET_SIZE() (was: CVS: python/dist/src/Objects classobject.c,2.89,2.90 object.c,2.72,2.73) [ In reply to ]
On Wed, Jun 28, 2000 at 03:17:58PM -0700, Greg Stein wrote:
> On Wed, Jun 28, 2000 at 02:57:20PM -0700, Guido van Rossum wrote:
> > Update of /cvsroot/python/python/dist/src/Objects
> > In directory slayer.i.sourceforge.net:/tmp/cvs-serv5838
> >
> > Modified Files:
> > classobject.c object.c
> > Log Message:
> > Trent Mick: change a few casts for Win64 compatibility.
> >
> >
> > Index: classobject.c
> > ===================================================================
> > RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
> > retrieving revision 2.89
> > retrieving revision 2.90
> > diff -C2 -r2.89 -r2.90
> > *** classobject.c 2000/06/23 19:37:01 2.89
> > --- classobject.c 2000/06/28 21:57:18 2.90
> > ***************
> > *** 284,288 ****
> > if (v == NULL || !PyString_Check(v))
> > return "__name__ must be a string object";
> > ! if ((long)strlen(PyString_AS_STRING(v)) != PyString_GET_SIZE(v))
> > return "__name__ must not contain null bytes";
> > set_slot(&c->cl_name, v);
> > --- 284,288 ----
> > if (v == NULL || !PyString_Check(v))
> > return "__name__ must be a string object";
> > ! if (strlen(PyString_AS_STRING(v)) != (size_t)PyString_GET_SIZE(v))
> > return "__name__ must not contain null bytes";
> > set_slot(&c->cl_name, v);
>
> Actually, it would seem to make more sense to place the cast *inside* the
> PyString_GET_SIZE() macro. That is the "true" semantic for GET_SIZE.
>
> May as well start some ANSI-fication while we can...
>

I agree. Go to town, Greg. :)

Trent

--
Trent Mick
trentm@activestate.com
Re: PyString_GET_SIZE() (was: CVS: python/dist/src/Objects classobject.c,2.89,2.90 object.c,2.72,2.73) [ In reply to ]
> > ! if (strlen(PyString_AS_STRING(v)) != (size_t)PyString_GET_SIZE(v))
>
> Actually, it would seem to make more sense to place the cast *inside* the
> PyString_GET_SIZE() macro. That is the "true" semantic for GET_SIZE.
>
> May as well start some ANSI-fication while we can...
>
> Guido: any problem with my changing the macro?

Please leave the macro alone. The type of the macro should be the
same as the type of the function -- PyString_Size() -- which is int.
If you change this, you potentially get tons of warnings because of
the signed / unsigned nature.

ANSI-fication is a good project for after 1.6. But even then, it's a
separate decision whether the size of a string should be a size_t
instead of an int. (The ob_size field should also change, if so --
with even more consequences.)

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