GLIB-GENMARSHAL(1)
π glib-genmarshal β the manual page, but make it cute π
okay bestie, welcome to the glib-genmarshal page from the GLib manual set. it's a lil command-line tool and honestly? it's giving backstage crew at the function factory. let's get into it π
β¨ NAME β¨
glib-genmarshal β the C code marshaller generation utility for GLib closures, and yes she does exactly what it says on the tin π
πΈ SYNOPSIS πΈ
glib-genmarshal [OPTIONβ¦] [FILEβ¦]
π¦ DESCRIPTION π¦
so glib-genmarshal is this small utility that generates C code marshallers for callback functions of the GClosure mechanism in the GObject sublibrary of GLib. lowkey iconic of her.
here's the vibe: the marshaller functions have a standard signature. they get handed the invoking closure, an array of value structures holding the callback function parameters, and a value structure for the return value of the callback. then the marshaller is responsible for calling the respective C code function of the closure with all the parameters on the stack, and collecting its return value. she's basically the middleman who knows everyone's names π«Ά
glib-genmarshal takes a list of marshallers to generate as input. that 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. periodt.
π MARSHALLER LIST FORMAT π
the marshaller lists get processed line by line. a line can be a comment in the form of:
# this is a comment
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 PTYPE instances to the right of the colon specify the callback's parameter list β except for the first and the last arguments, which are always pointers. no cap.
π PARAMETER TYPES π
currently, the following types are supported (she has range):
VOIDβ indicates no return type, or no extra parameters. ifVOIDis used as the parameter list, no additional parameters may be present. it's the "nothing to see here" of types πBOOLEANβ for boolean types (gboolean).CHARβ for signed char types (gchar).UCHARβ for unsigned char types (guchar).INTβ for signed integer types (gint).UINTβ for unsigned integer types (guint).LONGβ for signed long integer types (glong).ULONGβ for unsigned long integer types (gulong).INT64β for signed 64-bit integer types (gint64).UINT64β for unsigned 64-bit integer types (guint64).ENUMβ for enumeration types (gint).FLAGSβ for flag enumeration types (guint).FLOATβ for single-precision float types (gfloat).DOUBLEβ for double-precision float types (gdouble).STRINGβ for string types (gchar*).BOXEDβ for boxed (anonymous but reference counted) types (GBoxed*).PARAMβ forGParamSpecor derived types (GParamSpec*).POINTERβ for anonymous pointer types (gpointer).OBJECTβ forGObjector derived types (GObject*).VARIANTβ forGVarianttypes (GVariant*).NONEβ deprecated alias forVOID. she's retired bestie, don't call her π΅BOOLβ deprecated alias forBOOLEAN. same energy, also retired π
π OPTIONS π
--headerβ generate header file contents of the marshallers. this option is mutually exclusive with the--bodyoption β pick a lane, babe.--bodyβ generate C code file contents of the marshallers. this option is mutually exclusive with the--headeroption.--prefix <PREFIX>β specify the marshaller prefix. the default prefix isg_cclosure_user_marshal.--skip-sourceβ skip source location remarks in generated comments. no receipts, no locations π--stdincβ use the standard marshallers of the GObject library, and includeglib-object.hin generated header files. mutually exclusive with the--nostdincoption.--nostdincβ do not use the standard marshallers of the GObject library, and skip theglib-object.hinclude directive in generated header files. mutually exclusive with the--stdincoption.--internalβ mark generated functions as internal, usingG_GNUC_INTERNAL. keeping it lowkey β¨-valist-marshallersβ generate valist marshallers, for use withg_signal_set_va_marshaller(). (yes, one dash. that's how she's written. copy it exactly fr fr)-v,--versionβ print version information and exit.--g-fatal-warningsβ make warnings fatal. that is, exit immediately once a warning occurs. it's giving "one strike and you're out" π€-h,--helpβ print brief help and exit.--output <FILE>β write output to FILE instead of the standard output.--prototypesβ 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--bodyoption.--pragma-onceβ 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--headeroption.--include-header <HEADER>β adds a#includedirective for the given file in the C source file. this option is only useful when using the--bodyoption.-D <SYMBOL>[=<VALUE>]β adds a#defineC pre-processor directive for SYMBOL and its given VALUE, or"1"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-Uoption. this option is only useful when using the--bodyoption.-U <SYMBOL>β adds a#undefC pre-processor directive to undefine the given SYMBOL. 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-Doption. this option is only useful when using the--bodyoption.--quietβ minimizes the output ofglib-genmarshal, by printing only warnings and errors. mutually exclusive with the--verboseoption.--verboseβ increases the verbosity ofglib-genmarshal, by printing debugging information. mutually exclusive with the--quietoption.
π§ USING GLIB-GENMARSHAL WITH MESON π§
Meson supports generating closure marshallers using glib-genmarshal out of the box in its gnome module. no extra setup, she's built different π
in your meson.build file you will typically call the gnome.genmarshal() method with the source list of marshallers to generate:
gnome = import('gnome')
marshal_files = gnome.genmarshal('marshal',
sources: 'marshal.list',
internal: true,
)
the marshal_files variable will contain an array of two elements, in the following order:
- a build target for the source file
- a build target for the header file
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:
mainlib = library('project',
sources: project_sources + marshal_files,
β¦
)
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:
mainlib_dep = declare_dependency(sources: marshal_files[1], link_with: mainlib)
β οΈ 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. bestie do not do it, i'm begging π
to know more about why all this is required, please refer to the corresponding Meson FAQ entry <https://mesonbuild.com/FAQ.html#how-do-i-tell-meson-that-my-sources-use-generated-headers>.
for more information on how to use the method, see the Meson documentation <https://mesonbuild.com/Gnome-module.html#gnomegenmarshal> for gnome.genmarshal().
π 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. it's a lil chain reaction and honestly? obsessed π«Ά
β 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 π
glib-mkenums(1)<man:glib-mkenums(1)> β her sister, also slaying β¨
and that's the whole page bestie!! ππβ¨ this was the glib-genmarshal manual page β footer energy: glib-genmarshal(), that's the name stamped at the bottom of the original page, dated/versioned right along with the rest of the GLib docs. go generate some marshallers, you've got this π«Άπ
π
π¦ where this page comes from
- arch rolling: glib2-devel 2.90.1-1 Β· LGPL-2.1-or-later
- ubuntu stonking: libgio-2.0-dev-bin 2.90.0-1 Β· LGPL-2.1-or-later
- π the page's license: LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms