After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 667937 - allow creating schema source from resource
allow creating schema source from resource
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: gsettings
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: Allison Karlitskaya (desrt)
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-01-14 23:28 UTC by Christian Persch
Modified: 2018-05-24 13:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
settings: Plug resources into schema settings (4.89 KB, patch)
2012-01-14 23:28 UTC, Christian Persch
none Details | Review
Example code to read resources from elf files (2.81 KB, text/plain)
2012-01-17 11:25 UTC, Alexander Larsson
  Details
settings: Plug resources into schema settings (4.67 KB, patch)
2012-01-24 13:16 UTC, Christian Persch
none Details | Review

Description Christian Persch 2012-01-14 23:28:25 UTC
It should be possible to put a gschemas.compiled into a resource and use that to create a schema source.
Comment 1 Christian Persch 2012-01-14 23:28:44 UTC
Created attachment 205280 [details] [review]
settings: Plug resources into schema settings

Add g_settings_schema_source_new_from_resource().

Bug #667937.
Comment 2 Allison Karlitskaya (desrt) 2012-01-16 17:09:47 UTC
this is potentially evil due to the fact that it breaks the tools (editor, commandline)
Comment 3 Christian Persch 2012-01-16 19:11:47 UTC
IMHO that's not a blocker, since it would still be allowed to install the schema files to the usual paths for the tools to find, or those tools could just gain an option to take a executable and a resource path, and load the resources from it.
Comment 4 Alexander Larsson 2012-01-17 10:17:43 UTC
I can see how this could be usable. However, i think we need to make sure we know the full story of resources vs gsettings schemas before we put this in.

BTW. Its not *impossible* for e.g. dconf to access the build in schema file, at least on Linux. For instance you can use:

objcopy -j .gresource._gtk -Obinary libgtk-3.so gtk.gresource

To extract the gtk resources from the elf section, and you can then load the binary using g_resource_load() and access the schema.

In fact, with some minimal elf support you could probably mmap the library file, look up the .gresource.* section size and offsets in the elf header, and then directly g_resource_new_from_data() that region.

If this was supported then one could add a file in $datadir/glib-2.0/schemas/ pointing out the .so and the resource section name and the resource path.
Comment 5 Alexander Larsson 2012-01-17 11:25:36 UTC
Created attachment 205436 [details]
Example code to read resources from elf files

Here is an example of how to extract resources from an ELF file.
Compile it with:
 gcc `pkg-config --libs --cflags gio-2.0` -lelf dump-elf-resource.c -o dump-elf-resource

Then you can do e.g:
./dump-elf-resource libgtk-3.so _gtk /org/gtk/libgtk/gtk-default.css

to print the default gtk+ css
Comment 6 Alexander Larsson 2012-01-17 11:27:29 UTC
Note, we should probably strip any initial underscores from the c_name when generating the resource name.
Comment 7 Alexander Larsson 2012-01-17 11:35:09 UTC
Pushed a fix for the initial underscore to glib, so with that you need to use

 ./dump-elf-resource libgtk-3.so gtk /org/gtk/libgtk/gtk-default.css

instead.
Comment 8 Christian Persch 2012-01-17 13:50:25 UTC
Ryan: how about a g_settings_schema_source_new_from_data() then that just takes the raw data instead of the resource path? I can implement the new_from_resource as a tiny wrapper around that, but I can't do a new_from_data outside glib because I don't have access to gvdb from outside.
Comment 9 Christian Persch 2012-01-24 13:16:56 UTC
Created attachment 205975 [details] [review]
settings: Plug resources into schema settings

Add g_settings_schema_source_new_from_data().

This will allow to uses resources to create the schema source.

Bug #667937.
Comment 10 Allison Karlitskaya (desrt) 2012-01-26 20:12:06 UTC
I actually prefer the one that works from the resource.

I'd like to make sure that we first have a complete story about accessing schemas from resources inside of other people's binaries (for the sake of the gsettings commandline tool and dconf-editor).
Comment 11 Christian Persch 2016-08-13 18:22:03 UTC
Since the 'complete story' is unlikely to spontaneously emerge after > 4 years of this bug, can we just have the tiny function from attachment 205280 [details] [review] ? It'd be really useful to be able to embed the schema into the executable, no more asserts from mismatch with the installed schema (on key additions, for example). IMHO the 'complete story' is just corner cases (lockdown, overrides), and not that important (to me at least).
Comment 12 GNOME Infrastructure Team 2018-05-24 13:40:49 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/499.