[Geany-Devel] Problem with pointer from API function

Austin Green austin.green at xxxxx
Mon Aug 26 04:26:15 UTC 2019

Hi All,

I'm new to Geany hacking, so please be kind in your response to possibly dumb question.

Trying to make changes to "addons" plugin, and found that I needed to call keybindings_get_core_group(), so added the GEANY_API_SYMBOL to that function and rebuilt Geany.  It appeared to work, in that it returned a pointer,but when I tried to access the structure members pointed to, it segfaulted.  Adding diagnostics to the keybindings_get_core_group function, found that I could access the structure members while still in that function. Displayed the value of the pointer, both in the function and on return to my caller; they were identical.  (See code samples below)  So: the pointer apparently only works in its originating context.  Curious as to what's happening here.  Is there more to do than just adding GEANY_API_SYMBOL?  Or is it to do with keybindings_get_core_group being in a shared library?

Geany version:
geany 1.33 (git >= 63257599) (built on 2019-08-23 with GTK 3.22.30, GLib 2.56.4)
OS version:
Linux kernel 4.15.0-58-generic 64-bit Ubuntu x86_64

Example code:

In my calling function:
    key_group_clipboard = keybindings_get_core_group(GEANY_KEY_GROUP_CLIPBOARD);
    g_printf("Ptr: %0X\n", key_group_clipboard);
    gchar* s = key_group_clipboard->name;    // segfaults

In keybindings_get_core_group():
    key_group = &groups[id];
    gchar* s = key_group->name;    // works fine
    g_printf("Ptr: %0X, Name: %s\n", key_group, s);
        // displays same ptr as in caller, and correct name string

BTW, found that I didn't need to call keybindings_get_core_group after all, achieved the results I wanted by other means.  But would still like to know what's wrong.

Thanks in advance,

More information about the Devel mailing list