From bb83f34bebdd3581a01f521f8e6fda5a724ae0de Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 1 Jun 2012 02:54:46 -0400 Subject: [PATCH] tests: Add a refcounting boxed https://bugzilla.gnome.org/show_bug.cgi?id=677249 --- tests/scanner/Regress-1.0-expected.gir | 17 +++++++++++++++++ tests/scanner/regress.c | 32 ++++++++++++++++++++++++++++++++ tests/scanner/regress.h | 11 +++++++++++ 3 files changed, 60 insertions(+) diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir index b1fd124..e774948 100644 --- a/tests/scanner/Regress-1.0-expected.gir +++ b/tests/scanner/Regress-1.0-expected.gir @@ -171,6 +171,23 @@ use it should be. + + + + + + + + + + + + + diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c index ca8d6ef..13b1888 100644 --- a/tests/scanner/regress.c +++ b/tests/scanner/regress.c @@ -1825,6 +1825,38 @@ G_DEFINE_BOXED_TYPE(RegressTestBoxedB, regress_test_boxed_b_copy, regress_test_boxed_b_free); +RegressTestBoxedC * +regress_test_boxed_c_new (void) +{ + RegressTestBoxedC *boxed; + + boxed = g_slice_new (RegressTestBoxedC); + boxed->refcount = 1; + boxed->another_thing = 42; /* what else */ + + return boxed; +} + +static RegressTestBoxedC * +regress_test_boxed_c_ref (RegressTestBoxedC *boxed) +{ + g_atomic_int_inc (&boxed->refcount); + return boxed; +} + +static void +regress_test_boxed_c_unref (RegressTestBoxedC *boxed) +{ + if (g_atomic_int_dec_and_test (&boxed->refcount)) { + g_slice_free (RegressTestBoxedC, boxed); + } +} + +G_DEFINE_BOXED_TYPE(RegressTestBoxedC, + regress_test_boxed_c, + regress_test_boxed_c_ref, + regress_test_boxed_c_unref); + G_DEFINE_TYPE(RegressTestObj, regress_test_obj, G_TYPE_OBJECT); enum diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h index eeab81b..4d47430 100644 --- a/tests/scanner/regress.h +++ b/tests/scanner/regress.h @@ -328,6 +328,17 @@ GType regress_test_boxed_b_get_type (void); RegressTestBoxedB *regress_test_boxed_b_new (gint8 some_int8, glong some_long); RegressTestBoxedB *regress_test_boxed_b_copy (RegressTestBoxedB *boxed); +typedef struct _RegressTestBoxedC RegressTestBoxedC; + +struct _RegressTestBoxedC +{ + guint refcount; + guint another_thing; +}; + +GType regress_test_boxed_c_get_type (void); +RegressTestBoxedC *regress_test_boxed_c_new (void); + /* gobject */ #define REGRESS_TEST_TYPE_OBJ (regress_test_obj_get_type ()) #define REGRESS_TEST_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), REGRESS_TEST_TYPE_OBJ, RegressTestObj)) -- 2.7.4