-
Notifications
You must be signed in to change notification settings - Fork 2.2k
pybind11::str::raw_str simplification (for Python 2) #2367
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -930,12 +930,12 @@ class str : public object { | |
private: | ||
/// Return string representation -- always returns a new reference, even if already a str | ||
static PyObject *raw_str(PyObject *op) { | ||
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; | ||
PyObject *str_value = PyObject_Unicode(op); | ||
#else | ||
PyObject *str_value = PyObject_Str(op); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have a ton of compatibility macros in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks Boris, I'm inclined to take your suggestions, although it makes it a (slightly) sprawling change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be fine with a compatibility macro living in |
||
#endif | ||
if (!str_value) throw error_already_set(); | ||
return str_value; | ||
} | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one line went missing but is important! (Unless this can never fail?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Important to add a test for this as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm. Just noticed this will be done by the code generated by
PYBIND11_OBJECT_CVT
;-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, sorry, that was an accident (manual cherry-picking). I fixed it quick to get that part out of the way. More changes later.