It's a bit involved as we need to ensure that gl.Context.current doesn't
outline the Application instance, so we need to:
- remember the Application object when it gets constructed (and clear
it again when it gets destructed)
- in gl.Context.current check if there's an active Application (which
means sharing data across two different Python modules, and even
though pybind11 docs suggest to "simply export a symbol", this
*cannot* possibly work in practice; instead we share data using a
Python capsule), and increase its refcount when returning the Context
instance
- decrease the Application refcount again when the Context gets
destructed
Pybind changed py::module to py::module_ in order to support C++
modules, adapting to that change. It still builds on older versions,
but we're using only the new APIs.
Use only py::error_already_set as that's the least heavy of them. Also
changed all occurences of "throw" to "raise" so next time I'm doing a
prune of all C++ exceptions for good, those are easy to find.
Or also making the code coverage happier, since that damn thing reports
uncovered lines when the chained function call is wrapped on multiple
lines. FFS.
Compared to having to subclass every type that can reference external
data, this has several advantages for 3rd party binding code:
* it doesn't need to worry about the additional type when binding
function arguments (currently it had to provide lambdas that accept
the PyFoo subtype instead of just Foo)
* and it can now easily bind those types also for function
return values and properties -- the return type doesn't need to be
subclassed (which in case of move-only types is practically
impossible) but instead just wrapped in a holder along with the
memory owner object reference
The new holders also assert that memory owner is always specified unless
the data is empty.
That makes it much easier to handle in that case (because that's the
whole point of static builds) and also nicely circumvents any issues
with duplicated global data when a static lib would be linked to
multiple dynamic libraries.