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 to strip
70 * ignorable whitespace from the xml file. For this to work, the <envar>XMLLINT</envar>
71 * environment variable must be set to the full path to the xmllint executable, or xmllint
72 * must be in the PATH; otherwise the preprocessing step is skipped.
74 * <literal>to-pixdata</literal> which will use the gdk-pixbuf-pixdata command to convert
75 * images to the GdkPixdata format, which allows you to create pixbufs directly using the data inside
76 * the resource file, rather than an (uncompressed) copy if it. For this, the gdk-pixbuf-pixdata
77 * program must be in the PATH, or the <envar>GDK_PIXBUF_PIXDATA</envar> environment variable must be
78 * set to the full path to the gdk-pixbuf-pixdata executable; otherwise the resource compiler will
81 * Resource bundles are created by the <link linkend="glib-compile-resources">glib-compile-resources</link> program
82 * which takes an xml file that describes the bundle, and a set of files that the xml references. These
83 * are combined into a binary resource bundle.
85 * An example resource description:
87 * <?xml version="1.0" encoding="UTF-8"?>
89 * <gresource prefix="/org/gtk/Example">
90 * <file>data/splashscreen.png</file>
91 * <file compressed="true">dialog.ui</file>
92 * <file preprocess="xml-stripblanks">menumarkup.xml</file>
97 * This will create a resource bundle with the following files:
99 * /org/gtk/Example/data/splashscreen.png
100 * /org/gtk/Example/dialog.ui
101 * /org/gtk/Example/menumarkup.xml
104 * Note that all resources in the process share the same namespace, so use java-style
105 * path prefixes (like in the above example) to avoid conflicts.
107 * You can then use <link linkend="glib-compile-resources">glib-compile-resources</link> to compile the xml to a
108 * binary bundle that you can load with g_resource_load(). However, its more common to use the --generate-source and
109 * --generate-header arguments to create a source file and header to link directly into your application.
111 * Once a #GResource has been created and registered all the data in it can be accessed globally in the process by
112 * using API calls like g_resources_open_stream() to stream the data or g_resources_lookup_data() to get a direct pointer
113 * to the data. You can also use uris like "resource:///org/gtk/Example/data/splashscreen.png" with #GFile to access
116 * There are two forms of the generated source, the default version uses the compiler support for constructor
117 * and destructor functions (where available) to automatically create and register the #GResource on startup
118 * or library load time. If you pass --manual-register two functions to register/unregister the resource is instead
119 * created. This requires an explicit initialization call in your application/library, but it works on all platforms,
120 * even on the minor ones where this is not available. (Constructor support is available for at least Win32, MacOS and Linux.)
122 * Note that resource data can point directly into the data segment of e.g. a library, so if you are unloading libraries
123 * during runtime you need to be very careful with keeping around pointers to data from a resource, as this goes away
124 * when the library is unloaded. However, in practice this is not generally a problem, since most resource accesses
125 * is for your own resources, and resource data is often used once, during parsing, and then released.
131 * g_resource_error_quark:
133 * Gets the #GResource Error Quark.
135 * Return value: a #GQuark
139 G_DEFINE_QUARK (g-resource-error-quark, g_resource_error)
143 * @resource: A #GResource
145 * Atomically increments the reference count of @array by one. This
146 * function is MT-safe and may be called from any thread.
148 * Returns: The passed in #GResource
153 g_resource_ref (GResource *resource)
155 g_atomic_int_inc (&resource->ref_count);
161 * @resource: A #GResource
163 * Atomically decrements the reference count of @resource by one. If the
164 * reference count drops to 0, all memory allocated by the array is
165 * released. This function is MT-safe and may be called from any
171 g_resource_unref (GResource *resource)
173 if (g_atomic_int_dec_and_test (&resource->ref_count))
175 gvdb_table_unref (resource->table);
181 * g_resource_new_from_table:
182 * @table: (transfer full): a GvdbTable
184 * Returns: (transfer full): a new #GResource for @table
187 g_resource_new_from_table (GvdbTable *table)
191 resource = g_new (GResource, 1);
192 resource->ref_count = 1;
193 resource->table = table;
199 * g_resource_new_from_data:
201 * @error: return location for a #GError, or %NULL
203 * Creates a GResource from a reference to the binary resource bundle.
204 * This will keep a reference to @data while the resource lives, so
205 * the data should not be modified or freed.
207 * If you want to use this resource in the global resource namespace you need
208 * to register it with g_resources_register().
210 * Return value: (transfer full): a new #GResource, or %NULL on error
215 g_resource_new_from_data (GBytes *data,
220 table = gvdb_table_new_from_data (g_bytes_get_data (data, NULL),
221 g_bytes_get_size (data),
224 (GvdbRefFunc)g_bytes_ref,
225 (GDestroyNotify)g_bytes_unref,
231 return g_resource_new_from_table (table);
236 * @filename: (type filename): the path of a filename to load, in the GLib filename encoding
237 * @error: return location for a #GError, or %NULL
239 * Loads a binary resource bundle and creates a #GResource representation of it, allowing
240 * you to query it for data.
242 * If you want to use this resource in the global resource namespace you need
243 * to register it with g_resources_register().
245 * Return value: (transfer full): a new #GResource, or %NULL on error
250 g_resource_load (const gchar *filename,
255 table = gvdb_table_new (filename, FALSE, error);
259 return g_resource_new_from_table (table);
263 gboolean do_lookup (GResource *resource,
265 GResourceLookupFlags lookup_flags,
272 char *free_path = NULL;
274 gboolean res = FALSE;
277 path_len = strlen (path);
278 if (path[path_len-1] == '/')
280 path = free_path = g_strdup (path);
281 free_path[path_len-1] = 0;
284 value = gvdb_table_get_raw_value (resource->table, path);
288 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
289 _("The resource at '%s' does not exist"),
294 guint32 _size, _flags;
297 g_variant_get (value, "(uu@ay)",
302 _size = GUINT32_FROM_LE (_size);
303 _flags = GUINT32_FROM_LE (_flags);
310 *data = g_variant_get_data (array);
313 /* Don't report trailing newline that non-compressed files has */
314 if (_flags & G_RESOURCE_FLAGS_COMPRESSED)
315 *data_size = g_variant_get_size (array);
317 *data_size = g_variant_get_size (array) - 1;
319 g_variant_unref (array);
320 g_variant_unref (value);
330 * g_resource_open_stream:
331 * @resource: A #GResource
332 * @path: A pathname inside the resource
333 * @lookup_flags: A #GResourceLookupFlags
334 * @error: return location for a #GError, or %NULL
336 * Looks for a file at the specified @path in the resource and
337 * returns a #GInputStream that lets you read the data.
339 * @lookup_flags controls the behaviour of the lookup.
341 * Returns: (transfer full): #GInputStream or %NULL on error.
342 * Free the returned object with g_object_unref()
347 g_resource_open_stream (GResource *resource,
349 GResourceLookupFlags lookup_flags,
355 GInputStream *stream, *stream2;
357 if (!do_lookup (resource, path, lookup_flags, NULL, &flags, &data, &data_size, error))
360 stream = g_memory_input_stream_new_from_data (data, data_size, NULL);
361 g_object_set_data_full (G_OBJECT (stream), "g-resource",
362 g_resource_ref (resource),
363 (GDestroyNotify)g_resource_unref);
365 if (flags & G_RESOURCE_FLAGS_COMPRESSED)
367 GZlibDecompressor *decompressor =
368 g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB);
370 stream2 = g_converter_input_stream_new (stream, G_CONVERTER (decompressor));
371 g_object_unref (decompressor);
372 g_object_unref (stream);
380 * g_resource_lookup_data:
381 * @resource: A #GResource
382 * @path: A pathname inside the resource
383 * @lookup_flags: A #GResourceLookupFlags
384 * @error: return location for a #GError, or %NULL
386 * Looks for a file at the specified @path in the resource and
387 * returns a #GBytes that lets you directly access the data in
390 * The data is always followed by a zero byte, so you
391 * can safely use the data as a C string. However, that byte
392 * is not included in the size of the GBytes.
394 * For uncompressed resource files this is a pointer directly into
395 * the resource bundle, which is typically in some readonly data section
396 * in the program binary. For compressed files we allocate memory on
397 * the heap and automatically uncompress the data.
399 * @lookup_flags controls the behaviour of the lookup.
401 * Returns: (transfer full): #GBytes or %NULL on error.
402 * Free the returned object with g_bytes_unref()
407 g_resource_lookup_data (GResource *resource,
409 GResourceLookupFlags lookup_flags,
417 if (!do_lookup (resource, path, lookup_flags, &size, &flags, &data, &data_size, error))
420 if (flags & G_RESOURCE_FLAGS_COMPRESSED)
422 char *uncompressed, *d;
424 GConverterResult res;
425 gsize d_size, s_size;
426 gsize bytes_read, bytes_written;
429 GZlibDecompressor *decompressor =
430 g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB);
432 uncompressed = g_malloc (size + 1);
441 res = g_converter_convert (G_CONVERTER (decompressor),
444 G_CONVERTER_INPUT_AT_END,
448 if (res == G_CONVERTER_ERROR)
450 g_free (uncompressed);
451 g_object_unref (decompressor);
453 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_INTERNAL,
454 _("The resource at '%s' failed to decompress"),
460 s_size -= bytes_read;
462 d_size -= bytes_written;
464 while (res != G_CONVERTER_FINISHED);
466 uncompressed[size] = 0; /* Zero terminate */
468 g_object_unref (decompressor);
470 return g_bytes_new_take (uncompressed, size);
473 return g_bytes_new_with_free_func (data, data_size, (GDestroyNotify)g_resource_unref, g_resource_ref (resource));
477 * g_resource_get_info:
478 * @resource: A #GResource
479 * @path: A pathname inside the resource
480 * @lookup_flags: A #GResourceLookupFlags
481 * @size: (out) (allow-none): a location to place the length of the contents of the file,
482 * or %NULL if the length is not needed
483 * @flags: (out) (allow-none): a location to place the flags about the file,
484 * or %NULL if the length is not needed
485 * @error: return location for a #GError, or %NULL
487 * Looks for a file at the specified @path in the resource and
488 * if found returns information about it.
490 * @lookup_flags controls the behaviour of the lookup.
492 * Returns: %TRUE if the file was found. %FALSE if there were errors
497 g_resource_get_info (GResource *resource,
499 GResourceLookupFlags lookup_flags,
504 return do_lookup (resource, path, lookup_flags, size, flags, NULL, NULL, error);
508 * g_resource_enumerate_children:
509 * @resource: A #GResource
510 * @path: A pathname inside the resource
511 * @lookup_flags: A #GResourceLookupFlags
512 * @error: return location for a #GError, or %NULL
514 * Returns all the names of children at the specified @path in the resource.
515 * The return result is a %NULL terminated list of strings which should
516 * be released with g_strfreev().
518 * @lookup_flags controls the behaviour of the lookup.
520 * Returns: (array zero-terminated=1) (transfer full): an array of constant strings
525 g_resource_enumerate_children (GResource *resource,
527 GResourceLookupFlags lookup_flags,
532 char *path_with_slash;
536 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
537 _("The resource at '%s' does not exist"),
542 path_len = strlen (path);
543 if (path[path_len-1] != '/')
544 path_with_slash = g_strconcat (path, "/", NULL);
546 path_with_slash = g_strdup (path);
548 children = gvdb_table_list (resource->table, path_with_slash);
549 g_free (path_with_slash);
551 if (children == NULL)
553 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
554 _("The resource at '%s' does not exist"),
562 static GRWLock resources_lock;
563 static GList *registered_resources;
565 /* This is updated atomically, so we can append to it and check for NULL outside the
566 lock, but all other accesses are done under the write lock */
567 static GStaticResource *lazy_register_resources;
570 g_resources_register_unlocked (GResource *resource)
572 registered_resources = g_list_prepend (registered_resources, g_resource_ref (resource));
576 g_resources_unregister_unlocked (GResource *resource)
578 if (g_list_find (registered_resources, resource) == NULL)
580 g_warning ("Tried to remove not registered resource");
584 registered_resources = g_list_remove (registered_resources, resource);
585 g_resource_unref (resource);
590 * g_resources_register:
591 * @resource: A #GResource
593 * Registers the resource with the process-global set of resources.
594 * Once a resource is registered the files in it can be accessed
595 * with the global resource lookup functions like g_resources_lookup_data().
600 g_resources_register (GResource *resource)
602 g_rw_lock_writer_lock (&resources_lock);
603 g_resources_register_unlocked (resource);
604 g_rw_lock_writer_unlock (&resources_lock);
608 * g_resources_unregister:
609 * @resource: A #GResource
611 * Unregisters the resource from the process-global set of resources.
616 g_resources_unregister (GResource *resource)
618 g_rw_lock_writer_lock (&resources_lock);
619 g_resources_unregister_unlocked (resource);
620 g_rw_lock_writer_unlock (&resources_lock);
624 * g_resources_open_stream:
625 * @path: A pathname inside the resource
626 * @lookup_flags: A #GResourceLookupFlags
627 * @error: return location for a #GError, or %NULL
629 * Looks for a file at the specified @path in the set of
630 * globally registered resources and returns a #GInputStream
631 * that lets you read the data.
633 * @lookup_flags controls the behaviour of the lookup.
635 * Returns: (transfer full): #GInputStream or %NULL on error.
636 * Free the returned object with g_object_unref()
641 g_resources_open_stream (const gchar *path,
642 GResourceLookupFlags lookup_flags,
645 GInputStream *res = NULL;
647 GInputStream *stream;
649 register_lazy_static_resources ();
651 g_rw_lock_reader_lock (&resources_lock);
653 for (l = registered_resources; l != NULL; l = l->next)
655 GResource *r = l->data;
656 GError *my_error = NULL;
658 stream = g_resource_open_stream (r, path, lookup_flags, &my_error);
659 if (stream == NULL &&
660 g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
662 g_clear_error (&my_error);
667 g_propagate_error (error, my_error);
674 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
675 _("The resource at '%s' does not exist"),
678 g_rw_lock_reader_unlock (&resources_lock);
684 * g_resources_lookup_data:
685 * @path: A pathname inside the resource
686 * @lookup_flags: A #GResourceLookupFlags
687 * @error: return location for a #GError, or %NULL
689 * Looks for a file at the specified @path in the set of
690 * globally registered resources and returns a #GBytes that
691 * lets you directly access the data in memory.
693 * The data is always followed by a zero byte, so you
694 * can safely use the data as a C string. However, that byte
695 * is not included in the size of the GBytes.
697 * For uncompressed resource files this is a pointer directly into
698 * the resource bundle, which is typically in some readonly data section
699 * in the program binary. For compressed files we allocate memory on
700 * the heap and automatically uncompress the data.
702 * @lookup_flags controls the behaviour of the lookup.
704 * Returns: (transfer full): #GBytes or %NULL on error.
705 * Free the returned object with g_bytes_unref()
710 g_resources_lookup_data (const gchar *path,
711 GResourceLookupFlags lookup_flags,
718 register_lazy_static_resources ();
720 g_rw_lock_reader_lock (&resources_lock);
722 for (l = registered_resources; l != NULL; l = l->next)
724 GResource *r = l->data;
725 GError *my_error = NULL;
727 data = g_resource_lookup_data (r, path, lookup_flags, &my_error);
729 g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
731 g_clear_error (&my_error);
736 g_propagate_error (error, my_error);
743 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
744 _("The resource at '%s' does not exist"),
747 g_rw_lock_reader_unlock (&resources_lock);
753 * g_resources_enumerate_children:
754 * @path: A pathname inside the resource
755 * @lookup_flags: A #GResourceLookupFlags
756 * @error: return location for a #GError, or %NULL
758 * Returns all the names of children at the specified @path in the set of
759 * globally registered resources.
760 * The return result is a %NULL terminated list of strings which should
761 * be released with g_strfreev().
763 * @lookup_flags controls the behaviour of the lookup.
765 * Returns: (array zero-terminated=1) (transfer full): an array of constant strings
770 g_resources_enumerate_children (const gchar *path,
771 GResourceLookupFlags lookup_flags,
774 GHashTable *hash = NULL;
779 register_lazy_static_resources ();
781 g_rw_lock_reader_lock (&resources_lock);
783 for (l = registered_resources; l != NULL; l = l->next)
785 GResource *r = l->data;
787 children = g_resource_enumerate_children (r, path, 0, NULL);
789 if (children != NULL)
792 hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
794 for (i = 0; children[i] != NULL; i++)
795 g_hash_table_insert (hash, children[i], children[i]);
800 g_rw_lock_reader_unlock (&resources_lock);
804 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
805 _("The resource at '%s' does not exist"),
814 n_children = g_hash_table_size (hash);
815 children = g_new (char *, n_children + 1);
818 g_hash_table_iter_init (&iter, hash);
819 while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL))
820 children[i++] = g_strdup (key);
821 children[i++] = NULL;
823 g_hash_table_destroy (hash);
830 * g_resources_get_info:
831 * @path: A pathname inside the resource
832 * @lookup_flags: A #GResourceLookupFlags
833 * @size: (out) (allow-none): a location to place the length of the contents of the file,
834 * or %NULL if the length is not needed
835 * @flags: (out) (allow-none): a location to place the flags about the file,
836 * or %NULL if the length is not needed
837 * @error: return location for a #GError, or %NULL
839 * Looks for a file at the specified @path in the set of
840 * globally registered resources and if found returns information about it.
842 * @lookup_flags controls the behaviour of the lookup.
844 * Returns: %TRUE if the file was found. %FALSE if there were errors
849 g_resources_get_info (const gchar *path,
850 GResourceLookupFlags lookup_flags,
855 gboolean res = FALSE;
859 register_lazy_static_resources ();
861 g_rw_lock_reader_lock (&resources_lock);
863 for (l = registered_resources; l != NULL; l = l->next)
865 GResource *r = l->data;
866 GError *my_error = NULL;
868 r_res = g_resource_get_info (r, path, lookup_flags, size, flags, &my_error);
870 g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
872 g_clear_error (&my_error);
877 g_propagate_error (error, my_error);
884 g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
885 _("The resource at '%s' does not exist"),
888 g_rw_lock_reader_unlock (&resources_lock);
893 /* This code is to handle registration of resources very early, from a constructor.
894 * At that point we'd like to do minimal work, to avoid ordering issues. For instance,
895 * we're not allowed to use g_malloc, as the user need to be able to call g_mem_set_vtable
896 * before the first call to g_malloc.
898 * So, what we do at construction time is that we just register a static structure on
899 * a list of resources that need to be initialized, and then later, when doing any lookups
900 * in the global list of registered resources, or when getting a reference to the
901 * lazily initialized resource we lazily create and register all the GResources on
904 * To avoid having to use locks in the constructor, and having to grab the writer lock
905 * when checking the lazy registering list we update lazy_register_resources in
906 * a lock-less fashion (atomic prepend-only, atomic replace with NULL). However, all
908 * * check if there are any resources to lazily initialize
909 * * Add a static resource to the lazy init list
910 * Do use the full writer lock for protection.
914 register_lazy_static_resources_unlocked (void)
916 GStaticResource *list;
919 list = lazy_register_resources;
920 while (!g_atomic_pointer_compare_and_exchange (&lazy_register_resources, list, NULL));
924 GBytes *bytes = g_bytes_new_static (list->data, list->data_len);
925 GResource *resource = g_resource_new_from_data (bytes, NULL);
928 g_resources_register_unlocked (resource);
929 g_atomic_pointer_set (&list->resource, resource);
931 g_bytes_unref (bytes);
938 register_lazy_static_resources (void)
940 if (g_atomic_pointer_get (&lazy_register_resources) == NULL)
943 g_rw_lock_writer_lock (&resources_lock);
944 register_lazy_static_resources_unlocked ();
945 g_rw_lock_writer_unlock (&resources_lock);
949 * g_static_resource_init:
950 * @static_resource: pointer to a static #GStaticResource
952 * Initializes a GResource from static data using a
955 * This is normally used by code generated by
956 * <link linkend="glib-compile-resources">glib-compile-resources</link>
957 * and is not typically used by other code.
962 g_static_resource_init (GStaticResource *static_resource)
968 next = lazy_register_resources;
969 static_resource->next = next;
971 while (!g_atomic_pointer_compare_and_exchange (&lazy_register_resources, next, static_resource));
975 * g_static_resource_fini:
976 * @static_resource: pointer to a static #GStaticResource
978 * Finalized a GResource initialized by g_static_resource_init().
980 * This is normally used by code generated by
981 * <link linkend="glib-compile-resources">glib-compile-resources</link>
982 * and is not typically used by other code.
987 g_static_resource_fini (GStaticResource *static_resource)
991 g_rw_lock_writer_lock (&resources_lock);
993 register_lazy_static_resources_unlocked ();
995 resource = g_atomic_pointer_get (&static_resource->resource);
998 g_atomic_pointer_set (&static_resource->resource, NULL);
999 g_resources_unregister_unlocked (resource);
1000 g_resource_unref (resource);
1003 g_rw_lock_writer_unlock (&resources_lock);
1007 * g_static_resource_get_resource:
1008 * @static_resource: pointer to a static #GStaticResource
1010 * Gets the GResource that was registered by a call to g_static_resource_init().
1012 * This is normally used by code generated by
1013 * <link linkend="glib-compile-resources">glib-compile-resources</link>
1014 * and is not typically used by other code.
1016 * Return value: (transfer none): a #GResource
1021 g_static_resource_get_resource (GStaticResource *static_resource)
1023 register_lazy_static_resources ();
1025 return g_atomic_pointer_get (&static_resource->resource);