[vlc-commits] [Git][videolan/vlc][master] 3 commits: vlc_objects: add extern "C" convention

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Feb 26 12:00:54 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
65790424 by Alexandre Janniaux at 2022-02-26T11:12:41+00:00
vlc_objects: add extern "C" convention

- - - - -
2c43dc1c by Alexandre Janniaux at 2022-02-26T11:12:41+00:00
vlc_objects: add C++ helper for vlc_object_create

When running code in C++, remove the macro which is applying regardless
of the language context, and provide dedicated function overload for the
same effect. In addition, provide a dedicated wrapper avoiding cast and
size specification.

- - - - -
a801f678 by Alexandre Janniaux at 2022-02-26T11:12:41+00:00
modules: use C++ vlc_object_create when possible

- - - - -


5 changed files:

- include/vlc_objects.h
- modules/gui/qt/dialogs/extensions/extensions_manager.cpp
- modules/gui/qt/qt.cpp
- modules/gui/skins2/src/dialogs.cpp
- modules/stream_out/sdi/SDIStream.cpp


Changes:

=====================================
include/vlc_objects.h
=====================================
@@ -81,6 +81,10 @@ static inline vlc_object_t *VLC_OBJECT(T *d)
     { return &d->obj; }
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* The root object */
 struct libvlc_int_t
 {
@@ -273,5 +277,24 @@ VLC_API VLC_MALLOC char *vlc_obj_strdup(vlc_object_t *obj, const char *str);
  */
 VLC_API void vlc_obj_free(vlc_object_t *obj, void *ptr);
 
+#ifdef __cplusplus
+} /* extern "C" */
+
+#undef vlc_object_create
+
+template <typename O> VLC_MALLOC VLC_USED
+static inline void* vlc_object_create(O *obj, size_t size)
+{
+    return vlc_object_create(VLC_OBJECT(obj), size);
+}
+
+template<typename T, typename O> VLC_MALLOC VLC_USED
+static inline T* vlc_object_create(O *obj)
+{
+    static_assert(std::is_pointer<T>::value == false, "vlc_object_create can only create objects");
+    return static_cast<T*>(vlc_object_create(VLC_OBJECT(obj), sizeof(T)));
+}
+#endif
+
 /** @} */
 /** @} */


=====================================
modules/gui/qt/dialogs/extensions/extensions_manager.cpp
=====================================
@@ -69,8 +69,7 @@ bool ExtensionsManager::loadExtensions()
 {
     if( !p_extensions_manager )
     {
-        p_extensions_manager = ( extensions_manager_t* )
-                    vlc_object_create( p_intf, sizeof( extensions_manager_t ) );
+        p_extensions_manager = vlc_object_create<extensions_manager_t>( p_intf );
         if( !p_extensions_manager )
         {
             b_failed = true;


=====================================
modules/gui/qt/qt.cpp
=====================================
@@ -568,7 +568,7 @@ static int OpenIntfCommon( vlc_object_t *p_this, bool dialogProvider )
 {
     auto intfThread = reinterpret_cast<intf_thread_t*>(p_this);
     libvlc_int_t *libvlc = vlc_object_instance( p_this );
-    qt_intf_t* p_intf = (qt_intf_t*)vlc_object_create( libvlc, sizeof( *p_intf ) );
+    auto p_intf = vlc_object_create<qt_intf_t>( libvlc );
     if (!p_intf)
         return VLC_ENOMEM;
     p_intf->obj.logger = vlc_LogHeaderCreate(libvlc->obj.logger, "qt");


=====================================
modules/gui/skins2/src/dialogs.cpp
=====================================
@@ -161,8 +161,7 @@ void Dialogs::destroy( intf_thread_t *pIntf )
 bool Dialogs::init()
 {
     // Allocate descriptor
-    m_pProvider = (intf_thread_t *)vlc_object_create( getIntf(),
-                                                    sizeof( intf_thread_t ) );
+    m_pProvider = vlc_object_create<intf_thread_t>( getIntf() );
     if( m_pProvider == NULL )
         return false;
 


=====================================
modules/stream_out/sdi/SDIStream.cpp
=====================================
@@ -258,9 +258,7 @@ bool AbstractDecodedStream::init(const es_format_t *p_fmt)
         return false;
 
     /* Create decoder object */
-    struct decoder_owner * p_owner =
-            reinterpret_cast<struct decoder_owner *>(
-                vlc_object_create(p_stream, sizeof(*p_owner)));
+    auto p_owner = vlc_object_create<decoder_owner>(p_stream);
     if(!p_owner)
         return false;
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/bb5bfa7bd2a517e185d72eff7572c9736e025514...a801f6789d82e766c8a9be9afdd402f5c7d0406e

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/bb5bfa7bd2a517e185d72eff7572c9736e025514...a801f6789d82e766c8a9be9afdd402f5c7d0406e
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list