Open danielcjacobs opened 2 years ago
Note, if I don't derive from py::trampoline_self_life_support
, the code still compiles and runs without any lifetime issues (and the warning goes away of course).
Ping @rwgk
tried to call pure virtual function The smart holder branch seems intended to solve this very issue.
Only if there is actually a lifetime issue (with pybind11 master), but not in general. It looks like your case is in the "general" domain.
warning: ‘PyFoo’ declared with greater visibility than its base ‘pybind11::trampoline_self_life_support’ [-Wattributes] 134 | class PyFoo : Foo, py::trampoline_self_life_support {
This seems to be related:
With a lot of guessing, PyFoo
seems to have default visibility, while trampoline_self_life_support
has hidden visibility.
Spontaneous best guesses:
Your milage may vary.
Or do you think we need to PYBIND11_EXPORT
‘trampoline_self_life_support’? (I hope not, but it totally depends, I guess.)
Seeing that it works without deriving from py::trampoline_self_life_support
, I'm curious as to what the purpose of inheriting from this class is?
Or do you think we need to PYBIND11_EXPORT ‘trampoline_self_life_support’? (I hope not, but it totally depends, I guess.)
I'm curious, why would we not export this symbol? Seems like it should be exported since it's intended to be used by other libraries.
Seeing that it works without deriving from
py::trampoline_self_life_support
, I'm curious as to what the purpose of inheriting from this class is?
Did you see this already?
Takeaway:
unique_ptr
s between Python and C++.#ifdef
if you want to stay compatible with master).Or do you think we need to PYBIND11_EXPORT ‘trampoline_self_life_support’? (I hope not, but it totally depends, I guess.)
I'm curious, why would we not export this symbol? Seems like it should be exported since it's intended to be used by other libraries.
I'm not sure to be honest, especially because we (Google) internally use "default" visibility, i.e. everything is exported.
I am thinking/guessing for the "external" world that does many things differently, keeping the symbol hidden is better, for situations in which extensions are built with different pybind11 versions, compilers, or options, or all of it.
Unrelated to this issue, I recently got to understand more about -fvisibility=hidden
and namespace pybind11 __attribute__((visibility("hidden")))
(pybind11/detail/common.h).
My thinking now:
py::trampoline_self_life_support
is definitely not the right approach, because it could lead to issues if extensions built with different versions of pybind11 are used in the same process.__attribute__((visibility("hidden")))
, similar to (currently draft) PR #4072.#pragma GCC diagnostic push, ignored, pop
around the trampoline class, to suppress the warning.-DPYBIND11_NAMESPACE=pybind11
, which means all module-local features will be unavailable. That is probably only an option in tightly controlled environments, when it is certain that RTLD_LOCAL
or equivalent is in effect, or that all extensions are built with the same pybind11 version.
Required prerequisites
Problem description
I'm attempting to use the
Progressive
mode to solve a lifetime issue with a trampoline class via the following steps:-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT
to compilation commandsstd::shared_ptr<...>
holder withPYBIND11_SH_DEF(Foo)
public py::trampoline_self_life_support
When I compile, I get this warning:
Reproducible example code