Conversation
| #if defined(OIIO_PY_BACKEND_NANOBIND) | ||
| if (!py_str) { | ||
| py::raise_python_error(); | ||
| } | ||
| return py::steal<py::str>(py_str); | ||
| #else | ||
| if (!py_str) { | ||
| throw py::error_already_set(); | ||
| } | ||
| return py::reinterpret_steal<py::str>(py_str); | ||
| #endif |
There was a problem hiding this comment.
I went with a single function definition containing implementation details for both backends, but it would be easy enough to just have two definitions in the oiio_py namespace with the Python API call duplicated if you prefer. Or we could split the difference and alias the exception type and handle stealing functions in py_backend.h in order to collapse this into one code path.
| .OIIO_PY_PROP_RO("name", | ||
| [](const ParamValue& self) { | ||
| return oiio_py::str(self.name().string()); | ||
| return py_str_escaped(self.name().string()); |
There was a problem hiding this comment.
Flagging that I've also wrapped the ParamValue.name accessor, because there's nothing that normalizes/sanitizes attribute names in the C++ API.
|
Those wheel failures are unrelated. I just merged a fix that should take care of them. If you rebase on the current main, they should go away. |
Signed-off-by: Nathan Rusch <nrusch@users.noreply.github.com>
4c4f80b to
7137488
Compare
Signed-off-by: Larry Gritz <lg@larrygritz.com>
lgritz
left a comment
There was a problem hiding this comment.
LGTM!
I added a couple lines to a comment, but otherwise, all looks great and I am merging.
|
Oh OK cool. I can come back and address the spec serialization later, but this should cover most of the potential user-facing issues. |
|
Oh, sorry, did I get ahead of you? If there are more changes you want to make before merging this PR, I can certainly wait. |
Add a new
py_str_escapedhelper function to handle conversion of string-like C++ types topy:strwithout raising aUnicodeDecodeErrorfor non-UTF-8 input data.This function is a fairly simple wrapper that calls the
PyUnicode_DecodeUTF8with the'surrogateescape'error handling scheme (described at https://docs.python.org/3/library/codecs.html#error-handlers) and transfers ownership to the binding-specific object type.Fixes #3856
Tests
Only manual tests so far, but I plan to add some test cases to the harness.
Checklist:
and if I used AI coding assistants, I have an
Assisted-by: TOOL / MODELline in the pull request description above.
behavior.
PR, by pushing the changes to my fork and seeing that the automated CI
passed there. (Exceptions: If most tests pass and you can't figure out why
the remaining ones fail, it's ok to submit the PR and ask for help. Or if
any failures seem entirely unrelated to your change; sometimes things break
on the GitHub runners.)
fixed any problems reported by the clang-format CI test.
corresponding Python bindings. If altering ImageBufAlgo functions, I also
exposed the new functionality as oiiotool options.