-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Mark exceptions with export to fix exceptions in shared libraries #1769
Conversation
…rent client libraries
Thanks! |
Nice! Something's wrong on Windows, though :-(
Any idea what this problem could be and how it could be solved? |
https://stackoverflow.com/questions/24511376/how-to-dllexport-a-class-derived-from-stdruntime-error Frankly I'm surprised Linux wasn't complaining about this one too |
4498421
to
d351297
Compare
I'm not sure if you'll be able to have this land by hoisting the visibility of Can I ask why you hoisted the visibility on those types? |
Because compilers will throw warnings if I don't, specifically MSVC C4251. the error_already_set exception contains py::object instances, which derives from py::handle. The way I understand it, because these objects are expected to be passed across shared library boundaries, they must be exported to ensure correct behavior on the receiving end. It might be the case that we can simply silence the warning, but as I understand it, that might be dangerous. I don't believe that this will impact binary size, but that's worth double checking |
master sozie-pybind11_tests.cpython-36m-x86_64-linux-gnu.so: So it looks like it does increase binary size by a small amount. However, I think it' still more correct to do this - any time an object passes between shared libraries, it ought to be marked as exported, and these explicitly do. |
Aye, that makes sense. Out of my dogma-fueled paranoia on type privacy, I may suggest reworking However, I'd also suggest waiting until @wjakob weighs in to actually pull the trigger on making that change. |
This looks generally good to me. Two questions/comments:
|
ping? |
@yeswalrus, are you still planning to submit this PR? If so, could you respond to my feedback above? Thanks, |
This was fixed in a later PR: #2999 |
In a setup with two shared libraries, A and B, if A throws an exception, B should be able to catch it. To do this, the exception must have external linkage, otherwise A and B will both have their own separate copies of the type. See https://gcc.gnu.org/wiki/Visibility for more information, but the short version is that all exceptions defined in libraries should be declared with
__attribute__ ((visibility("default")))