PB 5.30 Linker error on import of g_signal_connect

Just starting out? Need help? Post your questions and find answers here.
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

PB 5.30 Linker error on import of g_signal_connect

Post by uwekel »

Hi,

in a lot of my sources i am connecting GTK events with the g_signal_connect_() library function and this works well. At the moment, i am converting all my sources to make them work with unicode mode.

Unfortunately, the GTK imports provided by PureBasic do not use the p-utf8 pseudotype for strings, so all library functions with pointers to strings do not work. An easy workaround is to import the required function with a missing leading dash and use the p-utf8 pseudo type for strings. This works on all functions i have tested, but not with the g_signal_connect() function.

Here is a sample code to test:

Code: Select all

ImportC ""
  g_signal_connect(*instance, signal.p-utf8, *handler, *data)
  ;g_signal_connect_data(*instance, signal.p-utf8, *handler, *data, *destroy_data, *connect_flags)
EndImport

ProcedureC Event()
  Debug "destroyed"
EndProcedure

OpenWindow(0, 0, 0, 300, 300, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)

g_signal_connect(WindowID(0), "destroy", @Event(), 0)
;g_signal_connect_data(WindowID(0), "destroy", @Event(), 0, 0, 0)

Repeat
  Select WaitWindowEvent()
  Case #PB_Event_CloseWindow
    Break
  EndSelect
ForEver
When i run the code, i get this error:
Image
If you comment out the g_signal_connect() and uncomment the g_signal_connect_data() lines, you can see that g_signal_connect_data() works as expected.

Does anyone know why this happens?

I hope the PB team will update the library bindings and use p-utf8 if the IDE has moved to unicode mode only.

Best regards
Uwe
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PB 5.30 Linker error on import of g_signal_connect

Post by luis »

g_signal_connect() is a macro, so you have to use g_signal_connect_data() instead.

/usr/include/glib-2.0/gobject/gsignal.h

Code: Select all

/* --- convenience --- */
/**
* g_signal_connect:
* @instance: the instance to connect to.
* @detailed_signal: a string of the form "signal-name::detail".
* @c_handler: the #GCallback to connect.
* @data: data to pass to @c_handler calls.
*
* Connects a #GCallback function to a signal for a particular object.
*
* The handler will be called before the default handler of the signal.
*
* Returns: the handler id
*/
#define g_signal_connect(instance, detailed_signal, c_handler, data) \
g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
"Have you tried turning it off and on again ?"
A little PureBasic review
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: PB 5.30 Linker error on import of g_signal_connect

Post by uwekel »

Thank you luis, i did not know that. The hint to lookup in the C++ headers is good, although i do not know very much about C++.

Do you know whythe PB bindings do not use p-utf8?
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: PB 5.30 Linker error on import of g_signal_connect

Post by ts-soft »

uwekel wrote:Do you know whythe PB bindings do not use p-utf8?
The api automated wrapped, so pb gives the pointer to untouched string.

I hope, this will be changed in future.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PB 5.30 Linker error on import of g_signal_connect

Post by luis »

Hi uwekel
uwekel wrote:The hint to lookup in the C++ headers is good, although i do not know very much about C++.
It's just C fortunately, a lot similar to PB.
It's a good thing in Linux you can look at the sources of everything because documentation it's a lot shakier than on Windows for many things.
uwekel wrote: Do you know why the PB bindings do not use p-utf8?
No, I don't.
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply