[gobject-introspection] tests: Add a refcounting boxed



commit bb83f34bebdd3581a01f521f8e6fda5a724ae0de
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Jun 1 02:54:46 2012 -0400

    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(+), 0 deletions(-)
---
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.</doc>
         </return-value>
       </method>
     </record>
+    <record name="TestBoxedC"
+            c:type="RegressTestBoxedC"
+            glib:type-name="RegressTestBoxedC"
+            glib:get-type="regress_test_boxed_c_get_type"
+            c:symbol-prefix="test_boxed_c">
+      <field name="refcount" writable="1">
+        <type name="guint" c:type="guint"/>
+      </field>
+      <field name="another_thing" writable="1">
+        <type name="guint" c:type="guint"/>
+      </field>
+      <constructor name="new" c:identifier="regress_test_boxed_c_new">
+        <return-value transfer-ownership="full">
+          <type name="TestBoxedC" c:type="RegressTestBoxedC*"/>
+        </return-value>
+      </constructor>
+    </record>
     <record name="TestBoxedPrivate"
             c:type="RegressTestBoxedPrivate"
             disguised="1">
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))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]