[Python-Dev] A cast from Py_ssize_t to long (original) (raw)

Thomas Wouters thomas at python.org
Mon Aug 21 16:34:25 CEST 2006


On 8/21/06, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:

Here is a similar problem: typedef struct { ... sizet pos; ... } mmapobject; ... mmaptellmethod(mmapobject *self, PyObject *unused) { CHECKVALID(NULL); return PyIntFromLong((long) self->pos); }

See Modules/mmapmodule.c . Here a cast to ssizet would, technically speaking, not be safe either, but it may be worth using ssizet anyways.

It should call PyInt_FromSize_t, without any casting. That will make it a PyLong if it's bigger than a Py_ssize_t, too.

Is there a simple automated way to detect situations like this? Maybe

there is a win64 compiler that would generate a warning.

I doubt it. Explicit casts are meant to silence warnings (among other things.) Warning for all casts is bound to generate quite a lot of warnings.

-- Thomas Wouters <thomas at python.org>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-dev/attachments/20060821/3f0f7968/attachment.htm



More information about the Python-Dev mailing list