Special case Lua copy-construction of trackable instances
authorRobin Gareus <robin@gareus.org>
Fri, 12 Apr 2019 02:12:22 +0000 (04:12 +0200)
committerRobin Gareus <robin@gareus.org>
Fri, 12 Apr 2019 03:45:27 +0000 (05:45 +0200)
commit3da07e6736bfc79fa4f61b58a65f025e0fa88c62
tree6e73ebee200d5d2f9f78578e2e2bf532579b3a3a
parent8dc883ebfac1560917948bc30f7f69cb8f76fc97
Special case Lua copy-construction of trackable instances

This fixes an crashing issue with ArdourUI.SelectionList a bug
introduced in 6dc3bdf252c and 35dcd46d7d.

Since removal of the special cases in 35dcd46d7d, when using
a C-pointer in a std::list<>,
  std::list<class*>::push_back(TypeListValue)
TypeListValues<>'s Head was expanded to  "class*& const"
implied by void ::push_back(const T& value);

This resulted in lifetime issues with a classes that derive
from sigc::trackable (e.g. Ardour's Selection).
The reference leaves scope and isn't duplicated when it is pushed back
to the std::list<>.

The script scripts/select_every_2nd_region.lua crashed because entries
in the SelectionList were no longer valid.

Previously (before 6dc3bdf252c) TypeListValues explicitly
copy-constructed the value to work around the lifetime issue.
This new solution bypasses the issue by directly using the c-pointer
without dereferencing it.
libs/lua/LuaBridge/detail/CFunctions.h
libs/lua/LuaBridge/detail/Namespace.h