|glib-genmarshal [OPTION...] [FILE...]|
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 standard input or from files passed as additional arguments on the command line.
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
(up to 16 PTYPEs may be present).
The RTYPE part specifies the callbacks return type and the PTYPEs right to the colon specify the callbacks parameter list, except for the first and the last arguments which are always pointers.
Currently, the following types are supported:
VOIDindicates no return type, or no extra parameters. If VOID is used as the parameter list, no additional parameters may be present.
BOOLEANfor boolean types (gboolean)
CHARfor signed char types (gchar)
UCHARfor unsigned char types (guchar)
INTfor signed integer types (gint)
UINTfor unsigned integer types (guint)
LONGfor signed long integer types (glong)
ULONGfor unsigned long integer types (gulong)
INT64for signed 64bit integer types (gint64)
UINT64for unsigned 64bit integer types (guint64)
ENUMfor enumeration types (gint)
FLAGSfor flag enumeration types (guint)
FLOATfor single-precision float types (gfloat)
DOUBLEfor double-precision float types (gdouble)
STRINGfor string types (gchar*)
BOXEDfor boxed (anonymous but reference counted) types (GBoxed*)
PARAMfor GParamSpec or derived types (GParamSpec*)
POINTERfor anonymous pointer types (gpointer)
OBJECTfor GObject or derived types (GObject*)
VARIANTfor GVariant types (GVariant*)
NONEdeprecated alias for VOID
BOOLdeprecated alias for BOOLEAN
--headerGenerate header file contents of the marshallers.
--bodyGenerate C code file contents of the marshallers.
--prefix=PREFIXSpecify marshaller prefix. The default prefix is g_cclosure_marshal.
--skip-sourceSkip source location remarks in generated comments.
--stdincUse the standard marshallers of the GObject library, and include gmarshal.h in generated header files.
--nostdincDo not use the standard marshallers of the GObject library, and skip gmarshal.h include directive in generated header files.
--internalMark generated functions as internal, using G_GNUC_INTERNAL.
--valist-marshallersGenerate valist marshallers, for use with g_signal_set_va_marshaller().
-v, --versionPrint version information.
--g-fatal-warningsMake warnings fatal, that is, exit immediately once a warning occurs.
-h, --helpPrint brief help and exit.
-v, --versionPrint version and exit.
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);