1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright © 2011 Red Hat, Inc
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 * Authors: Alexander Larsson <alexl@redhat.com>
25 #include "gresource.h"
26 #include <gvdb/gvdb-reader.h>
28 #include <gio/gmemoryinputstream.h>
29 #include <gio/gzlibdecompressor.h>
30 #include <gio/gconverterinputstream.h>
39 static void register_lazy_static_resources (void);
41 G_DEFINE_BOXED_TYPE (GResource, g_resource, g_resource_ref, g_resource_unref)
45 * @short_description: Resource framework
48 * Applications and libraries often contain binary or textual data that is really part of the
49 * application, rather than user data. For instance #GtkBuilder .ui files, splashscreen images,
50 * GMenu markup xml, CSS files, icons, etc. These are often shipped as files in <filename>$datadir/appname</filename>, or
51 * manually included as literal strings in the code.
53 * The #GResource API and the <link linkend="glib-compile-resources">glib-compile-resources</link> program
54 * provide a convenient and efficient alternative to this which has some nice properties. You
55 * maintain the files as normal files, so its easy to edit them, but during the build the files
56 * are combined into a binary bundle that is linked into the executable. This means that loading
57 * the resource files are efficient (as they are already in memory, shared with other instances) and
58 * simple (no need to check for things like I/O errors or locate the files in the filesystem). It
59 * also makes it easier to create relocatable applications.
61 * Resource files can also be marked as compressed. Such files will be included in the resource bundle
62 * in a compressed form, but will be automatically uncompressed when the resource is used. This
63 * is very useful e.g. for larger text files that are parsed once (or rarely) and then thrown away.
65 * Resource files can also be marked to be preprocessed, by setting the value of the
66 * <literal>preprocess</literal> attribute to a comma-separated list of preprocessing options.
67 * The only options currently supported are:
69 * <literal>xml-stripblanks</literal> which will use the xmllint command
70 * to strip ignorable whitespace from the xml file. For this to work,
71 * the `XMLLINT` environment variable must be set to the full path to
72 * the xmllint executable, or xmllint must be in the `PATH`; otherwise
73 * the preprocessing step is skipped.
75 * <literal>to-pixdata</literal> which will use the gdk-pixbuf-pixdata command to convert
76 * images to the GdkPixdata format, which allows you to create pixbufs directly using the data inside
77 * the resource file, rather than an (uncompressed) copy if it. For this, the gdk-pixbuf-pixdata
78 * program must be in the PATH, or the `GDK_PIXBUF_PIXDATA` environment variable must be
79 * set to the full path to the gdk-pixbuf-pixdata executable; otherwise the resource compiler will
82 * Resource bundles are created by the <link linkend="glib-compile-resources">glib-compile-resources</link> program
83 * which takes an xml file that describes the bundle, and a set of files that the xml references. These
84 * are combined into a binary resource bundle.
86 * An example resource description:
88 * <?xml version="1.0" encoding="UTF-8"?>
90 * <gresource prefix="/org/gtk/Example">
91 * <file>data/splashscreen.png</file>
92 * <file compressed="true">dialog.ui</file>
93 * <file preprocess="xml-stripblanks">menumarkup.xml</file>
98 * This will create a resource bundle with the following files:
100 * /org/gtk/Example/data/splashscreen.png
101 * /org/gtk/Example/dialog.ui
102 * /org/gtk/Example/menumarkup.xml
105 * Note that all resources in the process share the same namespace, so use java-style
106 * path prefixes (like in the above example) to avoid conflicts.
108 * You can then use <link linkend="glib-compile-resources">glib-compile-resources</link> to compile the xml to a
109 * binary bundle that you can load with g_resource_load(). However, its more common to use the --generate-source and
110 * --generate-header arguments to create a source file and header to link directly into your application.
112 * Once a #GResource has been created and registered all the data in it can be accessed globally in the process by
113 * using API calls like g_resources_open_stream() to stream the data or g_resources_lookup_data() to get a direct pointer
114 * to the data. You can also use uris like "resource:///org/gtk/Example/data/splashscreen.png" with #GFile to access
117 * There are two forms of the generated source, the default version uses the compiler support for constructor
118 * and destructor functions (where available) to automatically create and register the #GResource on startup
119 * or library load time. If you pass --manual-register two functions to register/unregister the resource is instead
120 * created. This requires an explicit initialization call in your application/library, but it works on all platforms,
121 * even on the minor ones where this is not available. (Constructor support is available for at least Win32, MacOS and Linux.)
123 * Note that resource data can point directly into the data segment of e.g. a library, so if you are unloading libraries
124 * during runtime you need to be very careful with keeping around pointers to data from a resource, as this goes away
125 * when the library is unloaded. However, in practice this is not generally a problem, since most resource accesses
126 * is for your own resources, and resource data is often used once, during parsing, and then released.
132 * g_resource_error_quark:
134 * Gets the #GResource Error Quark.
136 * Return value: a #GQuark
140 G_DEFINE_QUARK (g-resource-error-quark, g_resource_error)
144 * @resource: A #GResource
146 * Atomically increments the reference count of @array by one. This
147 * function is MT-safe and may be called from any thread.
149 * Returns: The passed in #GResource
154 g_resource_ref (GResource *resource)
156 g_atomic_int_inc (&resource->ref_count);
162 * @resource: A #GResource
164 * Atomically decrements the reference count of @resource by one. If the
165 * reference count drops to 0, all memory allocated by the array is
166 * released. This function is MT-safe and may be called from any
172 g_resource_unref (GResource *resource)
174 if (g_atomic_int_dec_and_test (&resource->ref_count))
176 gvdb_table_unref (resource->table);
182 * g_resource_new_from_table:
183 * @table: (transfer full): a GvdbTable
185 * Returns: (transfer full): a new #GResource for @table
188 g_resource_new_from_table (GvdbTable *table)
192 resource = g_new (GResource, 1);
193 resource->ref_count = 1;
194 resource->table = table;
200 * g_resource_new_from_data:
202 * @error: return location for a #GError, or %NULL
204 * Creates a GResource from a reference to the binary resource bundle.
205 * This will keep a reference to @data while the resource lives, so
206 * the data should not be modified or freed.
208 * If you want to use this resource in the global resource namespace you need
209 * to register it with g_resources_register().
211 * Return value: (transfer full): a new #GResource, or %NULL on error
216 g_resource_new_from_data (GBytes *data,
221 table = gvdb_table_new_from_data (g_bytes_get_data (data, NULL),
222 g_bytes_get_size (data),
225 (GvdbRefFunc)g_bytes_ref,
226 (GDestroyNotify)g_bytes_unref,
232 return g_resource_new_from_table (table);
237 * @filename: (type filename): the path of a filename to load, in the GLib filename encoding
238 * @error: return location for a #GError, or %NULL
240 * Loads a binary resource bundle and creates a #GResource representation of it, allowing
241 * you to query it for data.
243 * If you want to use this resource in the global resource namespace you need
244 * to register it with g_resources_register().
246 * Return value: (transfer full): a new #GResource, or %NULL on error
251 g_resource_load (const gchar *filename,
256 table = gvdb_table_new (filename, FALSE, error);
260 return g_resource_new_from_table (table);
264 gboolean do_lookup (GResource *resource,
266 GResourceLookupFlags lookup_flags,
273 char *free_path = NULL;
275 gboolean res = FALSE;
278 path_len = strlen (path);
279 if (path[path_len-1] == '/')
281 path = free_path = g_strdup (path);
282 free_path[path_len-1] = 0;
285 value = gvdb_table_get_raw_value (resource->table, path);
289 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
290 _("The resource at '%s' does not exist"),
295 guint32 _size, _flags;
298 g_variant_get (value, "(uu@ay)",
303 _size = GUINT32_FROM_LE (_size);
304 _flags = GUINT32_FROM_LE (_flags);
311 *data = g_variant_get_data (array);
314 /* Don't report trailing newline that non-compressed files has */
315 if (_flags & G_RESOURCE_FLAGS_COMPRESSED)
316 *data_size = g_variant_get_size (array);
318 *data_size = g_variant_get_size (array) - 1;
320 g_variant_unref (array);
321 g_variant_unref (value);
331 * g_resource_open_stream:
332 * @resource: A #GResource
333 * @path: A pathname inside the resource
334 * @lookup_flags: A #GResourceLookupFlags
335 * @error: return location for a #GError, or %NULL
337 * Looks for a file at the specified @path in the resource and
338 * returns a #GInputStream that lets you read the data.
340 * @lookup_flags controls the behaviour of the lookup.
342 * Returns: (transfer full): #GInputStream or %NULL on error.
343 * Free the returned object with g_object_unref()
348 g_resource_open_stream (GResource *resource,
350 GResourceLookupFlags lookup_flags,
356 GInputStream *stream, *stream2;
358 if (!do_lookup (resource, path, lookup_flags, NULL, &flags, &data, &data_size, error))
361 stream = g_memory_input_stream_new_from_data (data, data_size, NULL);
362 g_object_set_data_full (G_OBJECT (stream), "g-resource",
363 g_resource_ref (resource),
364 (GDestroyNotify)g_resource_unref);
366 if (flags & G_RESOURCE_FLAGS_COMPRESSED)
368 GZlibDecompressor *decompressor =
369 g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB);
371 stream2 = g_converter_input_stream_new (stream, G_CONVERTER (decompressor));
372 g_object_unref (decompressor);
373 g_object_unref (stream);
381 * g_resource_lookup_data:
382 * @resource: A #GResource
383 * @path: A pathname inside the resource
384 * @lookup_flags: A #GResourceLookupFlags
385 * @error: return location for a #GError, or %NULL
387 * Looks for a file at the specified @path in the resource and
388 * returns a #GBytes that lets you directly access the data in
391 * The data is always followed by a zero byte, so you
392 * can safely use the data as a C string. However, that byte
393 * is not included in the size of the GBytes.
395 * For uncompressed resource files this is a pointer directly into
396 * the resource bundle, which is typically in some readonly data section
397 * in the program binary. For compressed files we allocate memory on
398 * the heap and automatically uncompress the data.
400 * @lookup_flags controls the behaviour of the lookup.
402 * Returns: (transfer full): #GBytes or %NULL on error.
403 * Free the returned object with g_bytes_unref()
408 g_resource_lookup_data (GResource *resource,
410 GResourceLookupFlags lookup_flags,
418 if (!do_lookup (resource, path, lookup_flags, &size, &flags, &data, &data_size, error))
421 if (flags & G_RESOURCE_FLAGS_COMPRESSED)
423 char *uncompressed, *d;
425 GConverterResult res;
426 gsize d_size, s_size;
427 gsize bytes_read, bytes_written;
430 GZlibDecompressor *decompressor =
431 g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB);
433 uncompressed = g_malloc (size + 1);
442 res = g_converter_convert (G_CONVERTER (decompressor),
445 G_CONVERTER_INPUT_AT_END,
449 if (res == G_CONVERTER_ERROR)
451 g_free (uncompressed);
452 g_object_unref (decompressor);
454 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_INTERNAL,
455 _("The resource at '%s' failed to decompress"),
461 s_size -= bytes_read;
463 d_size -= bytes_written;
465 while (res != G_CONVERTER_FINISHED);
467 uncompressed[size] = 0; /* Zero terminate */
469 g_object_unref (decompressor);
471 return g_bytes_new_take (uncompressed, size);
474 return g_bytes_new_with_free_func (data, data_size, (GDestroyNotify)g_resource_unref, g_resource_ref (resource));
478 * g_resource_get_info:
479 * @resource: A #GResource
480 * @path: A pathname inside the resource
481 * @lookup_flags: A #GResourceLookupFlags
482 * @size: (out) (allow-none): a location to place the length of the contents of the file,
483 * or %NULL if the length is not needed
484 * @flags: (out) (allow-none): a location to place the flags about the file,
485 * or %NULL if the length is not needed
486 * @error: return location for a #GError, or %NULL
488 * Looks for a file at the specified @path in the resource and
489 * if found returns information about it.
491 * @lookup_flags controls the behaviour of the lookup.
493 * Returns: %TRUE if the file was found. %FALSE if there were errors
498 g_resource_get_info (GResource *resource,
500 GResourceLookupFlags lookup_flags,
505 return do_lookup (resource, path, lookup_flags, size, flags, NULL, NULL, error);
509 * g_resource_enumerate_children:
510 * @resource: A #GResource
511 * @path: A pathname inside the resource
512 * @lookup_flags: A #GResourceLookupFlags
513 * @error: return location for a #GError, or %NULL
515 * Returns all the names of children at the specified @path in the resource.
516 * The return result is a %NULL terminated list of strings which should
517 * be released with g_strfreev().
519 * @lookup_flags controls the behaviour of the lookup.
521 * Returns: (array zero-terminated=1) (transfer full): an array of constant strings
526 g_resource_enumerate_children (GResource *resource,
528 GResourceLookupFlags lookup_flags,
533 char *path_with_slash;
537 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
538 _("The resource at '%s' does not exist"),
543 path_len = strlen (path);
544 if (path[path_len-1] != '/')
545 path_with_slash = g_strconcat (path, "/", NULL);
547 path_with_slash = g_strdup (path);
549 children = gvdb_table_list (resource->table, path_with_slash);
550 g_free (path_with_slash);
552 if (children == NULL)
554 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
555 _("The resource at '%s' does not exist"),
563 static GRWLock resources_lock;
564 static GList *registered_resources;
566 /* This is updated atomically, so we can append to it and check for NULL outside the
567 lock, but all other accesses are done under the write lock */
568 static GStaticResource *lazy_register_resources;
571 g_resources_register_unlocked (GResource *resource)
573 registered_resources = g_list_prepend (registered_resources, g_resource_ref (resource));
577 g_resources_unregister_unlocked (GResource *resource)
579 if (g_list_find (registered_resources, resource) == NULL)
581 g_warning ("Tried to remove not registered resource");
585 registered_resources = g_list_remove (registered_resources, resource);
586 g_resource_unref (resource);
591 * g_resources_register:
592 * @resource: A #GResource
594 * Registers the resource with the process-global set of resources.
595 * Once a resource is registered the files in it can be accessed
596 * with the global resource lookup functions like g_resources_lookup_data().
601 g_resources_register (GResource *resource)
603 g_rw_lock_writer_lock (&resources_lock);
604 g_resources_register_unlocked (resource);
605 g_rw_lock_writer_unlock (&resources_lock);
609 * g_resources_unregister:
610 * @resource: A #GResource
612 * Unregisters the resource from the process-global set of resources.
617 g_resources_unregister (GResource *resource)
619 g_rw_lock_writer_lock (&resources_lock);
620 g_resources_unregister_unlocked (resource);
621 g_rw_lock_writer_unlock (&resources_lock);
625 * g_resources_open_stream:
626 * @path: A pathname inside the resource
627 * @lookup_flags: A #GResourceLookupFlags
628 * @error: return location for a #GError, or %NULL
630 * Looks for a file at the specified @path in the set of
631 * globally registered resources and returns a #GInputStream
632 * that lets you read the data.
634 * @lookup_flags controls the behaviour of the lookup.
636 * Returns: (transfer full): #GInputStream or %NULL on error.
637 * Free the returned object with g_object_unref()
642 g_resources_open_stream (const gchar *path,
643 GResourceLookupFlags lookup_flags,
646 GInputStream *res = NULL;
648 GInputStream *stream;
650 register_lazy_static_resources ();
652 g_rw_lock_reader_lock (&resources_lock);
654 for (l = registered_resources; l != NULL; l = l->next)
656 GResource *r = l->data;
657 GError *my_error = NULL;
659 stream = g_resource_open_stream (r, path, lookup_flags, &my_error);
660 if (stream == NULL &&
661 g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
663 g_clear_error (&my_error);
668 g_propagate_error (error, my_error);
675 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
676 _("The resource at '%s' does not exist"),
679 g_rw_lock_reader_unlock (&resources_lock);
685 * g_resources_lookup_data:
686 * @path: A pathname inside the resource
687 * @lookup_flags: A #GResourceLookupFlags
688 * @error: return location for a #GError, or %NULL
690 * Looks for a file at the specified @path in the set of
691 * globally registered resources and returns a #GBytes that
692 * lets you directly access the data in memory.
694 * The data is always followed by a zero byte, so you
695 * can safely use the data as a C string. However, that byte
696 * is not included in the size of the GBytes.
698 * For uncompressed resource files this is a pointer directly into
699 * the resource bundle, which is typically in some readonly data section
700 * in the program binary. For compressed files we allocate memory on
701 * the heap and automatically uncompress the data.
703 * @lookup_flags controls the behaviour of the lookup.
705 * Returns: (transfer full): #GBytes or %NULL on error.
706 * Free the returned object with g_bytes_unref()
711 g_resources_lookup_data (const gchar *path,
712 GResourceLookupFlags lookup_flags,
719 register_lazy_static_resources ();
721 g_rw_lock_reader_lock (&resources_lock);
723 for (l = registered_resources; l != NULL; l = l->next)
725 GResource *r = l->data;
726 GError *my_error = NULL;
728 data = g_resource_lookup_data (r, path, lookup_flags, &my_error);
730 g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
732 g_clear_error (&my_error);
737 g_propagate_error (error, my_error);
744 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
745 _("The resource at '%s' does not exist"),
748 g_rw_lock_reader_unlock (&resources_lock);
754 * g_resources_enumerate_children:
755 * @path: A pathname inside the resource
756 * @lookup_flags: A #GResourceLookupFlags
757 * @error: return location for a #GError, or %NULL
759 * Returns all the names of children at the specified @path in the set of
760 * globally registered resources.
761 * The return result is a %NULL terminated list of strings which should
762 * be released with g_strfreev().
764 * @lookup_flags controls the behaviour of the lookup.
766 * Returns: (array zero-terminated=1) (transfer full): an array of constant strings
771 g_resources_enumerate_children (const gchar *path,
772 GResourceLookupFlags lookup_flags,
775 GHashTable *hash = NULL;
780 register_lazy_static_resources ();
782 g_rw_lock_reader_lock (&resources_lock);
784 for (l = registered_resources; l != NULL; l = l->next)
786 GResource *r = l->data;
788 children = g_resource_enumerate_children (r, path, 0, NULL);
790 if (children != NULL)
793 hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
795 for (i = 0; children[i] != NULL; i++)
796 g_hash_table_insert (hash, children[i], children[i]);
801 g_rw_lock_reader_unlock (&resources_lock);
805 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
806 _("The resource at '%s' does not exist"),
815 n_children = g_hash_table_size (hash);
816 children = g_new (char *, n_children + 1);
819 g_hash_table_iter_init (&iter, hash);
820 while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL))
821 children[i++] = g_strdup (key);
822 children[i++] = NULL;
824 g_hash_table_destroy (hash);
831 * g_resources_get_info:
832 * @path: A pathname inside the resource
833 * @lookup_flags: A #GResourceLookupFlags
834 * @size: (out) (allow-none): a location to place the length of the contents of the file,
835 * or %NULL if the length is not needed
836 * @flags: (out) (allow-none): a location to place the flags about the file,
837 * or %NULL if the length is not needed
838 * @error: return location for a #GError, or %NULL
840 * Looks for a file at the specified @path in the set of
841 * globally registered resources and if found returns information about it.
843 * @lookup_flags controls the behaviour of the lookup.
845 * Returns: %TRUE if the file was found. %FALSE if there were errors
850 g_resources_get_info (const gchar *path,
851 GResourceLookupFlags lookup_flags,
856 gboolean res = FALSE;
860 register_lazy_static_resources ();
862 g_rw_lock_reader_lock (&resources_lock);
864 for (l = registered_resources; l != NULL; l = l->next)
866 GResource *r = l->data;
867 GError *my_error = NULL;
869 r_res = g_resource_get_info (r, path, lookup_flags, size, flags, &my_error);
871 g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
873 g_clear_error (&my_error);
878 g_propagate_error (error, my_error);
885 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
886 _("The resource at '%s' does not exist"),
889 g_rw_lock_reader_unlock (&resources_lock);
894 /* This code is to handle registration of resources very early, from a constructor.
895 * At that point we'd like to do minimal work, to avoid ordering issues. For instance,
896 * we're not allowed to use g_malloc, as the user need to be able to call g_mem_set_vtable
897 * before the first call to g_malloc.
899 * So, what we do at construction time is that we just register a static structure on
900 * a list of resources that need to be initialized, and then later, when doing any lookups
901 * in the global list of registered resources, or when getting a reference to the
902 * lazily initialized resource we lazily create and register all the GResources on
905 * To avoid having to use locks in the constructor, and having to grab the writer lock
906 * when checking the lazy registering list we update lazy_register_resources in
907 * a lock-less fashion (atomic prepend-only, atomic replace with NULL). However, all
909 * * check if there are any resources to lazily initialize
910 * * Add a static resource to the lazy init list
911 * Do use the full writer lock for protection.
915 register_lazy_static_resources_unlocked (void)
917 GStaticResource *list;
920 list = lazy_register_resources;
921 while (!g_atomic_pointer_compare_and_exchange (&lazy_register_resources, list, NULL));
925 GBytes *bytes = g_bytes_new_static (list->data, list->data_len);
926 GResource *resource = g_resource_new_from_data (bytes, NULL);
929 g_resources_register_unlocked (resource);
930 g_atomic_pointer_set (&list->resource, resource);
932 g_bytes_unref (bytes);
939 register_lazy_static_resources (void)
941 if (g_atomic_pointer_get (&lazy_register_resources) == NULL)
944 g_rw_lock_writer_lock (&resources_lock);
945 register_lazy_static_resources_unlocked ();
946 g_rw_lock_writer_unlock (&resources_lock);
950 * g_static_resource_init:
951 * @static_resource: pointer to a static #GStaticResource
953 * Initializes a GResource from static data using a
956 * This is normally used by code generated by
957 * <link linkend="glib-compile-resources">glib-compile-resources</link>
958 * and is not typically used by other code.
963 g_static_resource_init (GStaticResource *static_resource)
969 next = lazy_register_resources;
970 static_resource->next = next;
972 while (!g_atomic_pointer_compare_and_exchange (&lazy_register_resources, next, static_resource));
976 * g_static_resource_fini:
977 * @static_resource: pointer to a static #GStaticResource
979 * Finalized a GResource initialized by g_static_resource_init().
981 * This is normally used by code generated by
982 * <link linkend="glib-compile-resources">glib-compile-resources</link>
983 * and is not typically used by other code.
988 g_static_resource_fini (GStaticResource *static_resource)
992 g_rw_lock_writer_lock (&resources_lock);
994 register_lazy_static_resources_unlocked ();
996 resource = g_atomic_pointer_get (&static_resource->resource);
999 g_atomic_pointer_set (&static_resource->resource, NULL);
1000 g_resources_unregister_unlocked (resource);
1001 g_resource_unref (resource);
1004 g_rw_lock_writer_unlock (&resources_lock);
1008 * g_static_resource_get_resource:
1009 * @static_resource: pointer to a static #GStaticResource
1011 * Gets the GResource that was registered by a call to g_static_resource_init().
1013 * This is normally used by code generated by
1014 * <link linkend="glib-compile-resources">glib-compile-resources</link>
1015 * and is not typically used by other code.
1017 * Return value: (transfer none): a #GResource
1022 g_static_resource_get_resource (GStaticResource *static_resource)
1024 register_lazy_static_resources ();
1026 return g_atomic_pointer_get (&static_resource->resource);