GNOME Bugzilla – Bug 669671
gobject: use #pragmas to avoid deprecated function warnings
Last modified: 2012-02-15 14:59:24 UTC
I was thinking we might want #ifdef __GNUC__, but gio is already using these without that...
Created attachment 207100 [details] [review] gobject: use #pragmas to avoid deprecated function warnings
Review of attachment 207100 [details] [review]: for g_value_array_insert(), we can use an internal function instead of the pragma.
Created attachment 207101 [details] [review] value-array: Use an internal insert variant To avoid the deprecation warning.
Review of attachment 207101 [details] [review]: Looks good - though I'm not sure if it really needs to be inline
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.
Review of attachment 207101 [details] [review]: sorry, I usually inline internal functions - habit from Clutter.
(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.
Review of attachment 207100 [details] [review]: We could maybe use G_DEFINE_DESTRUCTOR instead of g_atexit for the gobject case ?
Created attachment 207244 [details] [review] gobject: Use a destructor rather than g_atexit() for refcount debugging
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.)
Review of attachment 207254 [details] [review]: looks definitely nicer to me
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...
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 ?
(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.
Created attachment 207267 [details] [review] gobject: Use a destructor rather than g_atexit() for refcount debugging fix !G_HAS_CONSTRUCTORS case
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.
Review of attachment 207267 [details] [review]: looks fine
Review of attachment 207268 [details] [review]: sure
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