Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding test_isinstance_string_types, with asserts simply matching cur… #2256

Closed
wants to merge 9 commits into from
Prev Previous commit
restoring original pybind11::str::raw_str implementation
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Aug 5, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit d7add69f4f38d4d30e36925a2c3831285947b425
9 changes: 9 additions & 0 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
@@ -928,12 +928,21 @@ class str : public object {
private:
/// Return string representation -- always returns a new reference, even if already a str
static PyObject *raw_str(PyObject *op) {
#ifdef PYBIND11_STR_RAW_STR_PY2_EMULATE_UNICODE_CONSTRUCTOR_NOT_IMPLICIT_ENCODE
#if PY_MAJOR_VERSION < 3
PyObject *str_value = PyObject_Unicode(op);
#else
PyObject *str_value = PyObject_Str(op);
#endif
if (!str_value) throw error_already_set();
#else
PyObject *str_value = PyObject_Str(op);
if (!str_value) throw error_already_set();
#if PY_MAJOR_VERSION < 3
PyObject *unicode = PyUnicode_FromEncodedObject(str_value, "utf-8", nullptr);
Py_XDECREF(str_value); str_value = unicode;
#endif
#endif
return str_value;
}
};