Commit aa0e531e authored by Alexandre Vassalotti's avatar Alexandre Vassalotti

Merged revisions 67932 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r67932 | alexandre.vassalotti | 2008-12-27 01:36:10 -0500 (Sat, 27 Dec 2008) | 5 lines

  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.
........
parent 801f9d38
...@@ -418,7 +418,8 @@ void unicode_dealloc(register PyUnicodeObject *unicode) ...@@ -418,7 +418,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; register PyUnicodeObject *v;
...@@ -427,7 +428,7 @@ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length) ...@@ -427,7 +428,7 @@ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return -1; return -1;
} }
v = (PyUnicodeObject *)*unicode; v = *unicode;
if (v == NULL || !PyUnicode_Check(v) || Py_REFCNT(v) != 1 || length < 0) { if (v == NULL || !PyUnicode_Check(v) || Py_REFCNT(v) != 1 || length < 0) {
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return -1; return -1;
...@@ -444,7 +445,7 @@ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length) ...@@ -444,7 +445,7 @@ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
Py_UNICODE_COPY(w->str, v->str, Py_UNICODE_COPY(w->str, v->str,
length < v->length ? length : v->length); length < v->length ? length : v->length);
Py_DECREF(*unicode); Py_DECREF(*unicode);
*unicode = (PyObject *)w; *unicode = w;
return 0; return 0;
} }
...@@ -453,9 +454,10 @@ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length) ...@@ -453,9 +454,10 @@ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
return unicode_resize(v, length); return unicode_resize(v, length);
} }
/* Internal API for use in unicodeobject.c only ! */ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
#define _PyUnicode_Resize(unicodevar, length) \ {
PyUnicode_Resize(((PyObject **)(unicodevar)), length) return _PyUnicode_Resize((PyUnicodeObject **)unicode, length);
}
PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u, PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u,
Py_ssize_t size) Py_ssize_t size)
...@@ -989,7 +991,7 @@ PyUnicode_FromFormatV(const char *format, va_list vargs) ...@@ -989,7 +991,7 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
PyObject_Free(callresults); PyObject_Free(callresults);
if (abuffer) if (abuffer)
PyObject_Free(abuffer); PyObject_Free(abuffer);
_PyUnicode_Resize(&string, s - PyUnicode_AS_UNICODE(string)); PyUnicode_Resize(&string, s - PyUnicode_AS_UNICODE(string));
return string; return string;
fail: fail:
if (callresults) { if (callresults) {
...@@ -1549,7 +1551,7 @@ int unicode_decode_call_errorhandler(const char *errors, PyObject **errorHandler ...@@ -1549,7 +1551,7 @@ int unicode_decode_call_errorhandler(const char *errors, PyObject **errorHandler
const char *encoding, const char *reason, const char *encoding, const char *reason,
const char **input, const char **inend, Py_ssize_t *startinpos, const char **input, const char **inend, Py_ssize_t *startinpos,
Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr, 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 (str, int) tuple"; static char *argparse = "O!n;decoding error handler must return (str, int) tuple";
...@@ -1627,7 +1629,7 @@ int unicode_decode_call_errorhandler(const char *errors, PyObject **errorHandler ...@@ -1627,7 +1629,7 @@ int unicode_decode_call_errorhandler(const char *errors, PyObject **errorHandler
if (requiredsize > outsize) { if (requiredsize > outsize) {
if (requiredsize<2*outsize) if (requiredsize<2*outsize)
requiredsize = 2*outsize; requiredsize = 2*outsize;
if (PyUnicode_Resize(output, requiredsize) < 0) if (_PyUnicode_Resize(output, requiredsize) < 0)
goto onError; goto onError;
*outptr = PyUnicode_AS_UNICODE(*output) + *outpos; *outptr = PyUnicode_AS_UNICODE(*output) + *outpos;
} }
...@@ -1827,7 +1829,7 @@ PyObject *PyUnicode_DecodeUTF7Stateful(const char *s, ...@@ -1827,7 +1829,7 @@ PyObject *PyUnicode_DecodeUTF7Stateful(const char *s,
errors, &errorHandler, errors, &errorHandler,
"utf7", errmsg, "utf7", errmsg,
&starts, &e, &startinpos, &endinpos, &exc, &s, &starts, &e, &startinpos, &endinpos, &exc, &s,
(PyObject **)&unicode, &outpos, &p)) &unicode, &outpos, &p))
goto onError; goto onError;
} }
...@@ -1838,7 +1840,7 @@ PyObject *PyUnicode_DecodeUTF7Stateful(const char *s, ...@@ -1838,7 +1840,7 @@ PyObject *PyUnicode_DecodeUTF7Stateful(const char *s,
errors, &errorHandler, errors, &errorHandler,
"utf7", "unterminated shift sequence", "utf7", "unterminated shift sequence",
&starts, &e, &startinpos, &endinpos, &exc, &s, &starts, &e, &startinpos, &endinpos, &exc, &s,
(PyObject **)&unicode, &outpos, &p)) &unicode, &outpos, &p))
goto onError; goto onError;
if (s < e) if (s < e)
goto restart; goto restart;
...@@ -2166,7 +2168,7 @@ PyObject *PyUnicode_DecodeUTF8Stateful(const char *s, ...@@ -2166,7 +2168,7 @@ PyObject *PyUnicode_DecodeUTF8Stateful(const char *s,
errors, &errorHandler, errors, &errorHandler,
"utf8", errmsg, "utf8", errmsg,
&starts, &e, &startinpos, &endinpos, &exc, &s, &starts, &e, &startinpos, &endinpos, &exc, &s,
(PyObject **)&unicode, &outpos, &p)) &unicode, &outpos, &p))
goto onError; goto onError;
} }
if (consumed) if (consumed)
...@@ -2446,7 +2448,7 @@ PyUnicode_DecodeUTF32Stateful(const char *s, ...@@ -2446,7 +2448,7 @@ PyUnicode_DecodeUTF32Stateful(const char *s,
errors, &errorHandler, errors, &errorHandler,
"utf32", errmsg, "utf32", errmsg,
&starts, (const char **)&e, &startinpos, &endinpos, &exc, (const char **)&q, &starts, (const char **)&e, &startinpos, &endinpos, &exc, (const char **)&q,
(PyObject **)&unicode, &outpos, &p)) &unicode, &outpos, &p))
goto onError; goto onError;
} }
...@@ -2724,7 +2726,7 @@ PyUnicode_DecodeUTF16Stateful(const char *s, ...@@ -2724,7 +2726,7 @@ PyUnicode_DecodeUTF16Stateful(const char *s,
errors, &errorHandler, errors, &errorHandler,
"utf16", errmsg, "utf16", errmsg,
&starts, (const char **)&e, &startinpos, &endinpos, &exc, (const char **)&q, &starts, (const char **)&e, &startinpos, &endinpos, &exc, (const char **)&q,
(PyObject **)&unicode, &outpos, &p)) &unicode, &outpos, &p))
goto onError; goto onError;
} }
...@@ -2949,7 +2951,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s, ...@@ -2949,7 +2951,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
errors, &errorHandler, errors, &errorHandler,
"unicodeescape", "end of string in escape sequence", "unicodeescape", "end of string in escape sequence",
&starts, &end, &startinpos, &endinpos, &exc, &s, &starts, &end, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) &v, &outpos, &p))
goto onError; goto onError;
goto nextByte; goto nextByte;
} }
...@@ -2961,7 +2963,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s, ...@@ -2961,7 +2963,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
errors, &errorHandler, errors, &errorHandler,
"unicodeescape", message, "unicodeescape", message,
&starts, &end, &startinpos, &endinpos, &exc, &s, &starts, &end, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) &v, &outpos, &p))
goto onError; goto onError;
goto nextByte; goto nextByte;
} }
...@@ -3000,7 +3002,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s, ...@@ -3000,7 +3002,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
errors, &errorHandler, errors, &errorHandler,
"unicodeescape", "illegal Unicode character", "unicodeescape", "illegal Unicode character",
&starts, &end, &startinpos, &endinpos, &exc, &s, &starts, &end, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) &v, &outpos, &p))
goto onError; goto onError;
} }
break; break;
...@@ -3042,7 +3044,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s, ...@@ -3042,7 +3044,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
errors, &errorHandler, errors, &errorHandler,
"unicodeescape", message, "unicodeescape", message,
&starts, &end, &startinpos, &endinpos, &exc, &s, &starts, &end, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) &v, &outpos, &p))
goto onError; goto onError;
break; break;
...@@ -3056,7 +3058,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s, ...@@ -3056,7 +3058,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
errors, &errorHandler, errors, &errorHandler,
"unicodeescape", message, "unicodeescape", message,
&starts, &end, &startinpos, &endinpos, &exc, &s, &starts, &end, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) &v, &outpos, &p))
goto onError; goto onError;
} }
else { else {
...@@ -3339,7 +3341,7 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s, ...@@ -3339,7 +3341,7 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
errors, &errorHandler, errors, &errorHandler,
"rawunicodeescape", "truncated \\uXXXX", "rawunicodeescape", "truncated \\uXXXX",
&starts, &end, &startinpos, &endinpos, &exc, &s, &starts, &end, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) &v, &outpos, &p))
goto onError; goto onError;
goto nextByte; goto nextByte;
} }
...@@ -3371,7 +3373,7 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s, ...@@ -3371,7 +3373,7 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
errors, &errorHandler, errors, &errorHandler,
"rawunicodeescape", "\\Uxxxxxxxx out of range", "rawunicodeescape", "\\Uxxxxxxxx out of range",
&starts, &end, &startinpos, &endinpos, &exc, &s, &starts, &end, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) &v, &outpos, &p))
goto onError; goto onError;
} }
nextByte: nextByte:
...@@ -3551,7 +3553,7 @@ PyObject *_PyUnicode_DecodeUnicodeInternal(const char *s, ...@@ -3551,7 +3553,7 @@ PyObject *_PyUnicode_DecodeUnicodeInternal(const char *s,
errors, &errorHandler, errors, &errorHandler,
"unicode_internal", reason, "unicode_internal", reason,
&starts, &end, &startinpos, &endinpos, &exc, &s, &starts, &end, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) { &v, &outpos, &p)) {
goto onError; goto onError;
} }
} }
...@@ -3924,7 +3926,7 @@ PyObject *PyUnicode_DecodeASCII(const char *s, ...@@ -3924,7 +3926,7 @@ PyObject *PyUnicode_DecodeASCII(const char *s,
errors, &errorHandler, errors, &errorHandler,
"ascii", "ordinal not in range(128)", "ascii", "ordinal not in range(128)",
&starts, &e, &startinpos, &endinpos, &exc, &s, &starts, &e, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) &v, &outpos, &p))
goto onError; goto onError;
} }
} }
...@@ -4225,7 +4227,7 @@ PyObject *PyUnicode_DecodeCharmap(const char *s, ...@@ -4225,7 +4227,7 @@ PyObject *PyUnicode_DecodeCharmap(const char *s,
errors, &errorHandler, errors, &errorHandler,
"charmap", "character maps to <undefined>", "charmap", "character maps to <undefined>",
&starts, &e, &startinpos, &endinpos, &exc, &s, &starts, &e, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) { &v, &outpos, &p)) {
goto onError; goto onError;
} }
continue; continue;
...@@ -4275,7 +4277,7 @@ PyObject *PyUnicode_DecodeCharmap(const char *s, ...@@ -4275,7 +4277,7 @@ PyObject *PyUnicode_DecodeCharmap(const char *s,
errors, &errorHandler, errors, &errorHandler,
"charmap", "character maps to <undefined>", "charmap", "character maps to <undefined>",
&starts, &e, &startinpos, &endinpos, &exc, &s, &starts, &e, &startinpos, &endinpos, &exc, &s,
(PyObject **)&v, &outpos, &p)) { &v, &outpos, &p)) {
Py_DECREF(x); Py_DECREF(x);
goto onError; goto onError;
} }
...@@ -5025,7 +5027,7 @@ int charmaptranslate_makespace(PyObject **outobj, Py_UNICODE **outp, ...@@ -5025,7 +5027,7 @@ int charmaptranslate_makespace(PyObject **outobj, Py_UNICODE **outp,
/* exponentially overallocate to minimize reallocations */ /* exponentially overallocate to minimize reallocations */
if (requiredsize < 2 * oldsize) if (requiredsize < 2 * oldsize)
requiredsize = 2 * oldsize; requiredsize = 2 * oldsize;
if (_PyUnicode_Resize(outobj, requiredsize) < 0) if (PyUnicode_Resize(outobj, requiredsize) < 0)
return -1; return -1;
*outp = PyUnicode_AS_UNICODE(*outobj) + outpos; *outp = PyUnicode_AS_UNICODE(*outobj) + outpos;
} }
...@@ -5204,7 +5206,7 @@ PyObject *PyUnicode_TranslateCharmap(const Py_UNICODE *p, ...@@ -5204,7 +5206,7 @@ PyObject *PyUnicode_TranslateCharmap(const Py_UNICODE *p,
/* Resize if we allocated to much */ /* Resize if we allocated to much */
respos = str-PyUnicode_AS_UNICODE(res); respos = str-PyUnicode_AS_UNICODE(res);
if (respos<PyUnicode_GET_SIZE(res)) { if (respos<PyUnicode_GET_SIZE(res)) {
if (_PyUnicode_Resize(&res, respos) < 0) if (PyUnicode_Resize(&res, respos) < 0)
goto onError; goto onError;
} }
Py_XDECREF(exc); Py_XDECREF(exc);
...@@ -7743,7 +7745,7 @@ PyObject *unicode_repr(PyObject *unicode) ...@@ -7743,7 +7745,7 @@ PyObject *unicode_repr(PyObject *unicode)
*p++ = PyUnicode_AS_UNICODE(repr)[0]; *p++ = PyUnicode_AS_UNICODE(repr)[0];
*p = '\0'; *p = '\0';
_PyUnicode_Resize(&repr, p - PyUnicode_AS_UNICODE(repr)); PyUnicode_Resize(&repr, p - PyUnicode_AS_UNICODE(repr));
return repr; return repr;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment