Remove unnecessary casts related to unicode_decode_call_errorhandler.

Make the _PyUnicode_Resize macro a static function.

These changes are needed to avoid breaking strict aliasing rules.
This commit is contained in:
Alexandre Vassalotti 2008-12-27 06:36:10 +00:00
parent 0fc0747586
commit 034e08ce8d
1 changed files with 29 additions and 27 deletions

View File

@ -386,7 +386,8 @@ void unicode_dealloc(register PyUnicodeObject *unicode)
}
}
int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
static
int _PyUnicode_Resize(PyUnicodeObject **unicode, Py_ssize_t length)
{
register PyUnicodeObject *v;
@ -395,7 +396,7 @@ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
PyErr_BadInternalCall();
return -1;
}
v = (PyUnicodeObject *)*unicode;
v = *unicode;
if (v == NULL || !PyUnicode_Check(v) || Py_REFCNT(v) != 1 || length < 0) {
PyErr_BadInternalCall();
return -1;
@ -412,7 +413,7 @@ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
Py_UNICODE_COPY(w->str, v->str,
length < v->length ? length : v->length);
Py_DECREF(*unicode);
*unicode = (PyObject *)w;
*unicode = w;
return 0;
}
@ -421,9 +422,10 @@ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
return unicode_resize(v, length);
}
/* Internal API for use in unicodeobject.c only ! */
#define _PyUnicode_Resize(unicodevar, length) \
PyUnicode_Resize(((PyObject **)(unicodevar)), length)
int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
{
return _PyUnicode_Resize((PyUnicodeObject **)unicode, length);
}
PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u,
Py_ssize_t size)
@ -937,7 +939,7 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
PyObject_Free(callresults);
if (abuffer)
PyObject_Free(abuffer);
_PyUnicode_Resize(&string, s - PyUnicode_AS_UNICODE(string));
PyUnicode_Resize(&string, s - PyUnicode_AS_UNICODE(string));
return string;
fail:
if (callresults) {
@ -1345,7 +1347,7 @@ int unicode_decode_call_errorhandler(const char *errors, PyObject **errorHandler
const char *encoding, const char *reason,
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)
PyUnicodeObject **output, Py_ssize_t *outpos, Py_UNICODE **outptr)
{
static char *argparse = "O!n;decoding error handler must return (unicode, int) tuple";
@ -1405,7 +1407,7 @@ int unicode_decode_call_errorhandler(const char *errors, PyObject **errorHandler
if (requiredsize > outsize) {
if (requiredsize<2*outsize)
requiredsize = 2*outsize;
if (PyUnicode_Resize(output, requiredsize) < 0)
if (_PyUnicode_Resize(output, requiredsize) < 0)
goto onError;
*outptr = PyUnicode_AS_UNICODE(*output) + *outpos;
}
@ -1604,7 +1606,7 @@ PyObject *PyUnicode_DecodeUTF7Stateful(const char *s,
errors, &errorHandler,
"utf7", errmsg,
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&unicode, &outpos, &p))
&unicode, &outpos, &p))
goto onError;
}
@ -1615,7 +1617,7 @@ PyObject *PyUnicode_DecodeUTF7Stateful(const char *s,
errors, &errorHandler,
"utf7", "unterminated shift sequence",
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&unicode, &outpos, &p))
&unicode, &outpos, &p))
goto onError;
if (s < e)
goto restart;
@ -1942,7 +1944,7 @@ PyObject *PyUnicode_DecodeUTF8Stateful(const char *s,
errors, &errorHandler,
"utf8", errmsg,
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&unicode, &outpos, &p))
&unicode, &outpos, &p))
goto onError;
}
if (consumed)
@ -2222,7 +2224,7 @@ PyUnicode_DecodeUTF32Stateful(const char *s,
errors, &errorHandler,
"utf32", errmsg,
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&unicode, &outpos, &p))
&unicode, &outpos, &p))
goto onError;
}
@ -2496,7 +2498,7 @@ PyUnicode_DecodeUTF16Stateful(const char *s,
errors, &errorHandler,
"utf16", errmsg,
starts, size, &startinpos, &endinpos, &exc, (const char **)&q,
(PyObject **)&unicode, &outpos, &p))
&unicode, &outpos, &p))
goto onError;
}
@ -2717,7 +2719,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
errors, &errorHandler,
"unicodeescape", "end of string in escape sequence",
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p))
&v, &outpos, &p))
goto onError;
goto nextByte;
}
@ -2729,7 +2731,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
errors, &errorHandler,
"unicodeescape", message,
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p))
&v, &outpos, &p))
goto onError;
goto nextByte;
}
@ -2768,7 +2770,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
errors, &errorHandler,
"unicodeescape", "illegal Unicode character",
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p))
&v, &outpos, &p))
goto onError;
}
break;
@ -2810,7 +2812,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
errors, &errorHandler,
"unicodeescape", message,
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p))
&v, &outpos, &p))
goto onError;
break;
@ -2824,7 +2826,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
errors, &errorHandler,
"unicodeescape", message,
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p))
&v, &outpos, &p))
goto onError;
}
else {
@ -3113,7 +3115,7 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
errors, &errorHandler,
"rawunicodeescape", "truncated \\uXXXX",
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p))
&v, &outpos, &p))
goto onError;
goto nextByte;
}
@ -3145,7 +3147,7 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
errors, &errorHandler,
"rawunicodeescape", "\\Uxxxxxxxx out of range",
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p))
&v, &outpos, &p))
goto onError;
}
nextByte:
@ -3315,7 +3317,7 @@ PyObject *_PyUnicode_DecodeUnicodeInternal(const char *s,
errors, &errorHandler,
"unicode_internal", reason,
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) {
&v, &outpos, &p)) {
goto onError;
}
}
@ -3695,7 +3697,7 @@ PyObject *PyUnicode_DecodeASCII(const char *s,
errors, &errorHandler,
"ascii", "ordinal not in range(128)",
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p))
&v, &outpos, &p))
goto onError;
}
}
@ -3996,7 +3998,7 @@ PyObject *PyUnicode_DecodeCharmap(const char *s,
errors, &errorHandler,
"charmap", "character maps to <undefined>",
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) {
&v, &outpos, &p)) {
goto onError;
}
continue;
@ -4046,7 +4048,7 @@ PyObject *PyUnicode_DecodeCharmap(const char *s,
errors, &errorHandler,
"charmap", "character maps to <undefined>",
starts, size, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) {
&v, &outpos, &p)) {
Py_DECREF(x);
goto onError;
}
@ -4797,7 +4799,7 @@ int charmaptranslate_makespace(PyObject **outobj, Py_UNICODE **outp,
/* exponentially overallocate to minimize reallocations */
if (requiredsize < 2 * oldsize)
requiredsize = 2 * oldsize;
if (_PyUnicode_Resize(outobj, requiredsize) < 0)
if (PyUnicode_Resize(outobj, requiredsize) < 0)
return -1;
*outp = PyUnicode_AS_UNICODE(*outobj) + outpos;
}
@ -4976,7 +4978,7 @@ PyObject *PyUnicode_TranslateCharmap(const Py_UNICODE *p,
/* Resize if we allocated to much */
respos = str-PyUnicode_AS_UNICODE(res);
if (respos<PyUnicode_GET_SIZE(res)) {
if (_PyUnicode_Resize(&res, respos) < 0)
if (PyUnicode_Resize(&res, respos) < 0)
goto onError;
}
Py_XDECREF(exc);