Skip to content

Expose BufferError among other pybind11 exceptions#1852

Merged
wjakob merged 1 commit into
pybind:masterfrom
mosra:add-buffer-error-exception
Aug 19, 2019
Merged

Expose BufferError among other pybind11 exceptions#1852
wjakob merged 1 commit into
pybind:masterfrom
mosra:add-buffer-error-exception

Conversation

@mosra

@mosra mosra commented Jul 21, 2019

Copy link
Copy Markdown
Contributor

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

wjakob commented Aug 15, 2019

Copy link
Copy Markdown
Member

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

mosra commented Aug 15, 2019

Copy link
Copy Markdown
Contributor Author

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

wjakob commented Aug 19, 2019

Copy link
Copy Markdown
Member

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.

2 participants