summaryrefslogtreecommitdiff
path: root/Objects/moduleobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-19 00:03:09 +0000
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-19 00:03:09 +0000
commiteccd1c0fb2d70544c806f4a262b173c3c53ff01d (patch)
tree91cf959b232904a7d97b45232c97cb6e6530df44 /Objects/moduleobject.c
parenta86b943aefa507358817fe6bfeab4bdc702595e5 (diff)
downloadcpython-eccd1c0fb2d70544c806f4a262b173c3c53ff01d.tar.gz
Issue #6697: Fix a crash if a module attribute name contains a surrogate
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r--Objects/moduleobject.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 9ef7339c14..6c6eac1c8d 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -263,10 +263,15 @@ _PyModule_Clear(PyObject *m)
pos = 0;
while (PyDict_Next(d, &pos, &key, &value)) {
if (value != Py_None && PyUnicode_Check(key)) {
- const char *s = _PyUnicode_AsString(key);
- if (s[0] == '_' && s[1] != '_') {
- if (Py_VerboseFlag > 1)
- PySys_WriteStderr("# clear[1] %s\n", s);
+ Py_UNICODE *u = PyUnicode_AS_UNICODE(key);
+ if (u[0] == '_' && u[1] != '_') {
+ if (Py_VerboseFlag > 1) {
+ const char *s = _PyUnicode_AsString(key);
+ if (s != NULL)
+ PySys_WriteStderr("# clear[1] %s\n", s);
+ else
+ PyErr_Clear();
+ }
PyDict_SetItem(d, key, Py_None);
}
}
@@ -276,10 +281,17 @@ _PyModule_Clear(PyObject *m)
pos = 0;
while (PyDict_Next(d, &pos, &key, &value)) {
if (value != Py_None && PyUnicode_Check(key)) {
- const char *s = _PyUnicode_AsString(key);
- if (s[0] != '_' || strcmp(s, "__builtins__") != 0) {
- if (Py_VerboseFlag > 1)
- PySys_WriteStderr("# clear[2] %s\n", s);
+ Py_UNICODE *u = PyUnicode_AS_UNICODE(key);
+ if (u[0] != '_'
+ || PyUnicode_CompareWithASCIIString(key, "__builtins__") != 0)
+ {
+ if (Py_VerboseFlag > 1) {
+ const char *s = _PyUnicode_AsString(key);
+ if (s != NULL)
+ PySys_WriteStderr("# clear[2] %s\n", s);
+ else
+ PyErr_Clear();
+ }
PyDict_SetItem(d, key, Py_None);
}
}