Better error message if ucnhash cannot be found (obscure attribute

errors aren't that helpful), or doesn't contain what's expected from
it.  Also tweaked the test script so it compiles even if ucnhash is
missing.
This commit is contained in:
Fredrik Lundh 2001-01-20 11:15:25 +00:00
parent ebb195b270
commit f60560626c
2 changed files with 17 additions and 3 deletions

View file

@ -1240,15 +1240,15 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
PyObject *mod = 0, *v = 0;
mod = PyImport_ImportModule("ucnhash");
if (mod == NULL)
goto onError;
goto ucnhashError;
v = PyObject_GetAttrString(mod,"Unicode_Names_CAPI");
Py_DECREF(mod);
if (v == NULL)
goto onError;
goto ucnhashError;
unicode_names = PyCObject_AsVoidPtr(v);
Py_DECREF(v);
if (unicode_names == NULL)
goto onError;
goto ucnhashError;
}
if (*s == '{') {
@ -1311,6 +1311,11 @@ store:
goto onError;
return (PyObject *)v;
ucnhashError:
PyErr_SetString(PyExc_UnicodeError,
"\\N escapes not supported (can't load ucnhash module)");
return NULL;
onError:
Py_XDECREF(v);
return NULL;