glib2.0_2.20.1
[mer:glib2_0.git] / tests / gobject / testmarshal.c
1
2 #include        <glib-object.h>
3
4
5 #ifdef G_ENABLE_DEBUG
6 #define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v)
7 #define g_marshal_value_peek_char(v)     g_value_get_char (v)
8 #define g_marshal_value_peek_uchar(v)    g_value_get_uchar (v)
9 #define g_marshal_value_peek_int(v)      g_value_get_int (v)
10 #define g_marshal_value_peek_uint(v)     g_value_get_uint (v)
11 #define g_marshal_value_peek_long(v)     g_value_get_long (v)
12 #define g_marshal_value_peek_ulong(v)    g_value_get_ulong (v)
13 #define g_marshal_value_peek_int64(v)    g_value_get_int64 (v)
14 #define g_marshal_value_peek_uint64(v)   g_value_get_uint64 (v)
15 #define g_marshal_value_peek_enum(v)     g_value_get_enum (v)
16 #define g_marshal_value_peek_flags(v)    g_value_get_flags (v)
17 #define g_marshal_value_peek_float(v)    g_value_get_float (v)
18 #define g_marshal_value_peek_double(v)   g_value_get_double (v)
19 #define g_marshal_value_peek_string(v)   (char*) g_value_get_string (v)
20 #define g_marshal_value_peek_param(v)    g_value_get_param (v)
21 #define g_marshal_value_peek_boxed(v)    g_value_get_boxed (v)
22 #define g_marshal_value_peek_pointer(v)  g_value_get_pointer (v)
23 #define g_marshal_value_peek_object(v)   g_value_get_object (v)
24 #else /* !G_ENABLE_DEBUG */
25 /* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
26  *          Do not access GValues directly in your code. Instead, use the
27  *          g_value_get_*() functions
28  */
29 #define g_marshal_value_peek_boolean(v)  (v)->data[0].v_int
30 #define g_marshal_value_peek_char(v)     (v)->data[0].v_int
31 #define g_marshal_value_peek_uchar(v)    (v)->data[0].v_uint
32 #define g_marshal_value_peek_int(v)      (v)->data[0].v_int
33 #define g_marshal_value_peek_uint(v)     (v)->data[0].v_uint
34 #define g_marshal_value_peek_long(v)     (v)->data[0].v_long
35 #define g_marshal_value_peek_ulong(v)    (v)->data[0].v_ulong
36 #define g_marshal_value_peek_int64(v)    (v)->data[0].v_int64
37 #define g_marshal_value_peek_uint64(v)   (v)->data[0].v_uint64
38 #define g_marshal_value_peek_enum(v)     (v)->data[0].v_long
39 #define g_marshal_value_peek_flags(v)    (v)->data[0].v_ulong
40 #define g_marshal_value_peek_float(v)    (v)->data[0].v_float
41 #define g_marshal_value_peek_double(v)   (v)->data[0].v_double
42 #define g_marshal_value_peek_string(v)   (v)->data[0].v_pointer
43 #define g_marshal_value_peek_param(v)    (v)->data[0].v_pointer
44 #define g_marshal_value_peek_boxed(v)    (v)->data[0].v_pointer
45 #define g_marshal_value_peek_pointer(v)  (v)->data[0].v_pointer
46 #define g_marshal_value_peek_object(v)   (v)->data[0].v_pointer
47 #endif /* !G_ENABLE_DEBUG */
48
49
50 /* BOOLEAN:INT (./testmarshal.list:2) */
51 void
52 test_marshal_BOOLEAN__INT (GClosure     *closure,
53                            GValue       *return_value G_GNUC_UNUSED,
54                            guint         n_param_values,
55                            const GValue *param_values,
56                            gpointer      invocation_hint G_GNUC_UNUSED,
57                            gpointer      marshal_data)
58 {
59   typedef gboolean (*GMarshalFunc_BOOLEAN__INT) (gpointer     data1,
60                                                  gint         arg_1,
61                                                  gpointer     data2);
62   register GMarshalFunc_BOOLEAN__INT callback;
63   register GCClosure *cc = (GCClosure*) closure;
64   register gpointer data1, data2;
65   gboolean v_return;
66
67   g_return_if_fail (return_value != NULL);
68   g_return_if_fail (n_param_values == 2);
69
70   if (G_CCLOSURE_SWAP_DATA (closure))
71     {
72       data1 = closure->data;
73       data2 = g_value_peek_pointer (param_values + 0);
74     }
75   else
76     {
77       data1 = g_value_peek_pointer (param_values + 0);
78       data2 = closure->data;
79     }
80   callback = (GMarshalFunc_BOOLEAN__INT) (marshal_data ? marshal_data : cc->callback);
81
82   v_return = callback (data1,
83                        g_marshal_value_peek_int (param_values + 1),
84                        data2);
85
86   g_value_set_boolean (return_value, v_return);
87 }
88
89 /* STRING:INT (./testmarshal.list:3) */
90 void
91 test_marshal_STRING__INT (GClosure     *closure,
92                           GValue       *return_value G_GNUC_UNUSED,
93                           guint         n_param_values,
94                           const GValue *param_values,
95                           gpointer      invocation_hint G_GNUC_UNUSED,
96                           gpointer      marshal_data)
97 {
98   typedef gchar* (*GMarshalFunc_STRING__INT) (gpointer     data1,
99                                               gint         arg_1,
100                                               gpointer     data2);
101   register GMarshalFunc_STRING__INT callback;
102   register GCClosure *cc = (GCClosure*) closure;
103   register gpointer data1, data2;
104   gchar* v_return;
105
106   g_return_if_fail (return_value != NULL);
107   g_return_if_fail (n_param_values == 2);
108
109   if (G_CCLOSURE_SWAP_DATA (closure))
110     {
111       data1 = closure->data;
112       data2 = g_value_peek_pointer (param_values + 0);
113     }
114   else
115     {
116       data1 = g_value_peek_pointer (param_values + 0);
117       data2 = closure->data;
118     }
119   callback = (GMarshalFunc_STRING__INT) (marshal_data ? marshal_data : cc->callback);
120
121   v_return = callback (data1,
122                        g_marshal_value_peek_int (param_values + 1),
123                        data2);
124
125   g_value_take_string (return_value, v_return);
126 }
127