if (module != NULL) {
snprintf(buf, size, "python.%s", module);
Py_XDECREF(mod);
+ PyErr_Clear();
return;
}
Py_XDECREF(mod);
snprintf(buf, size, "python.%p", callback);
+ PyErr_Clear();
}
static void cpy_log_exception(const char *context) {
const char *name;
cpy_callback_t *prev = NULL, *tmp;
- if (PyString_Check(arg)) {
+ if (PyUnicode_Check(arg)) {
+ arg = PyUnicode_AsEncodedString(arg, NULL, NULL);
+ if (arg == NULL)
+ return NULL;
+ name = PyString_AsString(arg);
+ Py_DECREF(arg);
+ } else if (PyString_Check(arg)) {
name = PyString_AsString(arg);
} else {
if (!PyCallable_Check(arg)) {
PyErr_Format(PyExc_RuntimeError, "Unable to unregister %s callback '%s'.", desc, name);
return NULL;
}
- /* Yes, this is actually save. To call this function the calles has to
+ /* Yes, this is actually save. To call this function the caller has to
* hold the GIL. Well, save as long as there is only one GIL anyway ... */
if (prev == NULL)
*list_head = tmp->next;
char buf[512];
const char *name;
- if (PyString_Check(arg)) {
+ if (PyUnicode_Check(arg)) {
+ arg = PyUnicode_AsEncodedString(arg, NULL, NULL);
+ if (arg == NULL)
+ return NULL;
+ name = PyString_AsString(arg);
+ Py_DECREF(arg);
+ } else if (PyString_Check(arg)) {
name = PyString_AsString(arg);
} else {
if (!PyCallable_Check(arg)) {
if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN)
continue;
do_interactive = item->values[0].value.boolean;
+ } else if (strcasecmp(item->key, "Encoding") == 0) {
+ if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_STRING)
+ continue;
+ /* Why is this even necessary? And undocumented? */
+ if (PyUnicode_SetDefaultEncoding(item->values[0].value.string))
+ cpy_log_exception("setting default encoding");
} else if (strcasecmp(item->key, "LogTraces") == 0) {
if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN)
continue;