Bug 28345 - Add tp_clear_object, tp_clear_pointer analogous to g_clear_error
Summary: Add tp_clear_object, tp_clear_pointer analogous to g_clear_error
Status: RESOLVED FIXED
Alias: None
Product: Telepathy
Classification: Unclassified
Component: tp-glib (show other bugs)
Version: git master
Hardware: Other All
: low enhancement
Assignee: Simon McVittie
QA Contact: Telepathy bugs list
URL: http://git.collabora.co.uk/?p=user/sm...
Whiteboard: we have clearance, clarence
Keywords: patch
Depends on:
Blocks:
 
Reported: 2010-06-01 06:21 UTC by Simon McVittie
Modified: 2010-06-01 07:41 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Simon McVittie 2010-06-01 06:21:36 UTC
Prior art includes g_clear_error in GLib, and Py_CLEAR in CPython.

I'm happy to omit the two commits "configure.ac: check for an optional C++ compiler" and "tests/util-cxx.cpp: check that tp_clear_pointer works..." if reviewers don't feel that they add enough value.

The commit "Use tp_clear_object, tp_clear_pointer in tests" replaces test_clear_object, CLEAR_OBJECT, CLEAR_BOXED and CLEAR_HASH, but does not attempt to use the new macros in every situation where they'd be a code reduction.

Similarly, the commit "Use tp_clear_object, tp_clear_pointer in various places" is not intended to be exhaustive.

I think we should encourage these macros in new code, but not put a lot of effort into replacing existing code with them, much like g_clear_error.
Comment 1 Will Thompson 2010-06-01 06:28:23 UTC
I for one don't really understand the code you compile in the configure.ac check for a C++ compiler.
Comment 2 Simon McVittie 2010-06-01 06:31:28 UTC
(In reply to comment #1)
> I for one don't really understand the code you compile in the configure.ac
> check for a C++ compiler.

+     [[#include <gio/gio.h>]],

This part goes before main(),

+     [[g_type_init (); g_object_unref (g_file_new_for_path ("/"));]])

and this part is the body of main() - it just checks that we a C++ program can link to GIO, from which I use GFile as a convenient easy-to-instantiate GObject in the test.
Comment 3 Will Thompson 2010-06-01 06:38:41 UTC
(In reply to comment #2)
> +     [[g_type_init (); g_object_unref (g_file_new_for_path ("/"));]])
> 
> and this part is the body of main() - it just checks that we a C++ program can
> link to GIO, from which I use GFile as a convenient easy-to-instantiate GObject
> in the test.

Okay, I wondered if there was any particular significance to this code. Then this branch seems fine. (I'd really prefer these were in GLib, though.)
Comment 4 Simon McVittie 2010-06-01 06:39:45 UTC
(In reply to comment #3)
> Okay, I wondered if there was any particular significance to this code. Then
> this branch seems fine. (I'd really prefer these were in GLib, though.)

Thanks. I'll open a GLib bug once I've merged these.
Comment 5 Simon McVittie 2010-06-01 07:41:35 UTC
Fixed in git for 0.11.7.

Also proposed for GLib: https://bugzilla.gnome.org/show_bug.cgi?id=620263


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.