Skip to content
Snippets Groups Projects
Commit 3a526cb3 authored by Alexandre Janniaux's avatar Alexandre Janniaux Committed by Hugo Beauzée-Luyssen
Browse files

vlc_objects: simplify VLC_OBJECT cast handling

Like done by _Generic in the C version, use overloading functions to
define the correct casting behaviour depending on whether the pointer
is already a vlc_object_t or possess a vlc_object_t as ->obj.

This removes the need for listing all the objects which need a casting
case, and non-vlc_object_t objects will fail with the following error:

    include/vlc_objects.h: In instantiation of ‘vlc_object_t* VLC_OBJECT(T*) [with T = {anonymous}::demux_sys_t; vlc_object_t = vlc_object_t]’:
    include/vlc_objects.h:83:18: error: ‘struct {anonymous}::demux_sys_t’ has no member named ‘obj’

or, if there is a obj field which is not a vlc_object_t:

    include/vlc_objects.h: In instantiation of ‘vlc_object_t* VLC_OBJECT(T*) [with T = Open(vlc_object_t*)::foo; vlc_object_t = vlc_object_t]’:
    include/vlc_objects.h:83:18: error: cannot convert ‘Open(vlc_object_t*)::foo::obj*’ to ‘vlc_object_t*’ in return
       83 |     { return &d->obj; }
          |               ~~~^~~
          |                  |
          |                  Open(vlc_object_t*)::foo::obj*
parent 84016b14
No related branches found
No related tags found
No related merge requests found
......@@ -72,42 +72,15 @@ struct vlc_object_t
struct vlc_object_marker *: (x), \
default: (&((x)->obj)) \
)
# define vlc_object_cast(t)
#else
static inline vlc_object_t *VLC_OBJECT(vlc_object_t *o)
{
return o;
}
{ return o; }
# define vlc_object_cast(t) \
struct t; \
static inline struct vlc_object_t *VLC_OBJECT(struct t *d) \
{ \
return (struct vlc_object_t *)d; \
}
template<typename T>
static inline vlc_object_t *VLC_OBJECT(T *d)
{ return &d->obj; }
#endif
vlc_object_cast(libvlc_int_t)
vlc_object_cast(intf_thread_t)
vlc_object_cast(stream_t)
vlc_object_cast(stream_directory_t)
vlc_object_cast(stream_extractor_t)
vlc_object_cast(decoder_t)
vlc_object_cast(filter_t)
vlc_object_cast(audio_output)
vlc_object_cast(vout_thread_t)
vlc_object_cast(vout_display_t)
vlc_object_cast(vout_window_t)
vlc_object_cast(sout_stream_t)
vlc_object_cast(sout_access_out_t)
vlc_object_cast(extensions_manager_t)
vlc_object_cast(fingerprinter_thread_t)
vlc_object_cast(demux_meta_t)
vlc_object_cast(xml_t)
vlc_object_cast(services_discovery_t)
vlc_object_cast(vlc_renderer_discovery_t)
vlc_object_cast(vlc_medialibrary_module_t)
/* The root object */
struct libvlc_int_t
{
......
......@@ -111,8 +111,6 @@ struct qt_intf_t
bool isShuttingDown;
};
vlc_object_cast(qt_intf_t)
/**
* This class may be used for scope-bound locking/unlocking
* of a player_t*. As hinted, the player is locked when
......
......@@ -283,8 +283,6 @@ struct vlc_player_t
struct vlc_player_timer timer;
};
vlc_object_cast(vlc_player_t);
#ifndef NDEBUG
/*
* Assert that the player mutex is locked.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment