Skip to content
  • Alexandre Janniaux's avatar
    vlc_objects: expose wrappers around vlc_object_create/delete · 6cfbabfc
    Alexandre Janniaux authored and Thomas Guillem's avatar Thomas Guillem committed
    Using placement new and manual call to the destructor. It ensures that
    C++ objects are correctly handled when creating C++ objects through
    vlc_object_create<>(), and that their destructors are correctly called
    when the (C++) object is destroyed.
    
    According to the C++ draft standard, the vlc_object_t won't get
    overwritten by the placement new since (7.1) will apply to the C++
    object being allocated and placement-new'ed, which triggers the default
    initialization of members, and the default initialization of the
    vlc_object_t member enters the (7.3) case since no constructors exists
    for the structure. (It's an extern "C" structure).
    
        To default-initialize an object of type T means:
        (7.1)
        If T is a (possibly cv-qualified) class type ([class]), constructors are considered.
        The applicable constructors are enumerated ([over.match.ctor]), and the best one for the initializer () is chosen through overload resolution ([over.match]).
        The constructor thus selected is called, with an empty argument list, to initialize the object.
        (7.2)
        If T is an array type, each element is default-initialized.
        (7.3)
        Otherwise, no initialization is performed.
        --: https://eel.is/c++draft/dcl.init#general-7
    
    However, it's not possible to use a zero-initializing placement-new
    operation.
    6cfbabfc