-
-
Notifications
You must be signed in to change notification settings - Fork 82
Dealing with G_DISABLE_CHECKS #270
Comments
It took me some time to track down this packaging guideline:
So one might argue that an It still is concerning to not be able to detect an incorrectly built library. And there is something more deterministic we can do: trigger a segfault in such library at startup. The downside would be that a correctly built version would emit a scary warning, e.g.: > LD_LIBRARY_PATH=/bad/gtk/lib ./crash-gtk
Segmentation fault (core dumped)
> ./crash-gtk
(process:31013): Gtk-CRITICAL **: gtk_main_quit: assertion 'main_loops != NULL' failed
> |
#ifdef G_ENABLE_DEBUG in gtk is gtk_arg_debug_cb Checking the compiled libraries confirms that it is in fact toggled during compilation. > nm gtkbad.so --demangle | grep gtk_arg_debug_cb
> nm gtkgood.so --demangle | grep gtk_arg_debug_cb
00000000002401c0 t gtk_arg_debug_cb So at runtime, I was thinking that we could use libloading to load gtk (since the search path should be the same) temporarily, and then check for that function. |
I can try this out tomorrow and get back to you if it works. |
Looks like it doesn't always get exported. > rpm -q gtk3
gtk3-3.18.7-2.fc23.x86_64
> nm --dynamic --demangle /lib64/libgtk-3.so | grep arg_debug
> |
Hmm, I tried diffing the > nm --dynamic --demangle /usr/lib/libgtk-3.so.0 | grep g_return_if_fail_warning
U g_return_if_fail_warning
> nm --dynamic --demangle gtkbad.so | grep g_return_if_fail_warning Would you mind confirming? |
Yes, that one |
Oh ok. |
One more idea: gtk only responds to extern crate gtk;
fn main() {
gtk::init();
gtk::idle_add(quit);
gtk::main();
}
fn quit() -> gtk::Continue {
gtk::main_quit();
return gtk::Continue(false);
} with > # Bad GTK
> GTK_DEBUG=help LD_LIBRARY_PATH=/home/honorabrutroll/gitproj/gtkg/gtkbad/gtk/.libs/:/home/honorabrutroll/gitproj/gtkg/gtkbad/gdk/.libs/:$LD_LIBRARY_PATH ./basic
Gtk-Message: Failed to load module "canberra-gtk-module" > # Good GTK
> GTK_DEBUG=help LD_LIBRARY_PATH=/home/honorabrutroll/gitproj/gtkg/gtkgood/gtk/.libs/:/home/honorabrutroll/gitproj/gtkg/gtkgood/gdk/.libs/:$LD_LIBRARY_PATH ./basic
Supported debug values: misc plugsocket text tree updates keybindings multihead modules geometry icontheme printing builder size-request no-css-cache baselines pixel-cache no-pixel-cache interactive touchscreen actions resize all help
Gtk-Message: Failed to load module "canberra-gtk-module" Don't really know how we would go about implementing this into the library though. |
Interesting idea. We could try capturing those logs by overriding the log handler before calling |
Let me see if |
It does in fact produce the same output. Code: extern crate gtk_sys;
use std::ptr;
use gtk_sys::gtk_parse_args;
fn main() {
unsafe {
gtk_parse_args(ptr::null_mut(), ptr::null_mut());
}
} |
So basically, we would:
For environment variables, I think the functions from |
I think I've figured out an easier way. 0.
|
I think we still need to store the |
Ah but that's the catch with |
I made a working prototype here. I used |
Thus far my tests have been successful: > LD_LIBRARY_PATH=/home/honorabrutroll/gitproj/gtkg/gtkgood/gtk/.libs/:/home/honorabrutroll/gitproj/gtkg/gtkgood/gdk/.libs/:$LD_LIBRARY_PATH cargo run
Running `/home/honorabrutroll/gitproj/gtk-test-debug/target/debug/gtkdebug`
GTK_DEBUG:
Gtk-Message: Failed to load module "canberra-gtk-module"
debug_flags_1: 1
Working library.
debug_flags_2: 0 > LD_LIBRARY_PATH=/home/honorabrutroll/gitproj/gtkg/gtkbad/gtk/.libs/:/home/honorabrutroll/gitproj/gtkg/gtkbad/gdk/.libs/:$LD_LIBRARY_PATH cargo run
Running `/home/honorabrutroll/gitproj/gtk-test-debug/target/debug/gtkdebug`
GTK_DEBUG:
Gtk-Message: Failed to load module "canberra-gtk-module"
debug_flags_1: 0
thread '<main>' panicked at 'This library was configured with --enable-debug=no', main.rs:67
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Process didn't exit successfully: `/home/honorabrutroll/gitproj/gtk-test-debug/target/debug/gtkdebug` (exit code: 101) > cargo run
Running `/home/honorabrutroll/gitproj/gtk-test-debug/target/debug/gtkdebug`
GTK_DEBUG:
debug_flags_1: 1
Working library.
debug_flags_2: 0 |
It working on windows with msys2's
|
I'm still not sure what benefits maintaining the list of debug options and performing slightly risky
|
Yeah that looks like a far more maintainable solution, and it does work with all of my tests. I just wasn't sure how using |
Ah so gtk would be storing the flags in set sections of the integer itself. That makes a lot more sense why you would be using binary ops now (I haven't seen or used bitflags before now). |
So I assume you'll be putting this in a PR @gkoz? |
@efyang I don't want to push this into the upcoming 0.0.7 release so sometime after. |
This breaks things on FreeBSD, as they configure libgtk with --disable-debug. I note that the referenced document is for glib, not libgtk, and they do build that with the default debug level. I have reached out to the maintainers about this issue. I've verified that building libgtk without specifying a debug level works properly. I'll be running with that while I continue to chase issues in the behavior of gtk. It'll be interesting to see how the system behavior changes. |
The recommendation for libgtk-3 is the same: https://developer.gnome.org/gtk3/stable/gtk-building.html#extra-configuration-options |
Homebrew's
(filed as Homebrew/homebrew-core#2142) |
Apparently affects libgtk on Ubuntu too. Filed https://bugs.launchpad.net/ubuntu/+source/gtk+3.0/+bug/1641358 Edit: Nevermind, not a bug in Ubuntu's libgtk configuration. It is already using the default, equivalent to |
I have a problem with that, too. I try to run tests in cargo with functions using gtk, see the following gist: This fails with various error messages, sometimes referencing to this bug. Weird thing is, if i comment out one of the tests it works fine - the problem seems to be running |
@cars10 try disable running tests in many treads https://internals.rust-lang.org/t/disable-parallel-tests/1592 |
Then it's even more weird: running with
|
After I add |
That sucks. Thanks., |
@cars10 I was stupid, we can use https://doc.rust-lang.org/book/testing.html#the-tests-directory. |
Add single digit version variant
GTK+ and other GLib-based libraries rely heavily on g_return_if_fail/g-return-val-if-fail checks for safety.
These shunts guard against undefined behavior.
But they're optional.
If
G_DISABLE_CHECKS
is set, this crate becomes unable to uphold the safety guarantees. We can't control that option because for technical and licensing reasonsgtk-sys
links withlibgtk-3
dynamically. Even detecting it in a straightforward way doesn't seem possible.Although the majority of those checks (
NULL
and object type checks) are superseded by Rust's type system, a significant number (potentially hundreds) remain necessary. Duplicating them all, beside being another handful of tedious error-prone work, would mean targeting not a documented interface but an implementation.Ideas?
The text was updated successfully, but these errors were encountered: