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 669671 - gobject: use #pragmas to avoid deprecated function warnings
gobject: use #pragmas to avoid deprecated function warnings
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-02-08 13:58 UTC by Dan Winship
Modified: 2012-02-15 14:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gobject: use #pragmas to avoid deprecated function warnings (1.87 KB, patch)
2012-02-08 13:58 UTC, Dan Winship
none Details | Review
value-array: Use an internal insert variant (3.11 KB, patch)
2012-02-08 14:11 UTC, Emmanuele Bassi (:ebassi)
reviewed Details | Review
gobject: Use a destructor rather than g_atexit() for refcount debugging (1.40 KB, patch)
2012-02-10 13:26 UTC, Dan Winship
reviewed Details | Review
Add G_GNUC_BEGIN/END_IGNORE_DEPRECATIONS (5.87 KB, patch)
2012-02-10 14:04 UTC, Dan Winship
reviewed Details | Review
gobject: Use a destructor rather than g_atexit() for refcount debugging (1.27 KB, patch)
2012-02-10 16:15 UTC, Dan Winship
committed Details | Review
Add G_GNUC_BEGIN/END_IGNORE_DEPRECATIONS (6.03 KB, patch)
2012-02-10 16:16 UTC, Dan Winship
committed Details | Review

Description Dan Winship 2012-02-08 13:58:11 UTC
I was thinking we might want #ifdef __GNUC__, but gio is already
using these without that...
Comment 1 Dan Winship 2012-02-08 13:58:13 UTC
Created attachment 207100 [details] [review]
gobject: use #pragmas to avoid deprecated function warnings
Comment 2 Emmanuele Bassi (:ebassi) 2012-02-08 14:10:33 UTC
Review of attachment 207100 [details] [review]:

for g_value_array_insert(), we can use an internal function instead of the pragma.
Comment 3 Emmanuele Bassi (:ebassi) 2012-02-08 14:11:11 UTC
Created attachment 207101 [details] [review]
value-array: Use an internal insert variant

To avoid the deprecation warning.
Comment 4 Matthias Clasen 2012-02-08 15:32:07 UTC
Review of attachment 207101 [details] [review]:

Looks good - though I'm not sure if it really needs to be inline
Comment 5 Colin Walters 2012-02-09 19:00:20 UTC
I want to keep testing deprecated API - duplicating a copy of it inside the test cases both results in duplicate code *and* not testing API that we still ship.
Comment 6 Emmanuele Bassi (:ebassi) 2012-02-09 19:50:02 UTC
Review of attachment 207101 [details] [review]:

sorry, I usually inline internal functions - habit from Clutter.
Comment 7 Emmanuele Bassi (:ebassi) 2012-02-09 19:51:25 UTC
(In reply to comment #5)
> I want to keep testing deprecated API - duplicating a copy of it inside the
> test cases both results in duplicate code *and* not testing API that we still
> ship.

the internal function is inside GValueArray, not the test case; it avoids GValueArray calling a deprecated symbol internally. the public API uses the internal function - as it was always the case.
Comment 8 Matthias Clasen 2012-02-10 00:35:02 UTC
Review of attachment 207100 [details] [review]:

We could maybe use G_DEFINE_DESTRUCTOR instead of g_atexit for the gobject case ?
Comment 9 Dan Winship 2012-02-10 13:26:55 UTC
Created attachment 207244 [details] [review]
gobject: Use a destructor rather than g_atexit() for refcount debugging
Comment 10 Dan Winship 2012-02-10 14:04:35 UTC
Created attachment 207254 [details] [review]
Add G_GNUC_BEGIN/END_IGNORE_DEPRECATIONS

Add new macros to disable -Wdeprecated-declarations around a piece of
code, using the C99 (and GNU89) _Pragma() operator. Replace the
existing use of #pragma for this in gio, and suppress the warnings in
gvaluearray.c as well.

=====

Here's another approach, which is nice because it provides a nice
macro you can use outside of glib too.

_Pragma() is a C99 addition, but gcc appears to support it even with
"-ansi -pedantic". (At least, current gcc does, and older gccs don't
matter because they don't implement "#pragma diagnostic push/pop" so
we don't define the macro there anyway.)
Comment 11 Emmanuele Bassi (:ebassi) 2012-02-10 14:35:14 UTC
Review of attachment 207254 [details] [review]:

looks definitely nicer to me
Comment 12 Matthias Clasen 2012-02-10 15:56:35 UTC
Review of attachment 207254 [details] [review]:

::: glib/docs.c
@@ +1998,3 @@
+ *
+ * This macro can be used either inside or outside of a function body,
+ * but must appear on a line by itself.

I actually got complaints about the pragma in side the function, from people using old gccs. So the last sentence may not really be true.

I also think it would be good to add some guidance here - this is just meant to be a temporary porting tool, adding these guards does not 'fix' deprecations...
Comment 13 Matthias Clasen 2012-02-10 15:59:28 UTC
Review of attachment 207244 [details] [review]:

::: gobject/gobject.c
@@ +348,3 @@
     }
 }
+#endif /* G_HAS_CONSTRUCTORS */

If I read this correctly, the entire debug_objects_atexit function is inside the ifdef here ? Then what is the g_atexit call in the !G_HAS_CONSTRUCTORS case going to use ?
Comment 14 Dan Winship 2012-02-10 16:09:26 UTC
(In reply to comment #12)
> I actually got complaints about the pragma in side the function, from people
> using old gccs.

Yeah, I saw that, but it turns out that those earlier versions don't implement the diagnostic pragmas anyway, so now we just make the macro only expand to the _Pragma call on recent-enough gccs.

(In reply to comment #13)
> If I read this correctly, the entire debug_objects_atexit function is inside
> the ifdef here ? Then what is the g_atexit call in the !G_HAS_CONSTRUCTORS case
> going to use ?

Oops, yeah, originally I made it so debug objects was only supported now if G_HAS_CONSTRUCTORS, but then I realized that I could just keep using g_atexit() in the non-constructor case, but forgot to fix the ifdef.
Comment 15 Dan Winship 2012-02-10 16:15:46 UTC
Created attachment 207267 [details] [review]
gobject: Use a destructor rather than g_atexit() for refcount debugging

fix !G_HAS_CONSTRUCTORS case
Comment 16 Dan Winship 2012-02-10 16:16:35 UTC
Created attachment 207268 [details] [review]
Add G_GNUC_BEGIN/END_IGNORE_DEPRECATIONS

Added to docs:
 * This is
 * useful for when you have one deprecated function calling another
 * one, or when you still have regression tests for deprecated
 * functions.
Comment 17 Matthias Clasen 2012-02-15 03:47:06 UTC
Review of attachment 207267 [details] [review]:

looks fine
Comment 18 Matthias Clasen 2012-02-15 03:47:36 UTC
Review of attachment 207268 [details] [review]:

sure
Comment 19 Dan Winship 2012-02-15 14:59:20 UTC
Attachment 207267 [details] pushed as ab59739 - gobject: Use a destructor rather than g_atexit() for refcount debugging
Attachment 207268 [details] pushed as ca05902 - Add G_GNUC_BEGIN/END_IGNORE_DEPRECATIONS