• Jason Rhinelander's avatar
    Fix occassional segfault introduced by #960 · cca20a7f
    Jason Rhinelander authored
    The fix for #960 could result a type being registered multiple times if
    its `__init__` is called multiple times.  This can happen perfectly
    ordinarily when python-side multiple inheritance is involved: for
    example, with a diamond inheritance pattern with each intermediate
    classes invoking the parent constructor.
    
    With the change in #960, the multiple `__init__` calls meant
    `register_instance` was called multiple times, but the deletion only
    deleted it once.  Thus, if a future instance of the same type was
    allocated at the same location, pybind would pick it up as a registered
    type.
    
    This fixes the issue by tracking whether a value pointer has been
    registered to avoid both double-registering it.  (There's also a slight
    optimization of not needing to do a registered_instances lookup when the
    type is known not registered, but this is secondary).
    cca20a7f
common.h 39.1 KB