[Python-checkins] cpython (merge default -> default): Merge.
charles-francois.natali
python-checkins at python.org
Tue Oct 4 23:34:48 CEST 2011
http://hg.python.org/cpython/rev/f62c13f5e689
changeset: 72682:f62c13f5e689
parent: 72681:08dd0f9b79fa
parent: 72679:b66033a0f140
user: Charles-François Natali <neologix at free.fr>
date: Tue Oct 04 23:37:43 2011 +0200
summary:
Merge.
files:
Modules/_io/stringio.c | 4 ++
Objects/unicodeobject.c | 52 +++++++++++++++++++++++-----
Python/getargs.c | 21 +++++++---
3 files changed, 60 insertions(+), 17 deletions(-)
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c
--- a/Modules/_io/stringio.c
+++ b/Modules/_io/stringio.c
@@ -131,6 +131,10 @@
return -1;
assert(PyUnicode_Check(decoded));
+ if (PyUnicode_READY(decoded)) {
+ Py_DECREF(decoded);
+ return -1;
+ }
len = PyUnicode_GET_LENGTH(decoded);
assert(len >= 0);
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -2120,6 +2120,10 @@
str_obj = PyUnicode_DecodeUTF8(str, strlen(str), "replace");
if (!str_obj)
goto fail;
+ if (PyUnicode_READY(str_obj)) {
+ Py_DECREF(str_obj);
+ goto fail;
+ }
argmaxchar = PyUnicode_MAX_CHAR_VALUE(str_obj);
maxchar = Py_MAX(maxchar, argmaxchar);
n += PyUnicode_GET_LENGTH(str_obj);
@@ -2625,10 +2629,12 @@
goto onError;
}
Py_DECREF(buffer);
+#ifndef DONT_MAKE_RESULT_READY
if (_PyUnicode_READY_REPLACE(&unicode)) {
Py_DECREF(unicode);
return NULL;
}
+#endif
return unicode;
onError:
@@ -3674,10 +3680,12 @@
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
+#ifndef DONT_MAKE_RESULT_READY
if (_PyUnicode_READY_REPLACE(&unicode)) {
Py_DECREF(unicode);
return NULL;
}
+#endif
return (PyObject *)unicode;
onError:
@@ -4244,10 +4252,12 @@
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
+#ifndef DONT_MAKE_RESULT_READY
if (_PyUnicode_READY_REPLACE(&unicode)) {
Py_DECREF(unicode);
return NULL;
}
+#endif
return (PyObject *)unicode;
onError:
@@ -4747,10 +4757,12 @@
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
+#ifndef DONT_MAKE_RESULT_READY
if (_PyUnicode_READY_REPLACE(&unicode)) {
Py_DECREF(unicode);
return NULL;
}
+#endif
return (PyObject *)unicode;
onError:
@@ -5145,10 +5157,12 @@
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
+#ifndef DONT_MAKE_RESULT_READY
if (_PyUnicode_READY_REPLACE(&unicode)) {
Py_DECREF(unicode);
return NULL;
}
+#endif
return (PyObject *)unicode;
onError:
@@ -5604,10 +5618,12 @@
}
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
+#ifndef DONT_MAKE_RESULT_READY
if (_PyUnicode_READY_REPLACE(&v)) {
Py_DECREF(v);
return NULL;
}
+#endif
return (PyObject *)v;
ucnhashError:
@@ -5905,10 +5921,12 @@
goto onError;
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
+#ifndef DONT_MAKE_RESULT_READY
if (_PyUnicode_READY_REPLACE(&v)) {
Py_DECREF(v);
return NULL;
}
+#endif
return (PyObject *)v;
onError:
@@ -6093,10 +6111,12 @@
goto onError;
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
+#ifndef DONT_MAKE_RESULT_READY
if (_PyUnicode_READY_REPLACE(&v)) {
Py_DECREF(v);
return NULL;
}
+#endif
return (PyObject *)v;
onError:
@@ -6519,10 +6539,12 @@
goto onError;
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
+#ifndef DONT_MAKE_RESULT_READY
if (_PyUnicode_READY_REPLACE(&v)) {
Py_DECREF(v);
return NULL;
}
+#endif
return (PyObject *)v;
onError:
@@ -6713,10 +6735,12 @@
goto retry;
}
#endif
+#ifndef DONT_MAKE_RESULT_READY
if (_PyUnicode_READY_REPLACE(&v)) {
Py_DECREF(v);
return NULL;
}
+#endif
return (PyObject *)v;
}
@@ -7012,10 +7036,12 @@
goto onError;
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
+#ifndef DONT_MAKE_RESULT_READY
if (_PyUnicode_READY_REPLACE(&v)) {
Py_DECREF(v);
return NULL;
}
+#endif
return (PyObject *)v;
onError:
@@ -8057,10 +8083,12 @@
p[i] = '0' + decimal;
}
}
- if (PyUnicode_READY((PyUnicodeObject*)result) == -1) {
+#ifndef DONT_MAKE_RESULT_READY
+ if (_PyUnicode_READY_REPLACE(&result)) {
Py_DECREF(result);
return NULL;
}
+#endif
return result;
}
/* --- Decimal Encoder ---------------------------------------------------- */
@@ -10038,17 +10066,17 @@
goto error;
}
+ if (PyUnicode_READY(left))
+ goto error;
+ if (PyUnicode_READY(right))
+ goto error;
+
if (PyUnicode_CheckExact(left) && left != unicode_empty
&& PyUnicode_CheckExact(right) && right != unicode_empty
&& unicode_resizable(left)
&& (_PyUnicode_KIND(right) <= _PyUnicode_KIND(left)
|| _PyUnicode_WSTR(left) != NULL))
{
- if (PyUnicode_READY(left))
- goto error;
- if (PyUnicode_READY(right))
- goto error;
-
/* Don't resize for ascii += latin1. Convert ascii to latin1 requires
to change the structure size, but characters are stored just after
the structure, and so it requires to move all charactres which is
@@ -10265,10 +10293,12 @@
}
}
assert (j == PyUnicode_GET_LENGTH(u));
- if (PyUnicode_READY(u)) {
+#ifndef DONT_MAKE_RESULT_READY
+ if (_PyUnicode_READY_REPLACE(&u)) {
Py_DECREF(u);
return NULL;
}
+#endif
return (PyObject*) u;
overflow:
@@ -12923,7 +12953,7 @@
if (unicode == NULL)
return NULL;
assert(_PyUnicode_CHECK(unicode));
- if (_PyUnicode_READY_REPLACE(&unicode))
+ if (PyUnicode_READY(unicode))
return NULL;
self = (PyUnicodeObject *) type->tp_alloc(type, 0);
@@ -13131,7 +13161,7 @@
if (PyUnicode_CHECK_INTERNED(s))
return;
if (_PyUnicode_READY_REPLACE(p)) {
- assert(0 && "PyUnicode_READY fail in PyUnicode_InternInPlace");
+ assert(0 && "_PyUnicode_READY_REPLACE fail in PyUnicode_InternInPlace");
return;
}
s = (PyUnicodeObject *)(*p);
@@ -13217,8 +13247,10 @@
n);
for (i = 0; i < n; i++) {
s = (PyUnicodeObject *) PyList_GET_ITEM(keys, i);
- if (PyUnicode_READY(s) == -1)
+ if (PyUnicode_READY(s) == -1) {
+ assert(0 && "could not ready string");
fprintf(stderr, "could not ready string\n");
+ }
switch (PyUnicode_CHECK_INTERNED(s)) {
case SSTATE_NOT_INTERNED:
/* XXX Shouldn't happen */
diff --git a/Python/getargs.c b/Python/getargs.c
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -834,14 +834,21 @@
case 'C': {/* unicode char */
int *p = va_arg(*p_va, int *);
- if (PyUnicode_Check(arg) &&
- PyUnicode_GET_LENGTH(arg) == 1) {
- int kind = PyUnicode_KIND(arg);
- void *data = PyUnicode_DATA(arg);
- *p = PyUnicode_READ(kind, data, 0);
- }
- else
+ int kind;
+ void *data;
+
+ if (!PyUnicode_Check(arg))
return converterr("a unicode character", arg, msgbuf, bufsize);
+
+ if (PyUnicode_READY(arg))
+ RETURN_ERR_OCCURRED;
+
+ if (PyUnicode_GET_LENGTH(arg) != 1)
+ return converterr("a unicode character", arg, msgbuf, bufsize);
+
+ kind = PyUnicode_KIND(arg);
+ data = PyUnicode_DATA(arg);
+ *p = PyUnicode_READ(kind, data, 0);
break;
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list