Uh oh!
There was an error while loading. Please reload this page.
Mark exceptions with export to fix exceptions in shared libraries - #1769
Mark exceptions with export to fix exceptions in shared libraries#1769yeswalrus wants to merge 3 commits into
Conversation
…rent client libraries
eacousineau
commented
Apr 19, 2019
Thanks! |
YannickJadoul
commented
Apr 19, 2019
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
d351297Compareeacousineau
commented
Apr 23, 2019
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. |
eacousineau
commented
Apr 27, 2019
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:
|
wjakob
commented
Jul 15, 2019
ping? |
wjakob
commented
Sep 4, 2019
@yeswalrus, are you still planning to submit this PR? If so, could you respond to my feedback above? Thanks, |
Skylion007
commented
Jul 15, 2021
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")))