table of contents
GLIB-GENMARSHAL(1) | User Commands | GLIB-GENMARSHAL(1) |
NAME¶
glib-genmarshal - C code marshaller generation utility for GLib closures
SYNOPSIS¶
glib-genmarshal [OPTION...] [FILE...]
DESCRIPTION¶
glib-genmarshal 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.
glib-genmarshal 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.
Marshaller list format¶
The marshaller lists are processed line by line, a line can contain a comment in the form of
or a marshaller specification of the form
RTYPE:PTYPE RTYPE:PTYPE,PTYPE RTYPE:PTYPE,PTYPE,PTYPE
The RTYPE part specifies the callback's return type and the PTYPEs right to the colon specify the callback's parameter list, except for the first and the last arguments which are always pointers.
Parameter types¶
Currently, the following types are supported:
VOID
BOOLEAN
CHAR
UCHAR
INT
UINT
LONG
ULONG
INT64
UINT64
ENUM
FLAGS
FLOAT
DOUBLE
STRING
BOXED
PARAM
POINTER
OBJECT
VARIANT
NONE
BOOL
OPTIONS¶
--header
--body
--prefix=PREFIX
--skip-source
--stdinc
--nostdinc
--internal
--valist-marshallers
-v, --version
--g-fatal-warnings
-h, --help
-v, --version
--output=FILE
--prototypes
--pragma-once
--include-header=HEADER
-D SYMBOL[=VALUE]
-U SYMBOL
--quiet
--verbose
USING GLIB-GENMARSHAL WITH AUTOTOOLS¶
In order to use glib-genmarshal 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 pkg-config, similarly as to how you discover the compiler and linker flags for GLib.
PKG_PROG_PKG_CONFIG([0.28]) PKG_CHECK_VAR([GLIB_GENMARSHAL], [glib-2.0], [glib_genmarshal])
In your Makefile.am file you will typically need very simple rules to generate the C files needed for the build.
marshal.h: marshal.list
$(AM_V_GEN)$(GLIB_GENMARSHAL) \
--header \
--output=$@ \
$< marshal.c: marshal.list marshal.h
$(AM_V_GEN)$(GLIB_GENMARSHAL) \
--include-header=marshal.h \
--body \
--output=$@ \
$< BUILT_SOURCES += marshal.h marshal.c CLEANFILES += marshal.h marshal.c EXTRA_DIST += marshal.list
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.
EXAMPLE¶
To generate marshallers for the following callback functions:
void foo (gpointer data1,
gpointer data2); void bar (gpointer data1,
gint param1,
gpointer data2); gfloat baz (gpointer data1,
gboolean param1,
guchar param2,
gpointer data2);
The marshaller.list file has to look like this:
VOID:VOID VOID:INT FLOAT:BOOLEAN,UCHAR
and you call glib-genmarshal like this:
glib-genmarshal --header marshaller.list > marshaller.h glib-genmarshal --body marshaller.list > marshaller.c
The generated marshallers have the arguments encoded in their function name. For this particular list, they are
g_cclosure_user_marshal_VOID__VOID(...), g_cclosure_user_marshal_VOID__INT(...), g_cclosure_user_marshal_FLOAT__BOOLEAN_UCHAR(...).
They can be used directly for GClosures or be passed in as the GSignalCMarshaller c_marshaller; argument upon creation of signals:
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);
SEE ALSO¶
GObject |