Message117362
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? | |
| Date | User | Action | Args | | 2010-09-25 13:07:08 | janglin | set | recipients: + janglin, loewis, effbot, pitrou, flox | | 2010-09-25 13:07:08 | janglin | set | messageid: <1285420028.44.0.844166355961.issue9783@psf.upfronthosting.co.za> | | 2010-09-25 13:07:07 | janglin | link | issue9783 messages | | 2010-09-25 13:07:06 | janglin | create | | |