This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author janglin
Recipients effbot, flox, janglin, loewis, pitrou
Date 2010-09-25.13:07:06
SpamBayes Score 7.873313e-09
Marked as misclassified No
Message-id <1285420028.44.0.844166355961.issue9783@psf.upfronthosting.co.za>
In-reply-to
Content
Martin is correct about this patch.

> In cases where we really can't propagate Py_ssize_t to (e.g.
> XML_Parse), we need to check for an int overflow, and raise
> an exception if it does overflow.

Is this an appropriate approach?

int
PySize_AsInt(Py_ssize_t value)
{
    if (value > (Py_ssize_t)INT_MAX || value < (Py_ssize_t)INT_MIN) {
        PyErr_SetString(PyExc_OverflowError, 
                        "Size value can not be represented as an integer");
    }
    return (int)value;
}

I would only define this when sizeof(Py_ssize_t) > sizeof(int) of course. In other cases it would be a macro that just evaluates to value.
I would most likely need an unsigned version as well (although not for this particular issue).

This code could be used in many C modules. Where in the Python code base should such functions be placed?
History
Date User Action Args
2010-09-25 13:07:08janglinsetrecipients: + janglin, loewis, effbot, pitrou, flox
2010-09-25 13:07:08janglinsetmessageid: <1285420028.44.0.844166355961.issue9783@psf.upfronthosting.co.za>
2010-09-25 13:07:07janglinlinkissue9783 messages
2010-09-25 13:07:06janglincreate