[Python-checkins] commit of r41876 - in python/branches/ssize_t: Objects/unicodeobject.c Python/codecs.c Python/exceptions.c
martin.v.loewis
python-checkins at python.org
Mon Jan 2 19:25:03 CET 2006
Author: martin.v.loewis
Date: Mon Jan 2 19:25:02 2006
New Revision: 41876
Modified:
python/branches/ssize_t/Objects/unicodeobject.c
python/branches/ssize_t/Python/codecs.c
python/branches/ssize_t/Python/exceptions.c
Log:
Fix ssize_t argument parsing and building.
Modified: python/branches/ssize_t/Objects/unicodeobject.c
==============================================================================
--- python/branches/ssize_t/Objects/unicodeobject.c (original)
+++ python/branches/ssize_t/Objects/unicodeobject.c Mon Jan 2 19:25:02 2006
@@ -747,13 +747,12 @@
const char *input, Py_ssize_t insize, Py_ssize_t *startinpos, Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr,
PyObject **output, Py_ssize_t *outpos, Py_UNICODE **outptr)
{
- static char *argparse = "O!i;decoding error handler must return (unicode, int) tuple";
+ static char *argparse = "O!n;decoding error handler must return (unicode, int) tuple";
PyObject *restuple = NULL;
PyObject *repunicode = NULL;
Py_ssize_t outsize = PyUnicode_GET_SIZE(*output);
Py_ssize_t requiredsize;
- int inewpos;
Py_ssize_t newpos;
Py_UNICODE *repptr;
int repsize;
@@ -787,12 +786,10 @@
PyErr_Format(PyExc_TypeError, &argparse[4]);
goto onError;
}
- if (!PyArg_ParseTuple(restuple, argparse, &PyUnicode_Type, &repunicode, &inewpos))
+ if (!PyArg_ParseTuple(restuple, argparse, &PyUnicode_Type, &repunicode, &newpos))
goto onError;
- if (inewpos<0)
- newpos = insize+inewpos;
- else
- newpos = inewpos;
+ if (newpos<0)
+ newpos = insize+newpos;
if (newpos<0 || newpos>insize) {
/* XXX %zd? */
PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", (int)newpos);
@@ -2441,7 +2438,7 @@
Py_ssize_t startpos, Py_ssize_t endpos,
Py_ssize_t *newpos)
{
- static char *argparse = "O!i;encoding error handler must return (unicode, int) tuple";
+ static char *argparse = "O!n;encoding error handler must return (unicode, int) tuple";
PyObject *restuple;
PyObject *resunicode;
Modified: python/branches/ssize_t/Python/codecs.c
==============================================================================
--- python/branches/ssize_t/Python/codecs.c (original)
+++ python/branches/ssize_t/Python/codecs.c Mon Jan 2 19:25:02 2006
@@ -478,7 +478,7 @@
return NULL;
}
/* ouch: passing NULL, 0, pos gives None instead of u'' */
- return Py_BuildValue("(u#i)", &end, 0, end);
+ return Py_BuildValue("(u#n)", &end, 0, end);
}
@@ -502,7 +502,7 @@
for (p = PyUnicode_AS_UNICODE(res), i = start;
i<end; ++p, ++i)
*p = '?';
- restuple = Py_BuildValue("(Oi)", res, end);
+ restuple = Py_BuildValue("(On)", res, end);
Py_DECREF(res);
return restuple;
}
@@ -510,7 +510,7 @@
Py_UNICODE res = Py_UNICODE_REPLACEMENT_CHARACTER;
if (PyUnicodeDecodeError_GetEnd(exc, &end))
return NULL;
- return Py_BuildValue("(u#i)", &res, 1, end);
+ return Py_BuildValue("(u#n)", &res, 1, end);
}
else if (PyObject_IsInstance(exc, PyExc_UnicodeTranslateError)) {
PyObject *res;
@@ -525,7 +525,7 @@
for (p = PyUnicode_AS_UNICODE(res), i = start;
i<end; ++p, ++i)
*p = Py_UNICODE_REPLACEMENT_CHARACTER;
- restuple = Py_BuildValue("(Oi)", res, end);
+ restuple = Py_BuildValue("(On)", res, end);
Py_DECREF(res);
return restuple;
}
@@ -631,7 +631,7 @@
}
*outp++ = ';';
}
- restuple = Py_BuildValue("(Oi)", res, end);
+ restuple = Py_BuildValue("(On)", res, end);
Py_DECREF(res);
Py_DECREF(object);
return restuple;
@@ -708,7 +708,7 @@
*outp++ = hexdigits[c&0xf];
}
- restuple = Py_BuildValue("(Oi)", res, end);
+ restuple = Py_BuildValue("(On)", res, end);
Py_DECREF(res);
Py_DECREF(object);
return restuple;
Modified: python/branches/ssize_t/Python/exceptions.c
==============================================================================
--- python/branches/ssize_t/Python/exceptions.c (original)
+++ python/branches/ssize_t/Python/exceptions.c Mon Jan 2 19:25:02 2006
@@ -919,7 +919,11 @@
if (PyInt_Check(attr)) {
*value = PyInt_AS_LONG(attr);
} else if (PyLong_Check(attr)) {
- *value = (size_t)PyLong_AsLongLong(attr); /* XXX overflow?*/
+ *value = (size_t)PyLong_AsLongLong(attr);
+ if (*value == -1) {
+ Py_DECREF(attr);
+ return -1;
+ }
} else {
PyErr_Format(PyExc_TypeError, "%.200s attribute must be int", name);
Py_DECREF(attr);
@@ -1301,7 +1305,7 @@
const char *encoding, const Py_UNICODE *object, Py_ssize_t length,
Py_ssize_t start, Py_ssize_t end, const char *reason)
{
- return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#iis",
+ return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns",
encoding, object, length, start, end, reason);
}
More information about the Python-checkins
mailing list