Jon Anglin <jang...@fortresgrand.com> added the comment:

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?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9783>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to