summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-04-27 11:55:39 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2012-04-27 11:55:39 (GMT)
commit8f825060f1c168b913f2ac299ca48d4e9375f34d (patch)
tree8f8a2fe0d64cd2fdf98fdb762ff1def490473bde /Python
parent990eff0776a948b4a45b1c2750552c0c6864b5c7 (diff)
downloadcpython-8f825060f1c168b913f2ac299ca48d4e9375f34d.zip
cpython-8f825060f1c168b913f2ac299ca48d4e9375f34d.tar.gz
cpython-8f825060f1c168b913f2ac299ca48d4e9375f34d.tar.bz2
Check newly created consistency using _PyUnicode_CheckConsistency(str, 1)
* In debug mode, fill the string data with invalid characters * Simplify also reference counting in PyCodec_BackslashReplaceErrors() and PyCodec_XMLCharRefReplaceError()
Diffstat (limited to 'Python')
-rw-r--r--Python/codecs.c10
-rw-r--r--Python/compile.c1
-rw-r--r--Python/import.c1
3 files changed, 8 insertions, 4 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index 607feea..797a45f 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -534,6 +534,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
data = PyUnicode_DATA(res);
for (i = 0; i < len; ++i)
PyUnicode_WRITE(kind, data, i, '?');
+ assert(_PyUnicode_CheckConsistency(res, 1));
return Py_BuildValue("(Nn)", res, end);
}
else if (PyObject_IsInstance(exc, PyExc_UnicodeDecodeError)) {
@@ -559,6 +560,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
data = PyUnicode_DATA(res);
for (i=0; i < len; i++)
PyUnicode_WRITE(kind, data, i, Py_UNICODE_REPLACEMENT_CHARACTER);
+ assert(_PyUnicode_CheckConsistency(res, 1));
return Py_BuildValue("(Nn)", res, end);
}
else {
@@ -652,8 +654,8 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
}
*outp++ = ';';
}
- restuple = Py_BuildValue("(On)", res, end);
- Py_DECREF(res);
+ assert(_PyUnicode_CheckConsistency(res, 1));
+ restuple = Py_BuildValue("(Nn)", res, end);
Py_DECREF(object);
return restuple;
}
@@ -720,8 +722,8 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
*outp++ = Py_hexdigits[c&0xf];
}
- restuple = Py_BuildValue("(On)", res, end);
- Py_DECREF(res);
+ assert(_PyUnicode_CheckConsistency(res, 1));
+ restuple = Py_BuildValue("(Nn)", res, end);
Py_DECREF(object);
return restuple;
}
diff --git a/Python/compile.c b/Python/compile.c
index 79d1d21..10e9ad2 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -263,6 +263,7 @@ _Py_Mangle(PyObject *privateobj, PyObject *ident)
Py_DECREF(result);
return NULL;
}
+ assert(_PyUnicode_CheckConsistency(result, 1));
return result;
}
diff --git a/Python/import.c b/Python/import.c
index 8cf10e6..103e7de 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -992,6 +992,7 @@ make_source_pathname(PyObject *path)
(j = dot0-right));
PyUnicode_WRITE(kind, data, i+j, 'p');
PyUnicode_WRITE(kind, data, i+j+1, 'y');
+ assert(_PyUnicode_CheckConsistency(result, 1));
return result;
}