summaryrefslogtreecommitdiff
path: root/src/if_py_both.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/if_py_both.h')
-rw-r--r--src/if_py_both.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/if_py_both.h b/src/if_py_both.h
index d66e2cbd1..b564d24b5 100644
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -3549,13 +3549,26 @@ StringToLine(PyObject *obj)
if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL)))
return NULL;
- if(PyBytes_AsStringAndSize(bytes, &str, &len) == -1
+ if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1
|| str == NULL)
{
Py_DECREF(bytes);
return NULL;
}
}
+ else
+ {
+#if PY_MAJOR_VERSION < 3
+ PyErr_FORMAT(PyExc_TypeError,
+ N_("expected str() or unicode() instance, but got %s"),
+ Py_TYPE_NAME(obj));
+#else
+ PyErr_FORMAT(PyExc_TypeError,
+ N_("expected bytes() or str() instance, but got %s"),
+ Py_TYPE_NAME(obj));
+#endif
+ return NULL;
+ }
/*
* Error checking: String must not contain newlines, as we