After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 754464 - Add support for g_autoptr() and friends
Add support for g_autoptr() and friends
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
unspecified
Other Linux
: Normal enhancement
: 1.7.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-09-02 14:50 UTC by Xavier Claessens
Modified: 2015-12-14 20:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add gst-autocleanup.h (4.63 KB, patch)
2015-10-06 19:17 UTC, Xavier Claessens
none Details | Review
Script used to generate autocleanup header (1.15 KB, text/x-python)
2015-10-06 19:19 UTC, Xavier Claessens
  Details
Script to generate gst-*-autocleanups.h (2.54 KB, text/x-python)
2015-10-06 20:23 UTC, Xavier Claessens
  Details
Add gst-*-autocleanups.h (12.24 KB, patch)
2015-10-07 00:07 UTC, Xavier Claessens
none Details | Review
Add gst-*-autocleanups.h (21.61 KB, patch)
2015-10-08 09:53 UTC, Xavier Claessens
none Details | Review
Add gst-*-autocleanups.h (4.68 KB, patch)
2015-10-08 09:54 UTC, Xavier Claessens
none Details | Review
Add gst-*-autocleanups.h (4.24 KB, patch)
2015-10-08 09:55 UTC, Xavier Claessens
none Details | Review
Script used to generate patches (2.14 KB, text/x-python)
2015-11-10 17:45 UTC, Xavier Claessens
  Details
Add g_autoptr() support to all types (39.41 KB, patch)
2015-11-10 17:50 UTC, Xavier Claessens
none Details | Review
Add g_autoptr() support to all types (22.94 KB, patch)
2015-11-10 17:55 UTC, Xavier Claessens
none Details | Review
Add g_autoptr() support to all types (6.00 KB, patch)
2015-11-10 19:10 UTC, Xavier Claessens
none Details | Review
Add g_autoptr() support to all types (22.94 KB, patch)
2015-11-10 19:12 UTC, Xavier Claessens
none Details | Review
core: Add g_autoptr() support to all types (39.42 KB, patch)
2015-11-10 19:14 UTC, Xavier Claessens
committed Details | Review
base: Add g_autoptr() support to all types (22.95 KB, patch)
2015-11-10 19:15 UTC, Xavier Claessens
committed Details | Review
bad: Add g_autoptr() support to all types (6.01 KB, patch)
2015-11-10 19:15 UTC, Xavier Claessens
committed Details | Review
rtsp-server: Add g_autoptr() support to all types (11.02 KB, patch)
2015-11-10 19:18 UTC, Xavier Claessens
committed Details | Review

Description Xavier Claessens 2015-09-02 14:50:12 UTC
It would be nice if all GStreamer libraries (those who install header files) define the autoptr function for all their typedefs, using one of those macro:
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC
G_DEFINE_AUTO_CLEANUP_FREE_FUNC
G_DEFINE_AUTOPTR_CLEANUP_FUNC

That would allow:
 - Use of G_DECLARE_* in GStreamer itself and in applications using it when subclassing a gst type.
 - Use of g_autoptr() in applications that don't care about other compilers than gcc/clang. Notably GStreamer itself shouldn't use it to keep compat with MSVC.

Note that it doesn't mean that GStreamer itself would depend on gcc/clang since those macro does nothing when not supported by the compiler.

Those macros are new in glib 2.44, and GStreamer isn't probably going to depend on it any time soon (is it?). But applications using gst often can depend on newer glib, so it would make sense to add a gst-autocleanups.h file like the one in gobject/gio/gtk but starting with a #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC.
Comment 1 Sebastian Dröge (slomo) 2015-09-02 14:53:59 UTC
I'm not sure I like this idea, it will cause people to write GStreamer code that does not compile on e.g. MSVC... and then later makes porting for them more work than if they didn't use the magic autoptr stuff in the first place.
Comment 2 Xavier Claessens 2015-09-02 15:34:04 UTC
You could disable that header when building gst itself if you like. But nothing prevents people to use g_autoptr() with glib/gio types already. That's a policy you'll have to enforce when reviewing code. It is of course not really useful for gst itself but is really nice to people using gst.
Comment 3 Xavier Claessens 2015-09-02 15:40:16 UTC
Note that glib/gtk are in the same case: they can't use g_autoptr in their code, but they have that header for apps that can.
Comment 4 Xavier Claessens 2015-09-02 15:43:40 UTC
Oh, and G_DECLARE_FINAL/DERIVABLE/TYPE can be used in gst itself (when it deps on glib 2.44) but it needs the G_DEFINE_AUTOPTR_CLEANUP_FUNC() for its base class.
Comment 5 Xavier Claessens 2015-10-06 19:17:09 UTC
Created attachment 312755 [details] [review]
Add gst-autocleanup.h
Comment 6 Xavier Claessens 2015-10-06 19:19:20 UTC
Created attachment 312756 [details]
Script used to generate autocleanup header

I wrote that quick python script to extract all records/class from a .gir file and output the corresponding G_DEFINE_AUTOPTR_CLEANUP_FUNC(). It can be used to create a header for all other gst libs that install public API.
Comment 7 Xavier Claessens 2015-10-06 20:23:52 UTC
Created attachment 312758 [details]
Script to generate gst-*-autocleanups.h

All files can be generated at once with:
  for f in `find -name "*.gir"`; do gen-autocleanup.py $f; done
Comment 8 Xavier Claessens 2015-10-07 00:07:27 UTC
Created attachment 312777 [details] [review]
Add gst-*-autocleanups.h
Comment 9 Xavier Claessens 2015-10-08 09:53:24 UTC
Created attachment 312897 [details] [review]
Add gst-*-autocleanups.h
Comment 10 Xavier Claessens 2015-10-08 09:54:35 UTC
Created attachment 312899 [details] [review]
Add gst-*-autocleanups.h
Comment 11 Xavier Claessens 2015-10-08 09:55:47 UTC
Created attachment 312900 [details] [review]
Add gst-*-autocleanups.h
Comment 12 Xavier Claessens 2015-10-08 09:58:27 UTC
Did the job for core/base/bad/rtsp-server (good doesn't expose APIs).
Comment 13 Sebastian Dröge (slomo) 2015-11-04 20:27:24 UTC
Should be a blocker IMHO as it's needed for G_DECLARE_*_TYPE, which is very convenient API (and portable) for people who can depend on new enough GLib.
Comment 14 Xavier Claessens 2015-11-10 17:45:26 UTC
Created attachment 315198 [details]
Script used to generate patches

I updated the script to add the G_DEFINE_AUTOPTR_CLEANUP_FUNC in each header instead of grouping them all in a single header. This allows using G_DECLARE_* even when including individual headers instead of having to include the global .h file. Especially important when we'll starting using it in gst itself.
Comment 15 Xavier Claessens 2015-11-10 17:50:03 UTC
Created attachment 315199 [details] [review]
Add g_autoptr() support to all types
Comment 16 Xavier Claessens 2015-11-10 17:55:08 UTC
Created attachment 315200 [details] [review]
Add g_autoptr() support to all types
Comment 17 Xavier Claessens 2015-11-10 19:10:01 UTC
Created attachment 315204 [details] [review]
Add g_autoptr() support to all types

Note that many types in mpegts does not expose their
free func, they are omitted from this patch.
Comment 18 Xavier Claessens 2015-11-10 19:12:53 UTC
Created attachment 315205 [details] [review]
Add g_autoptr() support to all types
Comment 19 Xavier Claessens 2015-11-10 19:14:08 UTC
Created attachment 315207 [details] [review]
core: Add g_autoptr() support to all types
Comment 20 Xavier Claessens 2015-11-10 19:15:05 UTC
Created attachment 315208 [details] [review]
base: Add g_autoptr() support to all types
Comment 21 Xavier Claessens 2015-11-10 19:15:34 UTC
Created attachment 315209 [details] [review]
bad: Add g_autoptr() support to all types

Note that many types in mpegts does not expose their
free func, they are omitted from this patch.
Comment 22 Xavier Claessens 2015-11-10 19:18:07 UTC
Created attachment 315210 [details] [review]
rtsp-server: Add g_autoptr() support to all types
Comment 23 Nicolas Dufresne (ndufresne) 2015-12-14 17:08:51 UTC
Ok, I'll start merging this in 1.7 dev. Note, I'll do one repo at the time, and wait for the build results.
Comment 24 Nicolas Dufresne (ndufresne) 2015-12-14 17:10:20 UTC
Comment on attachment 315207 [details] [review]
core: Add g_autoptr() support to all types

Attachment 315207 [details] pushed as 46f83f5 - core: Add g_autoptr() support to all types
Comment 25 Nicolas Dufresne (ndufresne) 2015-12-14 18:44:18 UTC
Comment on attachment 315208 [details] [review]
base: Add g_autoptr() support to all types

Attachment 315208 [details] pushed as 429860e - base: Add g_autoptr() support to all types
Comment 26 Nicolas Dufresne (ndufresne) 2015-12-14 19:48:41 UTC
Attachment 315209 [details] pushed as 598ddae - bad: Add g_autoptr() support to all types
Comment 27 Nicolas Dufresne (ndufresne) 2015-12-14 19:49:29 UTC
Comment on attachment 315210 [details] [review]
rtsp-server: Add g_autoptr() support to all types

commit 0ea68a1b0ff01725892b666eb8a4299a75ec39b1
Author: Xavier Claessens <xavier.claessens@collabora.com>
Date:   Tue Nov 10 14:17:18 2015 -0500

    rtsp-server: Add g_autoptr() support to all types
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754464
Comment 28 Nicolas Dufresne (ndufresne) 2015-12-14 19:49:46 UTC
Thanks !