Skip to content

EventControllerKey.set_static_name SEGFAULT #2053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
otaxhu opened this issue May 15, 2025 · 4 comments · May be fixed by #2056
Open

EventControllerKey.set_static_name SEGFAULT #2053

otaxhu opened this issue May 15, 2025 · 4 comments · May be fixed by #2056
Labels
bug Something isn't working

Comments

@otaxhu
Copy link

otaxhu commented May 15, 2025

Bug description

When I use the method EventControllerKey.set_static_name with a string literal param, then I add this controller to the window of the app, and then I open the GTK Inspector and visit the Controllers tab, I see one controller (I pressume it's the one I setted) with garbage characters (non-UTF-8), after navigating for a while, the application crashes with the Segmentation Fault (core dump) message.

I think it's because of the lifetime of the param not being 'static and the compiler optimizing it somehow.

fn set_static_name(name: Option<&str>) { ... }

Please provide a code sample as small as possible which reproduces the bug.

fn main() -> glib::ExitCode {
    let app: gtk::Application = glib::Object::builder().build();

    app.connect_activate(|app| {
        let window = gtk::ApplicationWindow::new(app);
        let key_controller = gtk::EventControllerKey::new();
        key_controller.set_static_name(Some("foo"));
        window.add_controller(key_controller);
        window.present()
    });

    app.run()
}

Backtrace

N/A because it doesn't panic, the process just get killed by the OS.

So the error is non-deterministic, I tried another run and the app didn't crash at any moment, but the garbage characters were still there

@otaxhu otaxhu added the bug Something isn't working label May 15, 2025
@otaxhu
Copy link
Author

otaxhu commented May 15, 2025

EventControllerKey.set_name works as expected, so this could be a workaround to this error for now.

@sdroege
Copy link
Member

sdroege commented May 16, 2025

The bindings for that function are wrong. They would have to use a &'static glib::GStr as parameter. Should also check if there are other such static string functions that need the same treatment.

You want to send a PR to manually implement bindings for that function?

@otaxhu
Copy link
Author

otaxhu commented May 16, 2025

Sure

@otaxhu
Copy link
Author

otaxhu commented May 16, 2025

What do you think about using this signature:

fn set_static_name<S: AsRef<str> + 'static>(name: Option<S>)

It should cover almost all of the types that implement AsRef<str> like String, GStr, GString, user-defined custom types, and str itself.

EDIT: The linked PR is using Option<&'static str>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants