The C ones, at least.
*
* Each action is constructed as per one #GActionEntry.
*
- * |[
+ * |[<!-- language="C" -->
* static void
* activate_quit (GSimpleAction *simple,
* GVariant *parameter,
*
* A typical implementation might look something like this:
*
- * |[
+ * |[<!-- language="C" -->
* enum {
* NOT_INITIALIZED,
* INITIALIZING,
* however, the "_finish()" function may be called at most once.
*
* Example of a typical asynchronous operation flow:
- * |[
+ * |[<!-- language="C" -->
* void _theoretical_frobnitz_async (Theoretical *t,
* GCancellable *c,
* GAsyncReadyCallback cb,
* like this.
*
* An example of how to us this:
- * |[
+ * |[<!-- language="C" -->
* /* Make sure we don't do unnecessary work if already cancelled */
* if (g_cancellable_set_error_if_cancelled (cancellable, error))
* return;
*
* If the @parameters #GVariant is floating, it is consumed. This allows
* convenient 'inline' use of g_variant_new(), e.g.:
- * |[
+ * |[<!-- language="C" -->
* g_dbus_connection_call (connection,
* "org.freedesktop.StringThings",
* "/org/freedesktop/StringThings",
*
* If the @parameters #GVariant is floating, it is consumed.
* This allows convenient 'inline' use of g_variant_new(), e.g.:
- * |[
+ * |[<!-- language="C" -->
* g_dbus_connection_call_sync (connection,
* "org.freedesktop.StringThings",
* "/org/freedesktop/StringThings",
* automatically map from D-Bus errors to #GError and back. This
* is typically done in the function returning the #GQuark for the
* error domain:
- * |[
+ * |[<!-- language="C" -->
* /* foo-bar-error.h: */
*
* #define FOO_BAR_ERROR (foo_bar_error_quark ())
*
* If the @value #GVariant is floating, it is consumed. This allows
* convenient 'inline' use of g_variant_new(), e.g.
- * |[
+ * |[<!-- language="C" -->
* g_dbus_proxy_set_cached_property (proxy,
* "SomeProperty",
* g_variant_new ("(si)",
*
* If the @parameters #GVariant is floating, it is consumed. This allows
* convenient 'inline' use of g_variant_new(), e.g.:
- * |[
+ * |[<!-- language="C" -->
* g_dbus_proxy_call (proxy,
* "TwoStrings",
* g_variant_new ("(ss)",
*
* If the @parameters #GVariant is floating, it is consumed. This allows
* convenient 'inline' use of g_variant_new(), e.g.:
- * |[
+ * |[<!-- language="C" -->
* g_dbus_proxy_call_sync (proxy,
* "TwoStrings",
* g_variant_new ("(ss)",
* inside loops with g_file_enumerator_next_file().
*
* This is a convenience method that's equivalent to:
- * |[
+ * |[<!-- language="C" -->
* gchar *name = g_file_info_get_name (info);
* GFile *child = g_file_get_child (g_file_enumerator_get_container (enumr),
* name);
* of an extension point has a name, and a priority. Use
* g_io_extension_point_implement() to implement an extension point.
*
- * |[
+ * |[<!-- language="C" -->
* GIOExtensionPoint *ep;
*
* /* Register an extension point */
* g_io_extension_point_set_required_type (ep, MY_TYPE_EXAMPLE);
* ]|
*
- * |[
+ * |[<!-- language="C" -->
* /* Implement an extension point */
* G_DEFINE_TYPE (MyExampleImpl, my_example_impl, MY_TYPE_EXAMPLE);
* g_io_extension_point_implement ("my-extension-point",
* @size as 0 (allowing #GMemoryOutputStream to do the initial
* allocation for itself).
*
- * |[
+ * |[<!-- language="C" -->
* /* a stream that can grow */
* stream = g_memory_output_stream_new (NULL, 0, realloc, free);
*
*
* Consider the following example:
*
- * |[
+ * |[<!-- language="C" -->
* typedef struct
* {
* ...
* ships a gschemas.compiled file as part of itself, and then simply do
* the following:
*
- * |[
+ * |[<!-- language="C" -->
* {
* GSettings *settings;
* gint some_value;
* call g_simple_action_set_state() from the handler.
*
* An example of a 'change-state' handler:
- * |[
+ * |[<!-- language="C" -->
* static void
* change_volume_state (GSimpleAction *action,
* GVariant *value,
* #GAsyncResult. A typical implementation of an asynchronous operation
* using GSimpleAsyncResult looks something like this:
*
- * |[
+ * |[<!-- language="C" -->
* static void
* baked_cb (Cake *cake,
* gpointer user_data)
* to try out each socket address in turn until one succeeds, as shown
* in the sample code below.
*
- * |[
+ * |[<!-- language="C" -->
* MyConnectionType *
* connect_to_host (const char *hostname,
* guint16 port,
* the return value.
*
* Here is an example for using GTask as a GAsyncResult:
- * |[
+ * |[<!-- language="C" -->
* typedef struct {
* CakeFrostingType frosting;
* char *message;
* and priority).
*
* Here is an example for chained asynchronous operations:
- * |[
+ * |[<!-- language="C" -->
* typedef struct {
* Cake *cake;
* CakeFrostingType frosting;
* #GMainContext when it completes.
*
* Running a task in a thread:
- * |[
+ * |[<!-- language="C" -->
* typedef struct {
* guint radius;
* CakeFlavor flavor;
* synchronous variants of blocking APIs.
*
* Cancelling a task:
- * |[
+ * |[<!-- language="C" -->
* static void
* bake_cake_thread (GTask *task,
* gpointer source_object,
*
* For example, if the icon name was "gnome-dev-cdrom-audio", the array
* would become
- * |[
+ * |[<!-- language="C" -->
* {
* "gnome-dev-cdrom-audio",
* "gnome-dev-cdrom",
* that can be created by shortening @iconname at '-' characters.
*
* In the following example, @icon1 and @icon2 are equivalent:
- * |[
+ * |[<!-- language="C" -->
* const char *names[] = {
* "gnome-dev-cdrom-audio",
* "gnome-dev-cdrom",
* either be equal or a prefix of what this function returns. In
* other words, in code
*
- * |[
+ * |[<!-- language="C" -->
* GMount *mount;
* GFile *mount_root
* GFile *volume_activation_root;
* volume_activation_root = g_volume_get_activation_root (volume); /* assume not NULL */
* ]|
* then the expression
- * |[
+ * |[<!-- language="C" -->
* (g_file_has_prefix (volume_activation_root, mount_root) ||
g_file_equal (volume_activation_root, mount_root))
* ]|
* and conversion specifier and append a conversion specifier.
*
* The following example prints "0x7b";
- * |[
+ * |[<!-- language="C" -->
* gint16 value = 123;
* g_print ("%#" G_GINT16_MODIFIER "x", value);
* ]|
* include the percent-sign, such that you can add precision and length
* modifiers between percent-sign and conversion specifier.
*
- * |[
+ * |[<!-- language="C" -->
* gint16 in;
* gint32 out;
* sscanf ("42", "%" G_GINT16_FORMAT, &in)
* data" to a callback, in the form of a void pointer. From time to time
* you want to pass an integer instead of a pointer. You could allocate
* an integer, with something like:
- * |[
+ * |[<!-- language="C" -->
* int *ip = g_new (int, 1);
* *ip = 42;
* ]|
* Pointers are always at least 32 bits in size (on all platforms GLib
* intends to support). Thus you can store at least 32-bit integer values
* in a pointer value. Naively, you might try this, but it's incorrect:
- * |[
+ * |[<!-- language="C" -->
* gpointer p;
* int i;
* p = (void*) 42;
* ]|
* Again, that example was not correct, don't copy it.
* The problem is that on some systems you need to do this:
- * |[
+ * |[<!-- language="C" -->
* gpointer p;
* int i;
* p = (void*) (long) 42;
* Accepts a macro or a string and converts it into a string after
* preprocessor argument expansion. For example, the following code:
*
- * |[
+ * |[<!-- language="C" -->
* #define AGE 27
* const gchar *greeting = G_STRINGIFY (AGE) " today!";
* ]|
*
* is transformed by the preprocessor into (code equivalent to):
*
- * |[
+ * |[<!-- language="C" -->
* const gchar *greeting = "27 today!";
* ]|
*/
* @identifier1identifier2 from its expanded
* arguments @identifier1 and @identifier2. For example,
* the following code:
- * |[
+ * |[<!-- language="C" -->
* #define GET(traveller,method) G_PASTE(traveller_get_, method) (traveller)
* const gchar *name = GET (traveller, name);
* const gchar *quest = GET (traveller, quest);
* ]|
*
* is transformed by the preprocessor into:
- * |[
+ * |[<!-- language="C" -->
* const gchar *name = traveller_get_name (traveller);
* const gchar *quest = traveller_get_quest (traveller);
* GdkColor *favourite = traveller_get_favourite_colour (traveller);
* Its value should be ignored. This can be accomplished by placing
* it as the first argument of a comma expression.
*
- * |[
+ * |[<!-- language="C" -->
* #define ADD_ONE_TO_INT(x) \
* (G_STATIC_ASSERT_EXPR(sizeof (x) == sizeof (int)), ((x) + 1))
* ]|
* semicolon. For arguments, place the attribute at the beginning of the
* argument declaration.
*
- * |[
+ * |[<!-- language="C" -->
* void my_unused_function (G_GNUC_UNUSED gint unused_argument,
* gint other_argument) G_GNUC_UNUSED;
* ]|
*
* See the GNU C documentation for more details.
*
- * |[
+ * |[<!-- language="C" -->
* gint g_snprintf (gchar *string,
* gulong n,
* gchar const *format,
*
* See the GNU C documentation for more details.
*
- * |[
+ * |[<!-- language="C" -->
* gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);
* ]|
*/
* function declaration. While GCC allows the macro after the declaration,
* Sun Studio does not.
*
- * |[
+ * |[<!-- language="C" -->
* G_GNUC_INTERNAL
* void _g_log_fallback_handler (const gchar *log_domain,
* GLogLevelFlags log_level,
* Hints the compiler that the expression is likely to evaluate to
* a true value. The compiler may use this information for optimizations.
*
- * |[
+ * |[<!-- language="C" -->
* if (G_LIKELY (random () != 1))
* g_print ("not one");
* ]|
* Hints the compiler that the expression is unlikely to evaluate to
* a true value. The compiler may use this information for optimizations.
*
- * |[
+ * |[<!-- language="C" -->
* if (G_UNLIKELY (random () == 1))
* g_print ("a random one");
* ]|
* To free an array, use g_array_free().
*
* Here is an example that stores integers in a #GArray:
- * |[
+ * |[<!-- language="C" -->
* GArray *garray;
* gint i;
* /* We create a new array to store gint values.
* value is cast to the given type.
*
* This example gets a pointer to an element in a #GArray:
- * |[
+ * |[<!-- language="C" -->
* EDayViewEvent *event;
* /* This gets a pointer to the 4th element
* * in the array of EDayViewEvent structs.
* To free a pointer array, use g_ptr_array_free().
*
* An example using a #GPtrArray:
- * |[
+ * |[<!-- language="C" -->
* GPtrArray *gparray;
* gchar *string1 = "one", *string2 = "two", *string3 = "three";
*
* To free a #GByteArray, use g_byte_array_free().
*
* An example for using a #GByteArray:
- * |[
+ * |[<!-- language="C" -->
* GByteArray *gbarray;
* gint i;
*
*
* If you were sorting a list of priority numbers to make sure the
* lowest priority would be at the top of the queue, you could use:
- * |[
+ * |[<!-- language="C" -->
* gint32 id1;
* gint32 id2;
*
* The following example shows how it can be used together with
* the g_log() functions.
*
- * |[
+ * |[<!-- language="C" -->
* #include <glib.h>
*
* static void
* function.
*
* Instead, do the following:
- * |[
+ * |[<!-- language="C" -->
* time_t ttime;
* GTime gtime;
*
* the user's current timezone.
*
* To set the value of a date to the current day, you could write:
- * |[
+ * |[<!-- language="C" -->
* g_date_set_time_t (date, time (NULL));
* ]|
*
*
* Functions that can fail take a return location for a #GError as their
* last argument. For example:
- * |[
+ * |[<!-- language="C" -->
* gboolean g_file_get_contents (const gchar *filename,
* gchar **contents,
* gsize *length,
* If you pass a non-%NULL value for the <literal>error</literal>
* argument, it should point to a location where an error can be placed.
* For example:
- * |[
+ * |[<!-- language="C" -->
* gchar *contents;
* GError *err = NULL;
*
* Because g_file_get_contents() returns %FALSE on failure, if you
* are only interested in whether it failed and don't need to display
* an error message, you can pass %NULL for the @error argument:
- * |[
+ * |[<!-- language="C" -->
* if (g_file_get_contents ("foo.txt", &contents, NULL, NULL)) /* ignore errors */
* /* no error occurred */ ;
* else
* want to g_set_error(), then return immediately. g_set_error()
* does nothing if the error location passed to it is %NULL.
* Here's an example:
- * |[
+ * |[<!-- language="C" -->
* gint
* foo_open_file (GError **error)
* {
* function that can report a #GError. If the sub-function indicates
* fatal errors in some way other than reporting a #GError, such as
* by returning %TRUE on success, you can simply do the following:
- * |[
+ * |[<!-- language="C" -->
* gboolean
* my_function_that_can_fail (GError **err)
* {
* reporting a #GError, you need to create a temporary #GError
* since the passed-in one may be %NULL. g_propagate_error() is
* intended for use in this case.
- * |[
+ * |[<!-- language="C" -->
* gboolean
* my_function_that_can_fail (GError **err)
* {
* ]|
*
* Error pileups are always a bug. For example, this code is incorrect:
- * |[
+ * |[<!-- language="C" -->
* gboolean
* my_function_that_can_fail (GError **err)
* {
* of handling an error by always doing nothing about it. So the
* following code is fine, assuming errors in sub_function_that_can_fail()
* are not fatal to my_function_that_can_fail():
- * |[
+ * |[<!-- language="C" -->
* gboolean
* my_function_that_can_fail (GError **err)
* {
*
* - The error domain is called <NAMESPACE>_<MODULE>_ERROR,
* for example %G_SPAWN_ERROR or %G_THREAD_ERROR:
- * |[
+ * |[<!-- language="C" -->
* #define G_SPAWN_ERROR g_spawn_error_quark ()
*
* GQuark
* For example, you might think you could use %G_FILE_TEST_IS_SYMLINK
* to know whether it is safe to write to a file without being
* tricked into writing into a different location. It doesn't work!
- * |[
+ * |[<!-- language="C" -->
* /* DON'T DO THIS */
* if (!g_file_test (filename, G_FILE_TEST_IS_SYMLINK))
* {
* <filename>glib/gi18n.h</filename>. For use in a library, you must include
* <filename>glib/gi18n-lib.h</filename> after defining the %GETTEXT_PACKAGE
* macro suitably for your library:
- * |[
+ * |[<!-- language="C" -->
* #define GETTEXT_PACKAGE "gtk20"
* #include <glib/gi18n-lib.h>
* ]|
* used as a context. This is mainly useful for short strings which
* may need different translations, depending on the context in which
* they are used.
- * |[
+ * |[<!-- language="C" -->
* label1 = C_("Navigation", "Back");
* label2 = C_("Body part", "Back");
* ]|
* where the translated strings can't be directly used, e.g. in string
* array initializers. To get the translated string, call gettext()
* at runtime.
- * |[
+ * |[<!-- language="C" -->
* {
* static const char *messages[] = {
* N_("some very meaningful message"),
* be directly used, e.g. in string array initializers. To get the
* translated string, you should call g_dpgettext2() at runtime.
*
- * |[
+ * |[<!-- language="C" -->
* {
* static const char *messages[] = {
* NC_("some context", "some very meaningful message"),
* Initializes a key/value pair iterator and associates it with
* @hash_table. Modifying the hash table after calling this function
* invalidates the returned iterator.
- * |[
+ * |[<!-- language="C" -->
* GHashTableIter iter;
* gpointer key, value;
*
* g_list_insert() and g_list_insert_sorted().
*
* To visit all elements in the list, use a loop over the list:
- * |[
+ * |[<!-- language="C" -->
* GList *l;
* for (l = list; l != NULL; l = l->next)
* {
*
* To loop over the list and modify it (e.g. remove a certain element)
* a while loop is more appropriate, for example:
- * |[
+ * |[<!-- language="C" -->
* GList *l = list;
* while (l != NULL)
* {
* to avoid the inefficiency is to use g_list_prepend() and reverse
* the list with g_list_reverse() when all elements have been added.
*
- * |[
+ * |[<!-- language="C" -->
* /* Notice that these are initialized to the empty list. */
* GList *string_list = NULL, *number_list = NULL;
*
* Note that the return value is the new start of the list,
* which will have changed, so make sure you store the new value.
*
- * |[
+ * |[<!-- language="C" -->
* /* Notice that it is initialized to the empty list. */
* GList *list = NULL;
*
*
* This function is for example used to move an element in the list.
* The following example moves an element to the top of the list:
- * |[
+ * |[<!-- language="C" -->
* list = g_list_remove_link (list, llink);
* list = g_list_concat (llink, list);
* ]|
* This function is for example used to move an element in the list
* (see the example for g_list_concat()) or to remove an element in
* the list before freeing its data:
- * |[
+ * |[<!-- language="C" -->
* list = g_list_remove_link (list, llink);
* free_some_data_that_may_access_the_list_again (llink->data);
* g_list_free (llink);
* if the copy function takes only one argument.
*
* For instance, if @list holds a list of GObjects, you can do:
- * |[
+ * |[<!-- language="C" -->
* another_list = g_list_copy_deep (list, (GCopyFunc) g_object_ref, NULL);
* ]|
*
* And, to entirely free the new list, you could do:
- * |[
+ * |[<!-- language="C" -->
* g_list_free_full (another_list, g_object_unref);
* ]|
*
* This function is useful in a situation like the following:
* Imagine an extremely simple "garbage collected" system.
*
- * |[
+ * |[<!-- language="C" -->
* static GList *free_list;
*
* gpointer
* doesn't work, since the idle function could be called from a
* recursive callback. This can be fixed by using g_main_depth()
*
- * |[
+ * |[<!-- language="C" -->
* gpointer
* allocate_memory (gsize size)
* {
* from within idle handlers, but may have freed the object
* before the dispatch of your idle handler.
*
- * |[
+ * |[<!-- language="C" -->
* static gboolean
* idle_callback (gpointer data)
* {
* this particular problem, is to check to if the source
* has already been destroy within the callback.
*
- * |[
+ * |[<!-- language="C" -->
* static gboolean
* idle_callback (gpointer data)
* {
* Another related use for this function is when implementing a main
* loop with a termination condition, computed from multiple threads:
*
- * |[
+ * |[<!-- language="C" -->
* #define NUM_TASKS 10
* static volatile gint tasks_remaining = NUM_TASKS;
* ...
* ]|
*
* Then in a thread:
- * |[
+ * |[<!-- language="C" -->
* perform_work();
*
* if (g_atomic_int_dec_and_test (&tasks_remaining))
* As an example, see the following implementation of a simple
* parser that counts the number of tags encountered.
*
- * |[
+ * |[<!-- language="C" -->
* typedef struct
* {
* gint tag_count;
* In order to allow this parser to be easily used as a subparser, the
* following interface is provided:
*
- * |[
+ * |[<!-- language="C" -->
* void
* start_counting (GMarkupParseContext *context)
* {
*
* The subparser would then be used as follows:
*
- * |[
+ * |[<!-- language="C" -->
* static void start_element (context, element_name, ...)
* {
* if (strcmp (element_name, "count-these") == 0)
* output, without having to worry that the strings
* might themselves contain markup.
*
- * |[
+ * |[<!-- language="C" -->
* const char *store = "Fortnum & Mason";
* const char *item = "Tea";
* char *output;
*
* Here is an example for adding a log handler for all warning messages
* in the default domain:
- * |[
+ * |[<!-- language="C" -->
* g_log_set_handler (NULL, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL
* | G_LOG_FLAG_RECURSION, my_log_handler, NULL);
* ]|
*
* This example adds a log handler for all critical messages from GTK+:
- * |[
+ * |[<!-- language="C" -->
* g_log_set_handler ("Gtk", G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL
* | G_LOG_FLAG_RECURSION, my_log_handler, NULL);
* ]|
*
* This example adds a log handler for all messages from GLib:
- * |[
+ * |[<!-- language="C" -->
* g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
* | G_LOG_FLAG_RECURSION, my_log_handler, NULL);
* ]|
*
* For example:
*
- * |[
+ * |[<!-- language="C" -->
* /* g_main_context_push_thread_default() should fail if the
* * context is already owned by another thread.
* */
*
* Here is a complete example of setting up GOption to parse the example
* commandline above and produce the example help output.
- * |[
+ * |[<!-- language="C" -->
* static gint repeats = 2;
* static gint max_size = 8;
* static gboolean verbose = FALSE;
* The following example shows how you can use #GOptionContext directly
* in order to correctly deal with Unicode filenames on Windows:
*
- * |[
+ * |[<!-- language="C" -->
* int
* main (int argc, char **argv)
* {
* To retrieve all the non-overlapping matches of the pattern in
* string you can use g_match_info_next().
*
- * |[
+ * |[<!-- language="C" -->
* static void
* print_uppercase_words (const gchar *string)
* {
* To retrieve all the non-overlapping matches of the pattern in
* string you can use g_match_info_next().
*
- * |[
+ * |[<!-- language="C" -->
* static void
* print_uppercase_words (const gchar *string)
* {
*
* The following example uses g_regex_replace_eval() to replace multiple
* strings at once:
- * |[
+ * |[<!-- language="C" -->
* static gboolean
* eval_cb (const GMatchInfo *info,
* GString *res,
* object size used at allocation time is still available when freeing.
*
* Here is an example for using the slice allocator:
- * |[
+ * |[<!-- language="C" -->
* gchar *mem[10000];
* gint i;
*
*
* And here is an example for using the using the slice allocator
* with data structures:
- * |[
+ * |[<!-- language="C" -->
* GRealArray *array;
*
* /* Allocate one block, using the g_slice_new() macro. */
* elements. A common idiom to avoid the inefficiency is to prepend
* the elements and reverse the list when all elements have been added.
*
- * |[
+ * |[<!-- language="C" -->
* /* Notice that these are initialized to the empty list. */
* GSList *list = NULL, *number_list = NULL;
*
* The return value is the new start of the list, which
* may have changed, so make sure you store the new value.
*
- * |[
+ * |[<!-- language="C" -->
* /* Notice that it is initialized to the empty list. */
* GSList *list = NULL;
* list = g_slist_prepend (list, "last");
* one argument.
*
* For instance, if @list holds a list of GObjects, you can do:
- * |[
+ * |[<!-- language="C" -->
* another_list = g_slist_copy_deep (list, (GCopyFunc) g_object_ref, NULL);
* ]|
*
* And, to entirely free the new list, you could do:
- * |[
+ * |[<!-- language="C" -->
* g_slist_free_full (another_list, g_object_unref);
* ]|
*
* on systems with 64bit IEEE-compatible doubles.
*
* The typical usage would be something like:
- * |[
+ * |[<!-- language="C" -->
* char buf[G_ASCII_DTOSTR_BUF_SIZE];
*
* fprintf (out, "value=%s\n", g_ascii_dtostr (buf, sizeof (buf), value));
* changed to the @new_delimiter character. Modifies @string in place,
* and returns @string itself, not a copy. The return value is to
* allow nesting such as
- * |[
+ * |[<!-- language="C" -->
* g_ascii_strup (g_strdelimit (str, "abc", '?'))
* ]|
*
* replaces the character with @substitutor. Modifies @string in place,
* and return @string itself, not a copy. The return value is to allow
* nesting such as
- * |[
+ * |[<!-- language="C" -->
* g_ascii_strup (g_strcanon (str, "abc", '?'))
* ]|
*
*
* The API is designed to handle creation and registration of test suites
* and test cases implicitly. A simple call like
- * |[
+ * |[<!-- language="C" -->
* g_test_add_func ("/misc/assertions", test_assertions);
* ]|
* creates a test suite called "misc" with a single test case named
* The advantage of this macro is that it can produce a message that
* includes the actual values of @s1 and @s2.
*
- * |[
+ * |[<!-- language="C" -->
* g_assert_cmpstr (mystring, ==, "fubar");
* ]|
*
* The forking parent process then asserts successful child program
* termination and validates child program outputs.
*
- * |[
+ * |[<!-- language="C" -->
* static void
* test_fork_patterns (void)
* {
* <literal>my_object_new(1000000)</literal> will abort with an error
* message.
*
- * |[
+ * |[<!-- language="C" -->
* static void
* test_create_large_object_subprocess (void)
* {
* It is not necessary to initialize a mutex that has been
* statically allocated.
*
- * |[
+ * |[<!-- language="C" -->
* typedef struct {
* GMutex m;
* ...
* It is not necessary to initialise a recursive mutex that has been
* statically allocated.
*
- * |[
+ * |[<!-- language="C" -->
* typedef struct {
* GRecMutex m;
* ...
* necessary to initialise a reader-writer lock that has been statically
* allocated.
*
- * |[
+ * |[<!-- language="C" -->
* typedef struct {
* GRWLock l;
* ...
* condition variable (extending the example presented in the
* documentation for #GCond):
*
- * |[
+ * |[<!-- language="C" -->
* gpointer
* pop_data_timed (void)
* {
* be properly initialised by default (ie: to all zeros). See the
* examples below.
*
- * |[
+ * |[<!-- language="C" -->
* static GPrivate name_key = G_PRIVATE_INIT (g_free);
*
* /* return value should not be freed */
* give_me_next_number() example using the #G_LOCK macros:
*
* Here is an example for using the #G_LOCK convenience macros:
- * |[
+ * |[<!-- language="C" -->
* G_LOCK_DEFINE (current_number);
*
* int
* access.
*
* Take for example the following function:
- * |[
+ * |[<!-- language="C" -->
* int
* give_me_next_number (void)
* {
* It is easy to see that this won't work in a multi-threaded
* application. There current_number must be protected against shared
* access. A #GMutex can be used as a solution to this problem:
- * |[
+ * |[<!-- language="C" -->
* int
* give_me_next_number (void)
* {
* g_rw_lock_reader_lock()).
*
* Here is an example for an array with access functions:
- * |[
+ * |[<!-- language="C" -->
* GRWLock lock;
* GPtrArray *array;
*
*
* Here is an example for using GCond to block a thread until a condition
* is satisfied:
- * |[
+ * |[<!-- language="C" -->
* gpointer current_data = NULL;
* GMutex data_mutex;
* GCond data_cond;
*
* A #GOnce must be initialized with this macro before it can be used.
*
- * |[
+ * |[<!-- language="C" -->
* GOnce my_once = G_ONCE_INIT;
* ]|
*
* Calling g_once() recursively on the same #GOnce struct in
* @func will lead to a deadlock.
*
- * |[
+ * |[<!-- language="C" -->
* gpointer
* get_debug_flags (void)
* {
* blocked until initialization completed. To be used in constructs
* like this:
*
- * |[
+ * |[<!-- language="C" -->
* static gsize initialization_value = 0;
*
* if (g_once_init_enter (&initialization_value))
* g_variant_new() would have collected.
*
* Consider this simple example:
- * |[
+ * |[<!-- language="C" -->
* g_variant_new_parsed ("[('one', 1), ('two', %i), (%s, 3)]", 2, "three");
* ]|
*
* In the example, the variable argument parameters are collected and
* filled in as if they were part of the original string to produce the
* result of
- * |[
+ * |[<!-- language="C" -->
* [('one', 1), ('two', 2), ('three', 3)]
* ]|
*
*
* This function might be used as follows:
*
- * |[
+ * |[<!-- language="C" -->
* GVariant *
* make_pointless_dictionary (void)
* {
* you no longer need it.
*
* Here is an example for iterating with g_variant_iter_next_value():
- * |[
+ * |[<!-- language="C" -->
* /* recursively iterate a container */
* void
* iterate_container_recursive (GVariant *container)
*
* This function might be used as follows:
*
- * |[
+ * |[<!-- language="C" -->
* GVariant *
* make_pointless_dictionary (void)
* {
* the unpacking process.
*
* Here is an example for memory management with g_variant_iter_next():
- * |[
+ * |[<!-- language="C" -->
* /* Iterates a dictionary of type 'a{sv}' */
* void
* iterate_dictionary (GVariant *dictionary)
* g_variant_get(). Failure to do so will cause a memory leak.
*
* Here is an example for memory management with g_variant_iter_loop():
- * |[
+ * |[<!-- language="C" -->
* /* Iterates a dictionary of type 'a{sv}' */
* void
* iterate_dictionary (GVariant *dictionary)
* it must ensure that it is never unloaded, by calling g_module_make_resident().
*
* Example: Calling a function defined in a GModule
- * |[
+ * |[<!-- language="C" -->
* /* the function signature for 'say_hello' */
* typedef void (* SayHelloFunc) (const char *message);
*
* value is applied to the target property; for instance, the following
* binding:
*
- * |[
+ * |[<!-- language="C" -->
* g_object_bind_property (object1, "property-a",
* object2, "property-b",
* G_BINDING_DEFAULT);
* of two #GObject instances, so that if either property changes, the
* other is updated as well, for instance:
*
- * |[
+ * |[<!-- language="C" -->
* g_object_bind_property (object1, "property-a",
* object2, "property-b",
* G_BINDING_BIDIRECTIONAL);
* transformation from the source value to the target value before
* applying it; for instance, the following binding:
*
- * |[
+ * |[<!-- language="C" -->
* g_object_bind_property_full (adjustment1, "value",
* adjustment2, "value",
* G_BINDING_BIDIRECTIONAL,
* part as a #GClosure. This function is mainly useful when
* implementing new types of closures.
*
- * |[
+ * |[<!-- language="C" -->
* typedef struct _MyClosure MyClosure;
* struct _MyClosure
* {
* count. If the closure is not floating, g_closure_sink() does
* nothing. The reason for the existence of the floating state is to
* prevent cumbersome code sequences like:
- * |[
+ * |[<!-- language="C" -->
* closure = g_cclosure_new (cb_func, cb_data);
* g_source_set_closure (source, closure);
* g_closure_unref (closure); /* GObject doesn't really need this */
* ]|
* Because g_source_set_closure() (and similar functions) take ownership of the
* initial reference count, if it is unowned, we instead can write:
- * |[
+ * |[<!-- language="C" -->
* g_source_set_closure (source, g_cclosure_new (cb_func, cb_data));
* ]|
*
* Generally, this function is used together with g_closure_ref(). Ane example
* of storing a closure for later notification looks like:
- * |[
+ * |[<!-- language="C" -->
* static GClosure *notify_closure = NULL;
* void
* foo_notify_set_closure (GClosure *closure)
* function of a #GTypePlugin implementation, as in the following
* example:
*
- * |[
+ * |[<!-- language="C" -->
* static void
* my_enum_complete_type_info (GTypePlugin *plugin,
* GType g_type,
* This means that it is not specifically claimed to be "owned" by
* any code portion. The main motivation for providing floating references is
* C convenience. In particular, it allows code to be written as:
- * |[
+ * |[<!-- language="C" -->
* container = create_container ();
* container_add_child (container, create_child());
* ]|
* references, container_add_child() can only g_object_ref() the new child,
* so to implement this code without reference leaks, it would have to be
* written as:
- * |[
+ * |[<!-- language="C" -->
* Child *child;
* container = create_container ();
* child = create_child ();
* across certain code portions (an example is #GtkMenu), to achieve this,
* the following sequence can be used:
*
- * |[
+ * |[<!-- language="C" -->
* /* save floating state */
* gboolean was_floating = g_object_is_floating (object);
* g_object_ref_sink (object);
* This signal is typically used to obtain change notification for a
* single property, by specifying the property name as a detail in the
* g_signal_connect() call, like this:
- * |[
+ * |[<!-- language="C" -->
* g_signal_connect (text_view->buffer, "notify::paste-target-list",
* G_CALLBACK (gtk_text_view_target_list_notify),
* text_view)
* #GParamSpecs and g_object_notify_by_pspec(). For instance, this
* class initialization:
*
- * |[
+ * |[<!-- language="C" -->
* enum {
* PROP_0, PROP_FOO, PROP_BAR, N_PROPERTIES
* };
*
* allows calling g_object_notify_by_pspec() to notify of property changes:
*
- * |[
+ * |[<!-- language="C" -->
* void
* my_object_set_foo (MyObject *self, gint foo)
* {
* instead, is to store the GParamSpec used with
* g_object_class_install_property() inside a static array, e.g.:
*
- *|[
+ *|[<!-- language="C" -->
* enum
* {
* PROP_0,
*
* and then notify a change on the "foo" property with:
*
- * |[
+ * |[<!-- language="C" -->
* g_object_notify_by_pspec (self, properties[PROP_FOO]);
* ]|
*
*
* Here is an example of using g_object_get() to get the contents
* of three properties: an integer, a string and an object:
- * |[
+ * |[<!-- language="C" -->
* gint intval;
* gchar *strval;
* GObject *objval;
* - swapped_signal_after, swapped-signal-after: equivalent to g_signal_connect_data (..., NULL, G_CONNECT_SWAPPED | G_CONNECT_AFTER)
* - swapped_object_signal_after, swapped-object-signal-after: equivalent to g_signal_connect_object (..., G_CONNECT_SWAPPED | G_CONNECT_AFTER)
*
- * |[
+ * |[<!-- language="C" -->
* menu->toplevel = g_object_connect (g_object_new (GTK_TYPE_WINDOW,
* "type", GTK_WINDOW_POPUP,
* "child", menu,
* set).
* Usually, calling this function is only required to update
* user data pointers with a destroy notifier, for example:
- * |[
+ * |[<!-- language="C" -->
* void
* object_add_to_user_list (GObject *object,
* const gchar *new_string)
* Note the use of a structure member "priv" to avoid the overhead
* of repeatedly calling MY_OBJECT_GET_PRIVATE().
*
- * |[
+ * |[<!-- language="C" -->
* typedef struct _MyObject MyObject;
* typedef struct _MyObjectPrivate MyObjectPrivate;
*
* 1. The type is initially introduced (usually upon loading the module
* the first time, or by your main application that knows what modules
* introduces what types), like this:
- * |[
+ * |[<!-- language="C" -->
* new_type_id = g_type_register_dynamic (parent_type_id,
* "TypeName",
* new_type_plugin,
* The code in the example program below demonstrates #GValue's
* features.
*
- * |[
+ * |[<!-- language="C" -->
* #include <glib-object.h>
*
* static void
* g_value_unset() as the clear function using g_array_set_clear_func(),
* for instance, the following code:
*
- * |[
+ * |[<!-- language="C" -->
* GValueArray *array = g_value_array_new (10);
* ]|
*
* can be replaced by:
*
- * |[
+ * |[<!-- language="C" -->
* GArray *array = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 10);
* g_array_set_clear_func (array, (GDestroyNotify) g_value_unset);
* ]|