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

Expose BufferError among other pybind11 exceptions #1852

Merged
merged 1 commit into from
Aug 19, 2019

Conversation

mosra
Copy link
Contributor

@mosra mosra commented Jul 21, 2019

A very minor thing, exposing python's BufferError among other exception types. Useful when dealing with py::buffer_protocol{} interfaces. Not sure if any tests need to be added for this, I guess not :)

Thank you!

@wjakob
Copy link
Member

wjakob commented Aug 15, 2019

This looks fine. For posterity, can you give an example of a potential use case that involves throwing a hypothetical py::buffer_error from C++?

@mosra
Copy link
Contributor Author

mosra commented Aug 15, 2019

Is a link to another repo fine? This is one use case: https://github.com/mosra/magnum-bindings/blob/1ec72697322715ce1d79cdd2eb22f11c1a6fc0af/src/python/corrade/containers.cpp#L121-L122

 if(buffer.strides && buffer.strides[0] != buffer.itemsize)
    throw py::buffer_error{Utility::formatString("expected stride of {} but got {}", 
        buffer.itemsize, buffer.strides[0])};

Basically, any error handling in py::init() that takes a py::buffer, or in in a def_buffer() would be throwing these.

@wjakob
Copy link
Member

wjakob commented Aug 19, 2019

Ok, sounds good :)

@wjakob wjakob merged commit 04c8f4b into pybind:master Aug 19, 2019
@mosra mosra deleted the add-buffer-error-exception branch August 19, 2019 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants