1 <refentry id="glib-genmarshal" lang="en">
4 <title>glib-genmarshal</title>
5 <productname>GObject</productname>
8 <contrib>Developer</contrib>
9 <firstname>Tim</firstname>
10 <surname>Janik</surname>
16 <refentrytitle>glib-genmarshal</refentrytitle>
17 <manvolnum>1</manvolnum>
18 <refmiscinfo class="manual">User Commands</refmiscinfo>
22 <refname>glib-genmarshal</refname>
23 <refpurpose>C code marshaller generation utility for GLib closures</refpurpose>
28 <command>glib-genmarshal</command>
29 <arg choice="opt" rep="repeat">OPTION</arg>
30 <arg choice="opt" rep="repeat">FILE</arg>
34 <refsect1><title>Description</title>
35 <para><command>glib-genmarshal</command> is a small utility that generates C code
36 marshallers for callback functions of the GClosure mechanism in the GObject
37 sublibrary of GLib. The marshaller functions have a standard signature,
38 they get passed in the invoking closure, an array of value structures holding
39 the callback function parameters and a value structure for the return value
40 of the callback. The marshaller is then responsible to call the respective C
41 code function of the closure with all the parameters on the stack and to
42 collect its return value.
45 <para><command>glib-genmarshal</command> takes a list of marshallers to generate as
46 input. The marshaller list is either read from standard input or from files
47 passed as additional arguments on the command line.
50 <refsect2><title>Marshaller list format</title>
52 The marshaller lists are processed line by line, a line can contain a
53 comment in the form of
54 <informalexample><programlisting>
56 </programlisting></informalexample>
57 or a marshaller specification of the form
59 <replaceable>RTYPE</replaceable>:<replaceable>PTYPE</replaceable>
60 <replaceable>RTYPE</replaceable>:<replaceable>PTYPE</replaceable>,<replaceable>PTYPE</replaceable>
61 <replaceable>RTYPE</replaceable>:<replaceable>PTYPE</replaceable>,<replaceable>PTYPE</replaceable>,<replaceable>PTYPE</replaceable>
63 (up to 16 <replaceable>PTYPE</replaceable>s may be present).
66 The <replaceable>RTYPE</replaceable> part specifies the callback's return
67 type and the <replaceable>PTYPE</replaceable>s right to the colon specify
68 the callback's parameter list, except for the first and the last arguments
69 which are always pointers.
72 <refsect2><title>Parameter types</title>
74 Currently, the following types are supported:
77 <term><replaceable>VOID</replaceable></term>
79 indicates no return type, or no extra parameters.
80 If <replaceable>VOID</replaceable> is used as the parameter list, no
81 additional parameters may be present.
86 <term><replaceable>BOOLEAN</replaceable></term>
88 for boolean types (gboolean)
93 <term><replaceable>CHAR</replaceable></term>
95 for signed char types (gchar)
100 <term><replaceable>UCHAR</replaceable></term>
102 for unsigned char types (guchar)
107 <term><replaceable>INT</replaceable></term>
109 for signed integer types (gint)
114 <term><replaceable>UINT</replaceable></term>
116 for unsigned integer types (guint)
121 <term><replaceable>LONG</replaceable></term>
123 for signed long integer types (glong)
128 <term><replaceable>ULONG</replaceable></term>
130 for unsigned long integer types (gulong)
135 <term><replaceable>INT64</replaceable></term>
137 for signed 64bit integer types (gint64)
142 <term><replaceable>UINT64</replaceable></term>
144 for unsigned 64bit integer types (guint64)
149 <term><replaceable>ENUM</replaceable></term>
151 for enumeration types (gint)
156 <term><replaceable>FLAGS</replaceable></term>
158 for flag enumeration types (guint)
163 <term><replaceable>FLOAT</replaceable></term>
165 for single-precision float types (gfloat)
170 <term><replaceable>DOUBLE</replaceable></term>
172 for double-precision float types (gdouble)
177 <term><replaceable>STRING</replaceable></term>
179 for string types (gchar*)
184 <term><replaceable>BOXED</replaceable></term>
186 for boxed (anonymous but reference counted) types (GBoxed*)
191 <term><replaceable>PARAM</replaceable></term>
193 for GParamSpec or derived types (GParamSpec*)
198 <term><replaceable>POINTER</replaceable></term>
200 for anonymous pointer types (gpointer)
205 <term><replaceable>OBJECT</replaceable></term>
207 for GObject or derived types (GObject*)
212 <term><replaceable>VARIANT</replaceable></term>
214 for GVariant types (GVariant*)
219 <term><replaceable>NONE</replaceable></term>
221 deprecated alias for <replaceable>VOID</replaceable>
226 <term><replaceable>BOOL</replaceable></term>
228 deprecated alias for <replaceable>BOOLEAN</replaceable>
236 <refsect1><title>Options</title>
240 <term><option>--header</option></term>
242 Generate header file contents of the marshallers.
247 <term><option>--body</option></term>
249 Generate C code file contents of the marshallers.
254 <term><option>--prefix=<replaceable>PREFIX</replaceable></option></term>
256 Specify marshaller prefix. The default prefix is <literal>`g_cclosure_marshal'</literal>.
261 <term><option>--skip-source</option></term>
263 Skip source location remarks in generated comments.
268 <term><option>--stdinc</option></term>
270 Use the standard marshallers of the GObject library, and include
271 <filename>gmarshal.h</filename> in generated header files.
276 <term><option>--nostdinc</option></term>
278 Do not use the standard marshallers of the GObject library, and skip
279 <filename>gmarshal.h</filename> include directive in generated header files.
284 <term><option>--internal</option></term>
286 Mark generated functions as internal, using G_GNUC_INTERNAL.
291 <term><option>--valist-marshallers</option></term>
293 Generate valist marshallers, for use with g_signal_set_va_marshaller().
298 <term><option>-v</option>, <option>--version</option></term>
300 Print version information.
305 <term><option>--g-fatal-warnings</option></term>
307 Make warnings fatal, that is, exit immediately once a warning occurs.
312 <term><option>-h</option>, <option>--help</option></term>
314 Print brief help and exit.
319 <term><option>-v</option>, <option>--version</option></term>
321 Print version and exit.
326 <term><option>--output=FILE</option></term>
328 Write output to FILE instead of stdout.
335 <refsect1><title>Example</title>
337 To generate marshallers for the following callback functions:
339 <informalexample><programlisting>
340 void foo (gpointer data1,
342 void bar (gpointer data1,
345 gfloat baz (gpointer data1,
349 </programlisting></informalexample>
351 The <filename>marshaller.list</filename> file has to look like this:
359 and you call glib-genmarshal like this:
362 glib-genmarshal --header marshaller.list > marshaller.h
363 glib-genmarshal --body marshaller.list > marshaller.c
366 The generated marshallers have the arguments encoded in their function name.
367 For this particular list, they are
370 g_cclosure_user_marshal_VOID__VOID(),
371 g_cclosure_user_marshal_VOID__INT(),
372 g_cclosure_user_marshal_FLOAT__BOOLEAN_UCHAR().
375 They can be used directly for GClosures or be passed in as the
376 GSignalCMarshaller c_marshaller; argument upon creation of signals:
378 <informalexample><programlisting>
379 GClosure *cc_foo, *cc_bar, *cc_baz;
381 cc_foo = g_cclosure_new (NULL, foo, NULL);
382 g_closure_set_marshal (cc_foo, g_cclosure_user_marshal_VOID__VOID);
383 cc_bar = g_cclosure_new (NULL, bar, NULL);
384 g_closure_set_marshal (cc_bar, g_cclosure_user_marshal_VOID__INT);
385 cc_baz = g_cclosure_new (NULL, baz, NULL);
386 g_closure_set_marshal (cc_baz, g_cclosure_user_marshal_FLOAT__BOOLEAN_UCHAR);
387 </programlisting></informalexample>
389 <refsect1><title>See also</title>
392 <refentrytitle>glib-mkenums</refentrytitle>
393 <manvolnum>1</manvolnum>