man-pages/man1/glib-genmarshal.1.html
2021-03-31 01:06:50 +01:00

767 lines
14 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of GLIB-GENMARSHAL</TITLE>
</HEAD><BODY>
<H1>GLIB-GENMARSHAL</H1>
Section: User Commands (1)<BR>Updated: <BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
glib-genmarshal - C code marshaller generation utility for GLib closures
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<DL COMPACT>
<DT id="1">
<B>glib-genmarshal</B> [OPTION...] [FILE...]
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<P>
<B>glib-genmarshal</B>
<DD>is a small utility that generates C code marshallers for callback functions of the GClosure mechanism in the GObject sublibrary of GLib. The marshaller functions have a standard signature, they get passed in the invoking closure, an array of value structures holding the callback function parameters and a value structure for the return value of the callback. The marshaller is then responsible to call the respective C code function of the closure with all the parameters on the stack and to collect its return value.
<P>
<B>glib-genmarshal</B>
takes a list of marshallers to generate as input. The marshaller list is either read from files passed as additional arguments on the command line; or from standard input, by using
-
as the input file.
<A NAME="lbAE">&nbsp;</A>
<H3>Marshaller list format</H3>
<P>
The marshaller lists are processed line by line, a line can contain a comment in the form of
<P>
or a marshaller specification of the form
<P>
<DL COMPACT><DT id="2"><DD>
<PRE>
<I>RTYPE</I>:<I>PTYPE</I>
<I>RTYPE</I>:<I>PTYPE</I>,<I>PTYPE</I>
<I>RTYPE</I>:<I>PTYPE</I>,<I>PTYPE</I>,<I>PTYPE</I>
</PRE>
</DL>
<P>
The
<I>RTYPE</I>
part specifies the callback's return type and the
<I>PTYPE</I>s right to the colon specify the callback's parameter list, except for the first and the last arguments which are always pointers.
<A NAME="lbAF">&nbsp;</A>
<H3>Parameter types</H3>
<P>
Currently, the following types are supported:
<P>
<I>VOID</I>
<DL COMPACT><DT id="3"><DD>
indicates no return type, or no extra parameters. If
<I>VOID</I>
is used as the parameter list, no additional parameters may be present.
</DL>
<P>
<I>BOOLEAN</I>
<DL COMPACT><DT id="4"><DD>
for boolean types (gboolean)
</DL>
<P>
<I>CHAR</I>
<DL COMPACT><DT id="5"><DD>
for signed char types (gchar)
</DL>
<P>
<I>UCHAR</I>
<DL COMPACT><DT id="6"><DD>
for unsigned char types (guchar)
</DL>
<P>
<I>INT</I>
<DL COMPACT><DT id="7"><DD>
for signed integer types (gint)
</DL>
<P>
<I>UINT</I>
<DL COMPACT><DT id="8"><DD>
for unsigned integer types (guint)
</DL>
<P>
<I>LONG</I>
<DL COMPACT><DT id="9"><DD>
for signed long integer types (glong)
</DL>
<P>
<I>ULONG</I>
<DL COMPACT><DT id="10"><DD>
for unsigned long integer types (gulong)
</DL>
<P>
<I>INT64</I>
<DL COMPACT><DT id="11"><DD>
for signed 64bit integer types (gint64)
</DL>
<P>
<I>UINT64</I>
<DL COMPACT><DT id="12"><DD>
for unsigned 64bit integer types (guint64)
</DL>
<P>
<I>ENUM</I>
<DL COMPACT><DT id="13"><DD>
for enumeration types (gint)
</DL>
<P>
<I>FLAGS</I>
<DL COMPACT><DT id="14"><DD>
for flag enumeration types (guint)
</DL>
<P>
<I>FLOAT</I>
<DL COMPACT><DT id="15"><DD>
for single-precision float types (gfloat)
</DL>
<P>
<I>DOUBLE</I>
<DL COMPACT><DT id="16"><DD>
for double-precision float types (gdouble)
</DL>
<P>
<I>STRING</I>
<DL COMPACT><DT id="17"><DD>
for string types (gchar*)
</DL>
<P>
<I>BOXED</I>
<DL COMPACT><DT id="18"><DD>
for boxed (anonymous but reference counted) types (GBoxed*)
</DL>
<P>
<I>PARAM</I>
<DL COMPACT><DT id="19"><DD>
for GParamSpec or derived types (GParamSpec*)
</DL>
<P>
<I>POINTER</I>
<DL COMPACT><DT id="20"><DD>
for anonymous pointer types (gpointer)
</DL>
<P>
<I>OBJECT</I>
<DL COMPACT><DT id="21"><DD>
for GObject or derived types (GObject*)
</DL>
<P>
<I>VARIANT</I>
<DL COMPACT><DT id="22"><DD>
for GVariant types (GVariant*)
</DL>
<P>
<I>NONE</I>
<DL COMPACT><DT id="23"><DD>
deprecated alias for
<I>VOID</I>
</DL>
<P>
<I>BOOL</I>
<DL COMPACT><DT id="24"><DD>
deprecated alias for
<I>BOOLEAN</I>
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>OPTIONS</H2>
<P>
<B>--header</B>
<DL COMPACT><DT id="25"><DD>
Generate header file contents of the marshallers. This option is mutually exclusive with the
<B>--body</B>
option.
</DL>
<P>
<B>--body</B>
<DL COMPACT><DT id="26"><DD>
Generate C code file contents of the marshallers. This option is mutually exclusive with the
<B>--header</B>
option.
</DL>
<P>
<B>--prefix=</B><B></B><I>PREFIX</I>
<DL COMPACT><DT id="27"><DD>
Specify marshaller prefix. The default prefix is
`g_cclosure_user_marshal'.
</DL>
<P>
<B>--skip-source</B>
<DL COMPACT><DT id="28"><DD>
Skip source location remarks in generated comments.
</DL>
<P>
<B>--stdinc</B>
<DL COMPACT><DT id="29"><DD>
Use the standard marshallers of the GObject library, and include
glib-object.h
in generated header files. This option is mutually exclusive with the
<B>--nostdinc</B>
option.
</DL>
<P>
<B>--nostdinc</B>
<DL COMPACT><DT id="30"><DD>
Do not use the standard marshallers of the GObject library, and skip
glib-object.h
include directive in generated header files. This option is mutually exclusive with the
<B>--stdinc</B>
option.
</DL>
<P>
<B>--internal</B>
<DL COMPACT><DT id="31"><DD>
Mark generated functions as internal, using
G_GNUC_INTERNAL.
</DL>
<P>
<B>--valist-marshallers</B>
<DL COMPACT><DT id="32"><DD>
Generate valist marshallers, for use with
<B>g_signal_set_va_marshaller()</B>.
</DL>
<P>
<B>-v</B>, <B>--version</B>
<DL COMPACT><DT id="33"><DD>
Print version information.
</DL>
<P>
<B>--g-fatal-warnings</B>
<DL COMPACT><DT id="34"><DD>
Make warnings fatal, that is, exit immediately once a warning occurs.
</DL>
<P>
<B>-h</B>, <B>--help</B>
<DL COMPACT><DT id="35"><DD>
Print brief help and exit.
</DL>
<P>
<B>-v</B>, <B>--version</B>
<DL COMPACT><DT id="36"><DD>
Print version and exit.
</DL>
<P>
<B>--output=FILE</B>
<DL COMPACT><DT id="37"><DD>
Write output to
<I>FILE</I>
instead of the standard output.
</DL>
<P>
<B>--prototypes</B>
<DL COMPACT><DT id="38"><DD>
Generate function prototypes before the function definition in the C source file, in order to avoid a
missing-prototypes
compiler warning. This option is only useful when using the
<B>--body</B>
option.
</DL>
<P>
<B>--pragma-once</B>
<DL COMPACT><DT id="39"><DD>
Use the
once
pragma instead of an old style header guard when generating the C header file. This option is only useful when using the
<B>--header</B>
option.
</DL>
<P>
<B>--include-header=</B><B></B><I>HEADER</I>
<DL COMPACT><DT id="40"><DD>
Adds a
#include
directive for the given file in the C source file. This option is only useful when using the
<B>--body</B>
option.
</DL>
<P>
<B>-D </B><B></B><I>SYMBOL[=VALUE]</I>
<DL COMPACT><DT id="41"><DD>
Adds a
#define
C pre-processor directive for
<I>SYMBOL</I>
and its given
<I>VALUE</I>, or &quot;1&quot; if the value is unset. You can use this option multiple times; if you do, all the symbols will be defined in the same order given on the command line, before the symbols undefined using the
<B>-U</B>
option. This option is only useful when using the
<B>--body</B>
option.
</DL>
<P>
<B>-U </B><B></B><I>SYMBOL</I>
<DL COMPACT><DT id="42"><DD>
Adds a
#undef
C pre-processor directive to undefine the given
<I>SYMBOL</I>. You can use this option multiple times; if you do, all the symbols will be undefined in the same order given on the command line, after the symbols defined using the
<B>-D</B>
option. This option is only useful when using the
<B>--body</B>
option.
</DL>
<P>
<B>--quiet</B>
<DL COMPACT><DT id="43"><DD>
Minimizes the output of
<B>glib-genmarshal</B>, by printing only warnings and errors. This option is mutually exclusive with the
<B>--verbose</B>
option.
</DL>
<P>
<B>--verbose</B>
<DL COMPACT><DT id="44"><DD>
Increases the verbosity of
<B>glib-genmarshal</B>, by printing debugging information. This option is mutually exclusive with the
<B>--quiet</B>
option.
</DL>
<A NAME="lbAH">&nbsp;</A>
<H2>USING GLIB-GENMARSHAL WITH MESON</H2>
<P>
Meson supports generating closure marshallers using
<B>glib-genmarshal</B>
out of the box in its &quot;gnome&quot; module.
<P>
In your
meson.build
file you will typically call the
gnome.genmarshal()
method with the source list of marshallers to generate:
<P>
<DL COMPACT><DT id="45"><DD>
<PRE>
gnome = import('gnome')
marshal_files = gnome.genmarshal('marshal',
sources: 'marshal.list',
internal: true,
)
</PRE>
</DL>
<P>
The
marshal_files
variable will contain an array of two elements in the following order:
<P>
<DL COMPACT><DT id="46"><DD>
&bull;
a build target for the source file
</DL>
<P>
<DL COMPACT><DT id="47"><DD>
&bull;
a build target for the header file
</DL>
<P>
You should use the returned objects to provide a dependency on every other build target that references the source or header file; for instance, if you are using the source to build a library:
<P>
<DL COMPACT><DT id="48"><DD>
<PRE>
mainlib = library('project',
sources: project_sources + marshal_files,
...
)
</PRE>
</DL>
<P>
Additionally, if you are including the generated header file inside a build target that depends on the library you just built, you must ensure that the internal dependency includes the generated header as a required source file:
<P>
<DL COMPACT><DT id="49"><DD>
<PRE>
mainlib_dep = declare_dependency(sources: marshal_files[1], link_with: mainlib)
</PRE>
</DL>
<P>
You should not include the generated source file as well, otherwise it will be built separately for every target that depends on it, causing build failures. To know more about why all this is required, please refer to the
m[blue]<B>corresponding Meson FAQ entry</B>m[]<FONT SIZE="-2">[1]</FONT>.
<P>
For more information on how to use the method, see the
m[blue]<B>Meson documentation for gnome.genmarshal()</B>m[]<FONT SIZE="-2">[2]</FONT>.
<A NAME="lbAI">&nbsp;</A>
<H2>USING GLIB-GENMARSHAL WITH AUTOTOOLS</H2>
<P>
In order to use
<B>glib-genmarshal</B>
in your project when using Autotools as the build system, you will first need to modify your
configure.ac
file to ensure you find the appropriate command using
<B>pkg-config</B>, similarly as to how you discover the compiler and linker flags for GLib.
<P>
<DL COMPACT><DT id="50"><DD>
<PRE>
PKG_PROG_PKG_CONFIG([0.28])
PKG_CHECK_VAR([GLIB_GENMARSHAL], [glib-2.0], [glib_genmarshal])
</PRE>
</DL>
<P>
In your
Makefile.am
file you will typically need very simple rules to generate the C files needed for the build.
<P>
<DL COMPACT><DT id="51"><DD>
<PRE>
marshal.h: marshal.list
$(AM_V_GEN)$(GLIB_GENMARSHAL) \
--header \
--output=$@ \
$&lt;
marshal.c: marshal.list marshal.h
$(AM_V_GEN)$(GLIB_GENMARSHAL) \
--include-header=marshal.h \
--body \
--output=$@ \
$&lt;
BUILT_SOURCES += marshal.h marshal.c
CLEANFILES += marshal.h marshal.c
EXTRA_DIST += marshal.list
</PRE>
</DL>
<P>
In the example above, the first rule generates the header file and depends on a
marshal.list
file in order to regenerate the result in case the marshallers list is updated. The second rule generates the source file for the same
marshal.list, and includes the file generated by the header rule.
<A NAME="lbAJ">&nbsp;</A>
<H2>EXAMPLE</H2>
<P>
To generate marshallers for the following callback functions:
<P>
<DL COMPACT><DT id="52"><DD>
<PRE>
void foo (gpointer data1,
gpointer data2);
void bar (gpointer data1,
gint param1,
gpointer data2);
gfloat baz (gpointer data1,
gboolean param1,
guchar param2,
gpointer data2);
</PRE>
</DL>
<P>
The
marshaller.list
file has to look like this:
<P>
<DL COMPACT><DT id="53"><DD>
<PRE>
VOID:VOID
VOID:INT
FLOAT:BOOLEAN,UCHAR
</PRE>
</DL>
<P>
and you call glib-genmarshal like this:
<P>
<DL COMPACT><DT id="54"><DD>
<PRE>
glib-genmarshal --header marshaller.list &gt; marshaller.h
glib-genmarshal --body marshaller.list &gt; marshaller.c
</PRE>
</DL>
<P>
The generated marshallers have the arguments encoded in their function name. For this particular list, they are
<P>
<DL COMPACT><DT id="55"><DD>
<PRE>
g_cclosure_user_marshal_VOID__VOID(...),
g_cclosure_user_marshal_VOID__INT(...),
g_cclosure_user_marshal_FLOAT__BOOLEAN_UCHAR(...).
</PRE>
</DL>
<P>
They can be used directly for GClosures or be passed in as the GSignalCMarshaller c_marshaller; argument upon creation of signals:
<P>
<DL COMPACT><DT id="56"><DD>
<PRE>
GClosure *cc_foo, *cc_bar, *cc_baz;
cc_foo = g_cclosure_new (NULL, foo, NULL);
g_closure_set_marshal (cc_foo, g_cclosure_user_marshal_VOID__VOID);
cc_bar = g_cclosure_new (NULL, bar, NULL);
g_closure_set_marshal (cc_bar, g_cclosure_user_marshal_VOID__INT);
cc_baz = g_cclosure_new (NULL, baz, NULL);
g_closure_set_marshal (cc_baz, g_cclosure_user_marshal_FLOAT__BOOLEAN_UCHAR);
</PRE>
</DL>
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<P>
<B><A HREF="/cgi-bin/man/man2html?1+glib-mkenums">glib-mkenums</A></B>(1)
<A NAME="lbAL">&nbsp;</A>
<H2>NOTES</H2>
<DL COMPACT>
<DT id="57"> 1.<DD>
corresponding Meson FAQ entry
<DL COMPACT><DT id="58"><DD>
<A HREF="https://mesonbuild.com/FAQ.html#how-do-i-tell-meson-that-my-sources-use-generated-headers">https://mesonbuild.com/FAQ.html#how-do-i-tell-meson-that-my-sources-use-generated-headers</A>
</DL>
<DT id="59"> 2.<DD>
Meson
documentation for gnome.genmarshal()
<DL COMPACT><DT id="60"><DD>
<A HREF="https://mesonbuild.com/Gnome-module.html#gnomegenmarshal">https://mesonbuild.com/Gnome-module.html#gnomegenmarshal</A>
</DL>
<P>
</DL>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="61"><A HREF="#lbAB">NAME</A><DD>
<DT id="62"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="63"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DL>
<DT id="64"><A HREF="#lbAE">Marshaller list format</A><DD>
<DT id="65"><A HREF="#lbAF">Parameter types</A><DD>
</DL>
<DT id="66"><A HREF="#lbAG">OPTIONS</A><DD>
<DT id="67"><A HREF="#lbAH">USING GLIB-GENMARSHAL WITH MESON</A><DD>
<DT id="68"><A HREF="#lbAI">USING GLIB-GENMARSHAL WITH AUTOTOOLS</A><DD>
<DT id="69"><A HREF="#lbAJ">EXAMPLE</A><DD>
<DT id="70"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="71"><A HREF="#lbAL">NOTES</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:15 GMT, March 31, 2021
</BODY>
</HTML>