Re: NCI and callback functions
Stephane Peiry <[EMAIL PROTECTED]> wrote: > The only issue I see atm is if parrot wants to call the callback it- > self while in the "waiting for callback loop", mean it would run into > some race conditions if for some reasons parrot invokes the callback, > and somebody triggers the callback via gtk..? If the run loop is calling the callback too, you have to provide synchronization. > Is this dealt with explicitly? ie. parrot executing a function (the > callback) in a single go? No. A callback or any other event function can be interrupted in the current implementation. > ... Or is it meant to be up to the programmer, > like "you shouldnt call it yourself", or lock your data or else? Yep. > Thanks, > Stéphane leo
Re: NCI and callback functions
Well, still about getting callbacks to work on GTK, thaught that before going for this: On Tue, Aug 24, 2004 at 09:44:56AM +0200, Leopold Toetsch wrote: > >Otherwise, already thaught of actually unrolling the gtk_main function > >and have it handled/implemented within parrot directly (mainly gtk_main > >simply loops and waits on the gtk event queue). > > That's the way to go. giving a try to the idea of "putting gtk_main on its own thread" would be worth.. unless theres a thourough warning with a "dont do that" msg in it? Attached is the a really "quick hack" that uses nci again to actually start gtk_main on its own thread, rather than calling it directly and this works nicelly for what I tested :) The only issue I see atm is if parrot wants to call the callback it- self while in the "waiting for callback loop", mean it would run into some race conditions if for some reasons parrot invokes the callback, and somebody triggers the callback via gtk..? While thinking about this, isnt the current callback implementation having this issue, or how does it handle this? say if the callback function increments an int value passed in and then prints it, it should always print 1 (if 0 was passed) whereas afaik it might sometimes print 0 or 2 (depending on when the external lib and parrot would be calling in). Is this dealt with explicitly? ie. parrot executing a function (the callback) in a single go? Or is it meant to be up to the programmer, like "you shouldnt call it yourself", or lock your data or else? Thanks, Stéphane gtk.callbacks.tar.gz Description: GNU Zip compressed data
Re: NCI and callback functions
On Tue, Aug 24, 2004 at 09:44:56AM +0200, Leopold Toetsch wrote: > Whatever you'll try the current scheme is not compatible with this GTK > callback. Parrot needs a PMC as user_data. GTK awaits a GObject. > Yes. But draining the event queue still needs a running Parrot runloop. This made me remember that Ive tried sometime ago another of those gtk callback installer function that is g_signal_connect_data (wich is what the #defined g_signal_connect uses actually. That didn't broke, or even freeze the app, or else.. but it was "say" actually working.. o well.. Mainly Ive traced it to be sure and indeed, parrot is properly called each time the button pressed. Just that, as you say, parrot piles it up in its event queue.. and never takes it, since its busy "doing gtk_main". Well at least I know for sure how the whole callback scheme works now in parrot and can go try this: > >Otherwise, already thaught of actually unrolling the gtk_main function > >and have it handled/implemented within parrot directly (mainly gtk_main > >simply loops and waits on the gtk event queue). > > That's the way to go. ! :) Thanks, Stephane # -- Gtk Button Example. .sub _gtkcallback print "Hello\n" .end .sub _main @MAIN .include "glib.pasm" .include "gtk.pasm" .local pmc window .local pmc button .local pmc callback .local pmc userdata .local NCI init init = global "Gtk::gtk_init" init(0) # -- create the window .local NCI w_new w_new = global "Gtk::gtk_window_new" window = w_new(0) # -- create the button .local NCI b_new b_new = global "Gtk::gtk_button_new_with_label" button = b_new("Parrot") # -- install callback? .local pmc cb_sub cb_sub = global "_gtkcallback" userdata = new Integer userdata = 42 callback = new_callback cb_sub, userdata, "pU" # -- function sig is "'lptppi', then we have: #P5 is the button #P6 the callback #P7 data we may to pass through. #S5 "clicked" #I5 is 0 # -- Uncomment this section to actually install the callback # -- (this segfaulst on my system) .local NCI sig_conn sig_conn = global "Glib::g_signal_connect_data" sig_conn(button, "clicked", callback, userdata, 0, 0) # -- Set the container. .local NCI cont_add cont_add = global "Gtk::gtk_container_add" cont_add(window, button) # -- show button .local NCI w_show w_show = global "Gtk::gtk_widget_show" w_show(button) # -- show window w_show(window) .local NCI g_main g_main = global "Gtk::gtk_main" g_main() end .end saveall loadlib P1, 'libgtk-x11-2.0' dlfunc P2, P1, 'gtk_init', 'vii' store_global 'Gtk::gtk_init', P2 dlfunc P2, P1, 'gtk_main', 'vv' store_global 'Gtk::gtk_main', P2 dlfunc P2, P1, 'gtk_widget_show', 'vp' store_global 'Gtk::gtk_widget_show', P2 dlfunc P2, P1, 'gtk_container_add', 'vpp' store_global 'Gtk::gtk_container_add', P2 dlfunc P2, P1, 'gtk_button_new_with_label', 'pt' store_global 'Gtk::gtk_button_new_with_label', P2 dlfunc P2, P1, 'gtk_window_new', 'pi' store_global 'Gtk::gtk_window_new', P2 restoreall saveall loadlib P1, 'libgobject-2.0' dlfunc P2, P1, 'g_signal_connect_data', 'lptpPii' store_global 'Glib::g_signal_connect_data', P2 restoreall
Re: NCI and callback functions
Stephane Peiry wrote: dlfunc P2, P1, 'g_signal_connect_object', 'lptppi' Whatever you'll try the current scheme is not compatible with this GTK callback. Parrot needs a PMC as user_data. GTK awaits a GObject. Parrot stuffs the interpreter and the Sub PMC into user_data and unpacks that when the callback should run. This is based on the assumption that the function that establishes the callback takes a (void *) pointer and *does not* care, what the pointer is pointing to. GTK obviously takes either a NULL (which isn't usable with Parrot) or a GObject* only. I can currently only imagine to put the needed information "into" the function pointer, which is obviously not that easy: struct callback_info { Interp *interpreter; PMC *sub; opcode_t code[1]; } GTK gets the address of C< code >). At code[0] ... code[n] is a function (created NCI-like on-the-fly) that extracts the interpreter (code[-2]) and the Sub (code[-1]) and calls the C function inside Parrot that actually triggers the call of the callback. The problem is of course that it would need (minimal) JIT support for every platform. (as I understand it, by having "p" on the signature for the user data, gtk gets what it wants, a pointer to the user data, No. 'p' means that GTK get's, what PMC_data(user_data) is pointing to. I mean understood from this thread (*): [1] pdd16 states: Hand over control to the external library. IT IS IMPORTANT THAT THE INTERPRETER YOU ARE CALLING BACK INTO IS NOT ACTIVE WHEN THE CALLBACK IS MADE! That's IMHO a restriction we hardly can fulfill. This is the reason for: As we don't know, when the callback is invoked, my scheme uses an event so that its safe to run the PASM code. that callbacks were indeed installed through an event (that is on its own thread) so that it wouldnt block nomatter what parrot would be doing at a given point (say it invoked some long running function in a lib :) unless there would be a lock on the user data itself. Yes. But draining the event queue still needs a running Parrot runloop. Only because the event system is running its own thread does not mean, that we just can run the code at any time or in parallel with the foreground runloop. Callbacks or timer event subroutines are always run by the interpreter that created that event. This needs a running Parrot. Otherwise, already thaught of actually unrolling the gtk_main function and have it handled/implemented within parrot directly (mainly gtk_main simply loops and waits on the gtk event queue). That's the way to go. Thanks, Stephane leo
Re: NCI and callback functions
mh.. guess P is an actuall pointer to PMC, in that case forget that part.. :) Stephane On Mon, Aug 23, 2004 at 11:15:03PM +0200, Stephane Peiry wrote: [signatures question gone] > > *If* that is solved then the next problem is of course that by calling > > gtk_main() the GTK event loop is running. That means, while > > Parrot_callback_C() would get called, the callback fuction itself > > wouldn't get run because Parrot isn't executing any code at that point. > > Parrot is stuck in the NCI call to gtk_main(). > > mh.. thats was not the way I understood callbacks were implemented. > I mean understood from this thread (*): > > [1] pdd16 states: > Hand over control to the external library. IT IS > IMPORTANT THAT THE INTERPRETER YOU ARE CALLING BACK > INTO IS NOT ACTIVE WHEN THE CALLBACK IS MADE! > As we don't know, when the callback is invoked, my scheme uses an event > so that its safe to run the PASM code. > > that callbacks were indeed installed through an event (that is on its own > thread) so that it wouldnt block nomatter what parrot would be doing at a > given point (say it invoked some long running function in a lib :) unless > there would be a lock on the user data itself. > > Otherwise, already thaught of actually unrolling the gtk_main function > and have it handled/implemented within parrot directly (mainly gtk_main > simply loops and waits on the gtk event queue). Or maybe run it in its > own thread if the event threads are not enought? > Thanks, > Stephane
Re: NCI and callback functions
On Mon, Aug 23, 2004 at 12:14:51PM +0200, Leopold Toetsch wrote: > Leopold Toetsch wrote: > >Stephane Peiry wrote: > > > >> g_return_val_if_fail (G_IS_OBJECT (gobject), 0); Fails here > > >gtk shouldn't make assumption on the user_data argument IMHO. [...] > call is NULL, because of the same check, G_IS_OBJECT(gobject). mh.. ok, this whole thing made me try the following, and that is actually sticking to what I do really understand about nci and function signatures for parrot. Currently the signature is 'lptpPi' dlfunc P2, P1, 'g_signal_connect_object', 'lptpPi' and Ive placed P in there for the user data mainly because of the example taken from the t/pmc/nct.t tests and I thaught that well.. that would do the "right thing" :) Now I would have otherwise written the function sig as 'lptppi' dlfunc P2, P1, 'g_signal_connect_object', 'lptppi' as thats what gtk really wants, a pointer to the user data, and for sure "p" will give it exactly that. Doing so, gtk doesnt complain anymore, it goes onto creating the window, the button, installing the callback (by calling this g_signal..) without problems and shows the window and button. So now gtk is "happy" but parrot isnt: if I hit the button, it goes onto calling callback in parrot, and he breaks with: Parrot VM: PANIC: callback_info doesn't look like a pointer! C file src/inter_cb.c, line 132 (as I understand it, by having "p" on the signature for the user data, gtk gets what it wants, a pointer to the user data, but parrot doesnt like it because once it gets it, it doesnt get it wrapped into a PMC? otoh, if P is used then its gtk not happy because it wants a pointer rather than a - pmc - struct?.. how wrong is this view?) > *If* that is solved then the next problem is of course that by calling > gtk_main() the GTK event loop is running. That means, while > Parrot_callback_C() would get called, the callback fuction itself > wouldn't get run because Parrot isn't executing any code at that point. > Parrot is stuck in the NCI call to gtk_main(). mh.. thats was not the way I understood callbacks were implemented. I mean understood from this thread (*): [1] pdd16 states: Hand over control to the external library. IT IS IMPORTANT THAT THE INTERPRETER YOU ARE CALLING BACK INTO IS NOT ACTIVE WHEN THE CALLBACK IS MADE! As we don't know, when the callback is invoked, my scheme uses an event so that its safe to run the PASM code. that callbacks were indeed installed through an event (that is on its own thread) so that it wouldnt block nomatter what parrot would be doing at a given point (say it invoked some long running function in a lib :) unless there would be a lock on the user data itself. Otherwise, already thaught of actually unrolling the gtk_main function and have it handled/implemented within parrot directly (mainly gtk_main simply loops and waits on the gtk event queue). Or maybe run it in its own thread if the event threads are not enought? Thanks, Stephane (*) Subject: [CVS ci] approaching pdd16 callbacks http://groups.google.com/groups?q=callback+group:perl.perl6.internals&hl=en&lr=&ie=UTF-8&group=perl.perl6.internals&selm=4024E112.5030809%40toetsch.at&rnum=3 PS.: attached the same test files, just using the new signature. # -- Gtk Button Example. .sub _gtkcallback print "Hello\n" .end .sub _main @MAIN .include "glib.pasm" .include "gtk.pasm" .local pmc window .local pmc button .local pmc callback .local pmc userdata .local NCI init init = global "Gtk::gtk_init" init(0) # -- create the window .local NCI w_new w_new = global "Gtk::gtk_window_new" window = w_new(0) # -- create the button .local NCI b_new b_new = global "Gtk::gtk_button_new_with_label" button = b_new("Parrot") # -- install callback? .local pmc cb_sub cb_sub = global "_gtkcallback" userdata = new Integer userdata = 42 callback = new_callback cb_sub, userdata, "pU" # -- function sig is "'lptppi', then we have: #P5 is the button #P6 the callback #P7 data we may to pass through. #S5 "clicked" #I5 is 0 # -- Uncomment this section to actually install the callback # -- (this segfaulst on my system) .local NCI sig_conn sig_conn = global "Glib::g_signal_connect_object" sig_conn(button, "clicked", callback, userdata, 0) # -- Set the container. .local NCI cont_add cont_add = global "Gtk::gtk_container_add" cont_add(window, button) # -- show button .local NCI w_show w_show = global "Gtk::gtk_widget_show" w_show(button) # -- show window w_show(window) .local NCI g_main g_main = global "Gtk::gtk_main" g_main() end .end saveall loadlib P1, 'libgtk-x11-2.0' dlfunc P2, P1, 'gtk_init', 'vii' store_global 'Gtk::gtk_init', P2 dlfunc P2, P1, 'gtk_main', 'vv' store_global 'Gtk::gtk_main', P2 dlfunc P2, P1, 'gtk_widget_show', 'vp' store_global 'Gtk::gtk_widget_show', P2 dlfunc P2, P1, 'gtk_container
Re: NCI and callback functions
Leopold Toetsch wrote: Leopold Toetsch wrote: Stephane Peiry wrote: g_return_val_if_fail (G_IS_OBJECT (gobject), 0); Fails here gtk shouldn't make assumption on the user_data argument IMHO. The whole idea behind callbacks is, that there is a userdata argument that get's passed through transparently. GTK is taking a gobject only. So there is currently no way to use the existing callback scheme. Can't you wrap what you want to pass in a GObject?
Re: NCI and callback functions
Leopold Toetsch wrote: Stephane Peiry wrote: g_return_val_if_fail (G_IS_OBJECT (gobject), 0); Fails here gtk shouldn't make assumption on the user_data argument IMHO. I now tried calling g_cclosure_new_object() and g_signal_connect_closure() directly. Doesn't segfault anymore (at least, when you pass a String as user_data) But the return value of the first call is NULL, because of the same check, G_IS_OBJECT(gobject). The whole idea behind callbacks is, that there is a userdata argument that get's passed through transparently. GTK is taking a gobject only. So there is currently no way to use the existing callback scheme. *If* that is solved then the next problem is of course that by calling gtk_main() the GTK event loop is running. That means, while Parrot_callback_C() would get called, the callback fuction itself wouldn't get run because Parrot isn't executing any code at that point. Parrot is stuck in the NCI call to gtk_main(). leo
Re: NCI and callback functions
Stephane Peiry wrote: g_return_val_if_fail (G_IS_OBJECT (gobject), 0); Fails here anyway I just dont see what could be wrong with the way parrot could be passing the "user_data"? gtk shouldn't make assumption on the user_data argument IMHO. Whats the difference between the way parrot calls this, and the way the C example is doing it? As the parrot example follows exactly the same steps as the C one. The C example had NULL as user_data. Stephane leo
Re: NCI and callback functions
On Thu, Aug 19, 2004 at 01:21:33PM +0200, Leopold Toetsch wrote: > [ segfaulting example ] > >g_signal_connect_object (G_OBJECT (button), "clicked", > > G_CALLBACK (hello), NULL, 0); > > Are you sure, that these two G_foo() aren't doing something with the > function arguments? These are just typecasts/checks actually, so you can remove them and it will still work (youll receive a warning though when compiling it but otherwise it will work without problems - have tried it). > I've beautified the example a bit, segfaults much nicer now ;) Cool, thanks for that :), Ill go through the sdl examples as well to get on more pir. > Dunno, what's wrong. Just built a "debugable" version of gtk, so as to see whats going on when it enters this function. Mainly its "button" param, as well as its "user_data" are not set (or at least ddd doesnt know how to give me any info about it), but it breaks "because of its user data".. g_signal_connect_object (gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer gobject, GConnectFlags connect_flags) { g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); g_return_val_if_fail (detailed_signal != NULL, 0); g_return_val_if_fail (c_handler != NULL, 0); if (gobject) { GClosure *closure; g_return_val_if_fail (G_IS_OBJECT (gobject), 0); Fails here anyway I just dont see what could be wrong with the way parrot could be passing the "user_data"? Whats the difference between the way parrot calls this, and the way the C example is doing it? As the parrot example follows exactly the same steps as the C one. What ddd can tell me is: [instance] ? disableb [detailed_signal] = "clicked" [c_handler]= Parrot_callback_C [gobject] ? disabled [connect_flags]= 0 > leo Thanks, Stephane gobject.c.gz Description: GNU Zip compressed data
Re: NCI and callback functions
Stephane Peiry wrote: [ segfaulting example ] g_signal_connect_object (G_OBJECT (button), "clicked", G_CALLBACK (hello), NULL, 0); Are you sure, that these two G_foo() aren't doing something with the function arguments? I've beautified the example a bit, segfaults much nicer now ;) Dunno, what's wrong. leo # -- Gtk Button Example. .sub _gtkcallback print "Hello\n" .end .sub _main @MAIN .include "gtk.pasm" .local pmc window .local pmc button .local pmc callback .local pmc userdata .local NCI init init = global "Gtk::gtk_init" init(0) # -- create the window .local NCI w_new w_new = global "Gtk::gtk_window_new" window = w_new(0) # -- create the button .local NCI b_new b_new = global "Gtk::gtk_button_new_with_label" button = b_new("Parrot") # -- install callback? .local pmc cb_sub cb_sub = global "_gtkcallback" userdata = new Integer userdata = 42 callback = new_callback cb_sub, userdata, "vU" # -- function sig is "'lptpPi', then we have: #P5 is the button #P6 the callback #P7 data we may to pass through. #S5 "clicked" #I5 is 0 # -- Uncomment this section to actually install the callback # -- (this segfaulst on my system) .local NCI sig_conn sig_conn = global "Gtk::g_signal_connect_object" sig_conn(button, "clicked", callback, userdata, 0) # -- Set the container. .local NCI cont_add cont_add = global "Gtk::gtk_container_add" cont_add(window, button) # -- show button .local NCI w_show w_show = global "Gtk::gtk_widget_show" w_show(button) # -- show window w_show(window) .local NCI g_main g_main = global "Gtk::gtk_main" g_main() end .end
Re: NCI and callback functions
On Wed, Aug 18, 2004 at 09:11:17AM +0200, Leopold Toetsch wrote: > You've mixed up the function parameters. > > > P0 = global "Gtk::gtk_window_new" > > null I5 > > invoke > > > P15 = P5 > > I presume that's "instance" ... actually shouldnt the callback is for the button > > # -- function sig is "'lptpPi', then we have: > > #P5 is the button > > #P6 the callback > > #P7 data we may to pass through. > > #S5 "clicked" > > #I5 is 0 > > ... and the button is the "gobject". I did: > > set P6, P5# the callback > set P5, P15 # instance > set S5, "clicked" > set P7, P11 # button = object > > And got a clickable button labeled "Parrot". do you mean the callback worked? as I dont get it to on my system (ie if I activate the callback the it seg faults). > You might start using PIR code and named variables so that it gets > simpler to call such functions. Ok I have changed this a bit and should be more readable. Mainly attached is the C version of this small example, and the parrot version is just about a conversion to it line be line. (its simply a slightly modified of the Gtk tutorial "hello world", where instead of using the #defined g_signal_connect it uses the g_signal_connect_object function) Unless Im overlooking something the parrot version mimics exactly whats the C version does. Just still cant get it to work out the callback. > leo Thanks always, Stephane /* * Compile this with: * * gcc hello.c -o hello `pkg-config --cflags --libs gtk+-2.0` */ #include static void hello( GtkWidget *widget, gpointer data ) { g_print ("Hello\n"); } int main( int argc, char *argv[] ) { GtkWidget *window; GtkWidget *button; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); button = gtk_button_new_with_label ("Parrot"); g_signal_connect_object (G_OBJECT (button), "clicked", G_CALLBACK (hello), NULL, 0); gtk_container_add (GTK_CONTAINER (window), button); gtk_widget_show (button); gtk_widget_show (window); gtk_main (); return 0; } # -- Gtk Button Example. .sub _gtkcallback print "Hello\n" .end .sub _main @MAIN .include "gtk.pasm" .local pmc window .local pmc button .local pmc callback .local pmc userdata P0 = global "Gtk::gtk_init" I5 = 0 invoke # -- create the window P0 = global "Gtk::gtk_window_new" null I5 invoke window = P5 # -- create the button P0 = global "Gtk::gtk_button_new_with_label" S5 = "Parrot" invoke button = P5 # -- install callback? newsub P6, .Sub, _gtkcallback new P7, .Integer # -- just give it something even if dont care set P7, 42 userdata = P7 new_callback P5, P6, P7, "Ut" callback = P5 # -- function sig is "'lptpPi', then we have: #P5 is the button #P6 the callback #P7 data we may to pass through. #S5 "clicked" #I5 is 0 # -- Uncomment this section to actually install the callback # -- (this segfaulst on my system) # P0 = global "Gtk::g_signal_connect_object" # P5 = button # S5 = "clicked" # P6 = callback # P7 = userdata # I5 = 0 # invoke # -- . # -- Set the container. P5 = window P6 = button P0 = global "Gtk::gtk_container_add" invoke # -- show button P5 = button P0 = global "Gtk::gtk_widget_show" invoke # -- show window P5 = window P0 = global "Gtk::gtk_widget_show" invoke P0 = global "Gtk::gtk_main" invoke end .end saveall loadlib P1, 'libgtk-x11-2.0' dlfunc P2, P1, 'gtk_init', 'vii' store_global 'Gtk::gtk_init', P2 dlfunc P2, P1, 'gtk_main', 'vv' store_global 'Gtk::gtk_main', P2 dlfunc P2, P1, 'gtk_widget_show', 'vp' store_global 'Gtk::gtk_widget_show', P2 dlfunc P2, P1, 'gtk_container_add', 'vpp' store_global 'Gtk::gtk_container_add', P2 dlfunc P2, P1, 'gtk_button_new_with_label', 'pt' store_global 'Gtk::gtk_button_new_with_label', P2 dlfunc P2, P1, 'gtk_window_new', 'pi' store_global 'Gtk::gtk_window_new', P2 dlfunc P2, P1, 'g_signal_connect_object', 'lptpPi' store_global 'Gtk::g_signal_connect_object', P2 restoreall
Re: NCI and callback functions
Stephane Peiry <[EMAIL PROTECTED]> wrote: > ow.. ok, this one is actaully a macro.. the actual function is > gulong g_signal_connect_object (gpointer instance, > const gchar *detailed_signal, > GCallback c_handler, > gpointer gobject, > GConnectFlags connect_flags); > so I've changed this and now it does find it. Ah. Ok. You've mixed up the function parameters. > P0 = global "Gtk::gtk_window_new" > null I5 > invoke > P15 = P5 I presume that's "instance" ... > # -- function sig is "'lptpPi', then we have: > #P5 is the button > #P6 the callback > #P7 data we may to pass through. > #S5 "clicked" > #I5 is 0 ... and the button is the "gobject". I did: set P6, P5 # the callback set P5, P15 # instance set S5, "clicked" set P7, P11 # button = object And got a clickable button labeled "Parrot". You might start using PIR code and named variables so that it gets simpler to call such functions. leo
Re: NCI and callback functions
On Tue, Aug 17, 2004 at 09:01:39AM +0200, Leopold Toetsch wrote: > >> It returns a PerlUndef. > > 60 dlfunc P2, P1, "g_signal_connect", "lptpP" - \ > > P2=NCI=PMC(0x8363fd0), P1=ParrotLibrary=PMC(0x8364108), , > > 65 store_global "Gtk::g_signal_connec", P2 - , \ > >P2=PerlUndef=PMC(0x8363fb8 Num:0 Int:0) > ^ > > The symbol "g_signal_connect" isn't found in that lib. ow.. ok, this one is actaully a macro.. the actual function is gulong g_signal_connect_object (gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer gobject, GConnectFlags connect_flags); so I've changed this and now it does find it. And it does seem to "callback" as well, but there must something else wrong (or I'm missing something) as it dies anyway. Attached are again the test files, plus two dumps of my tries to run it. In one of them (run.null) I simply null the user data to be passed through. In that case it displays the button but dies as soon as it is clicked on (in this case it dies because the user data is null actually, but at least it let me now it does actually callback :) Parrot_callback_D then verify_CD). On other one (run), there is an actual (not null) user data. Know it goes somewhere into the g_signal function and (guess) also someway back.. but I'm really blind as to what is really happening there..? > leo Thanks Stephane 8 saveall 9 loadlib P1, "libgtk-x11-2.0" - P1=NULL, 12 dlfunc P2, P1, "gtk_init", "vii" - P2=NULL, P1=ParrotLibrary=PMC(0x8364108), , 17 store_global "Gtk::gtk_init", P2 - , P2=NCI=PMC(0x8364048) 20 dlfunc P2, P1, "gtk_main", "vv" - P2=NCI=PMC(0x8364048), P1=ParrotLibrary=PMC(0x8364108), , GC 25 store_global "Gtk::gtk_main", P2 - , P2=NCI=PMC(0x8364030) 28 dlfunc P2, P1, "gtk_widget_show", "vp" - P2=NCI=PMC(0x8364030), P1=ParrotLibrary=PMC(0x8364108), , 33 store_global "Gtk::gtk_widget_show", P2 - , P2=NCI=PMC(0x8364018) 36 dlfunc P2, P1, "gtk_container_add", "vpp"- P2=NCI=PMC(0x8364018), P1=ParrotLibrary=PMC(0x8364108), , 41 store_global "Gtk::gtk_container_a", P2 - , P2=NCI=PMC(0x8364000) GC 44 dlfunc P2, P1, "gtk_button_new_with_", "pt" - P2=NCI=PMC(0x8364000), P1=ParrotLibrary=PMC(0x8364108), , 49 store_global "Gtk::gtk_button_new_", P2 - , P2=NCI=PMC(0x8363fe8) 52 dlfunc P2, P1, "gtk_window_new", "pi"- P2=NCI=PMC(0x8363fe8), P1=ParrotLibrary=PMC(0x8364108), , 57 store_global "Gtk::gtk_window_new", P2 - , P2=NCI=PMC(0x8363fd0) GC 60 dlfunc P2, P1, "g_signal_connect_obj", "lptpPi" - P2=NCI=PMC(0x8363fd0), P1=ParrotLibrary=PMC(0x8364108), , 65 store_global "Gtk::g_signal_connec", P2 - , P2=NCI=PMC(0x8363fb8) 68 restoreall 69 find_global P0, "Gtk::gtk_init" - P0=NULL, 72 set I5, 0- I5=0, 75 invoke 76 find_global P0, "Gtk::gtk_window_new"- P0=NCI=PMC(0x8364048), GC 79 null I5 - I5=0 81 invoke 82 set P15, P5 - P15=NULL, P5=UnManagedStruct=PMC(0x8363fa0) 85 find_global P0, "Gtk::gtk_button_new_" - P0=NCI=PMC(0x8363fd0), 88 set S5, "Parrot" - , 91 invoke 92 set P6, P5 - P6=NULL, P5=UnManagedStruct=PMC(0x8363f88) GC 95 set P11, P5 - P11=NULL, P5=UnManagedStruct=PMC(0x8363f88) 98 newsub P6, 22, -98 - P6=UnManagedStruct=PMC(0x8363f88), , 102 new P7, 31 - P7=NULL, 105 set P7, 42 - P7=Integer=PMC(0x8363f58), 108 new_callback P5, P6, P7, "Ut"- P5=UnManagedStruct=PMC(0x8363f88), P6=Sub=PMC(0x8363f70 Adr:0x84e6628), P7=Integer=PMC(0x8363f58), GC 113 find_global P0, "Gtk::g_signal_connec" - P0=NCI=PMC(0x8363fe8), 116 set S5, "clicked"- S5="Parrot", 119 set I5, 0- I5=0, 122 set P6, P5 - P6=Sub=PMC(0x8363f70 Adr:0x84e6628), P5=UnManagedStruct=PMC(0x8363ef8) 125 set P5, P11 - P5=UnManagedStruct=PMC(0x8363ef8), P11=UnManagedStruct=PMC(0x8363f88) GC 128 invoke Segmentation fault 8 saveall 9 loadlib P1, "libgtk-x11-2.0" - P1=NULL, 12 dlfunc P2, P1, "gtk_init", "vii" - P2=NULL, P1=ParrotLibrary=PMC(0x8364108), , 17 store_global "Gtk::gtk_init", P2 - , P2=NCI=PMC(0x8364048) 20 dlfunc P2, P1, "gtk_main", "vv" - P2=NCI=PMC(0x8364048), P1=ParrotLibrary=PMC(0x8364108), , GC 25 store_global "Gtk::gtk_main", P2 - , P2=NCI=PMC(0x8364030) 28 dlfunc P2, P1, "gtk_widget_show", "vp" - P2=NCI=PMC(0x8364030), P1=ParrotLibrary=PMC(0x8364108), , 33 store_global "Gtk::gtk_widget_show", P2 - , P2=NCI=PMC(0x8364018) 36 dlfunc P2, P1, "gtk_container_add", "vpp"- P2=NCI=PMC(0x8364018),
Re: NCI and callback functions
Stephane Peiry <[EMAIL PROTECTED]> wrote: > On Mon, Aug 16, 2004 at 10:20:46AM +0200, Leopold Toetsch wrote: >> "gtk-signal-connect" or "g-signal-connect" isn't found here. I can't >> check the symbols of the lib, this dam** OS has symbols stripped. The >> other box has only gtk-1.2. > actually it should run as well against gtk-1.2 if "g_signal_connect" > is renamed "gtk_signal_connect". Attached here are the files with > that small change, but I've never been able to run any parrot code > against gtk v1.2 as parrot dies complaining: > /usr/lib/libgtk.so: undefined symbol: gdk_root_window Yep, I got that too. > actually its simply dlopen dumping this. > (btw there parrot displays a misleading ".. No such file or dir.." > caused by the way loadlib lookups for the lib, note for a patch if > I find a nice way to clean it :) Thought about that. The problem is that "no such file..." could come out in any language that happens to be defined in the current locale. We should ignore all "no such file..." errors, because we are looking for different names in different places. But, if it happens to be found, like "libgtk.so", and there is a different error message, we should stop right there and spit out this message. Maybe errno is set too. Dunno. >> It returns a PerlUndef. > 60 dlfunc P2, P1, "g_signal_connect", "lptpP" - \ > P2=NCI=PMC(0x8363fd0), P1=ParrotLibrary=PMC(0x8364108), , > 65 store_global "Gtk::g_signal_connec", P2- , \ >P2=PerlUndef=PMC(0x8363fb8 Num:0 Int:0) ^ The symbol "g_signal_connect" isn't found in that lib. leo
Re: NCI and callback functions
On Mon, Aug 16, 2004 at 10:20:46AM +0200, Leopold Toetsch wrote: > "gtk-signal-connect" or "g-signal-connect" isn't found here. I can't > check the symbols of the lib, this dam** OS has symbols stripped. The > other box has only gtk-1.2. actually it should run as well against gtk-1.2 if "g_signal_connect" is renamed "gtk_signal_connect". Attached here are the files with that small change, but I've never been able to run any parrot code against gtk v1.2 as parrot dies complaining: /usr/lib/libgtk.so: undefined symbol: gdk_root_window actually its simply dlopen dumping this. (btw there parrot displays a misleading ".. No such file or dir.." caused by the way loadlib lookups for the lib, note for a patch if I find a nice way to clean it :) > It returns a PerlUndef. > Run it with -t. Attached is the trace output. > leo Thanks, Stephane # -- Gtk Button Example. .sub _gtkcallback print "Hello\n" .end .sub main @MAIN .include "gtk.pasm" P0 = global "Gtk::gtk_init" I5 = 0 invoke P0 = global "Gtk::gtk_window_new" null I5 invoke P15 = P5 P0 = global "Gtk::gtk_button_new_with_label" S5 = "Parrot" invoke # -- Save it. P6 = P5 P11 = P5 # -- install callback? newsub P6, .Sub, _gtkcallback new P7, .Integer # -- just give it something even if dont care set P7, 42 new_callback P5, P6, P7, "U" P0 = global "Gtk::gtk_signal_connect" S5 = "clicked" P6 = P5 P5 = P11 invoke # -- . P5 = P11 P6 = P11 P0 = global "Gtk::gtk_widget_show" invoke # -- Set the container. P5 = P15 P0 = global "Gtk::gtk_container_add" invoke P0 = global "Gtk::gtk_widget_show" invoke P0 = global "Gtk::gtk_main" invoke end .end saveall loadlib P1, 'libgtk' dlfunc P2, P1, 'gtk_init', 'vii' store_global 'Gtk::gtk_init', P2 dlfunc P2, P1, 'gtk_main', 'vv' store_global 'Gtk::gtk_main', P2 dlfunc P2, P1, 'gtk_widget_show', 'vp' store_global 'Gtk::gtk_widget_show', P2 dlfunc P2, P1, 'gtk_container_add', 'vpp' store_global 'Gtk::gtk_container_add', P2 dlfunc P2, P1, 'gtk_button_new_with_label', 'pt' store_global 'Gtk::gtk_button_new_with_label', P2 dlfunc P2, P1, 'gtk_window_new', 'pi' store_global 'Gtk::gtk_window_new', P2 dlfunc P2, P1, 'gtk_signal_connect', 'lptpP' store_global 'Gtk::gtk_signal_connect', P2 restoreall $ ./parrot -t gtk.toplevel.button.imc 8 saveall 9 loadlib P1, "libgtk-x11-2.0" - P1=NULL, 12 dlfunc P2, P1, "gtk_init", "vii" - P2=NULL, P1=ParrotLibrary=PMC(0x8364108), , 17 store_global "Gtk::gtk_init", P2 - , P2=NCI=PMC(0x8364048) 20 dlfunc P2, P1, "gtk_main", "vv" - P2=NCI=PMC(0x8364048), P1=ParrotLibrary=PMC(0x8364108), , GC 25 store_global "Gtk::gtk_main", P2 - , P2=NCI=PMC(0x8364030) 28 dlfunc P2, P1, "gtk_widget_show", "vp" - P2=NCI=PMC(0x8364030), P1=ParrotLibrary=PMC(0x8364108), , 33 store_global "Gtk::gtk_widget_show", P2 - , P2=NCI=PMC(0x8364018) 36 dlfunc P2, P1, "gtk_container_add", "vpp"- P2=NCI=PMC(0x8364018), P1=ParrotLibrary=PMC(0x8364108), , 41 store_global "Gtk::gtk_container_a", P2 - , P2=NCI=PMC(0x8364000) GC 44 dlfunc P2, P1, "gtk_button_new_with_", "pt" - P2=NCI=PMC(0x8364000), P1=ParrotLibrary=PMC(0x8364108), , 49 store_global "Gtk::gtk_button_new_", P2 - , P2=NCI=PMC(0x8363fe8) 52 dlfunc P2, P1, "gtk_window_new", "pi"- P2=NCI=PMC(0x8363fe8), P1=ParrotLibrary=PMC(0x8364108), , 57 store_global "Gtk::gtk_window_new", P2 - , P2=NCI=PMC(0x8363fd0) GC 60 dlfunc P2, P1, "g_signal_connect", "lptpP" - P2=NCI=PMC(0x8363fd0), P1=ParrotLibrary=PMC(0x8364108), , 65 store_global "Gtk::g_signal_connec", P2 - , P2=PerlUndef=PMC(0x8363fb8 Num:0 Int:0) 68 restoreall 69 find_global P0, "Gtk::gtk_init" - P0=NULL, 72 set I5, 0- I5=0, 75 invoke 76 find_global P0, "Gtk::gtk_window_new"- P0=NCI=PMC(0x8364048), GC 79 null I5 - I5=0 81 invoke 82 set P15, P5 - P15=NULL, P5=UnManagedStruct=PMC(0x8363fa0) 85 find_global P0, "Gtk::gtk_button_new_" - P0=NCI=PMC(0x8363fd0), 88 set S5, "Parrot" - , 91 invoke 92 set P6, P5 - P6=NULL, P5=UnManagedStruct=PMC(0x8363f88) GC 95 set P11, P5 - P11=NULL, P5=UnManagedStruct=PMC(0x8363f88) 98 newsub P6, 22, -98 - P6=UnManagedStruct=PMC(0x8363f88), , 102 new P7, 31 - P7=NULL, 105 set P7, 42 - P7=Integer=PMC(0x8363f58), 108 new_callback P5, P6, P7, "U" - P5=UnManagedStruct=PMC(0x8363f88), P6=Sub=PMC(0x8363f70 Adr:0x84e6548), P7=Integer=PMC(0x8363f58), GC 113 find_global P0, "Gtk::g_signal_connec" - P0=NCI=PMC(0x8363fe8), 116 set S5, "clicked"- S5="Parrot", 119 set P5, P11 - P5=UnManagedStruct=PMC(0x8363ef8), P11=UnManagedStruct=PMC(0x8363f88) 122 invoke get_string() not implemented in class 'UnManagedStruct'\n
Re: NCI and callback functions
Stephane Peiry <[EMAIL PROTECTED]> wrote: > The problem is that as soon as it goes onto installing the callback > parrot returns with a "get_string() not implemented in class > 'UnManagedStruct'". > So what is happening there? "gtk-signal-connect" or "g-signal-connect" isn't found here. I can't check the symbols of the lib, this dam** OS has symbols stripped. The other box has only gtk-1.2. It returns a PerlUndef. Run it with -t. > Stephane leo
NCI and callback functions
Hi All, Ive been trying to get the (NCI) callbacks working with GTK but somehow cant. Mainly the attached file implements a (very) small test app where it simply displays a button within a window. The problem is that as soon as it goes onto installing the callback parrot returns with a "get_string() not implemented in class 'UnManagedStruct'". So what is happening there? Either the small test program attached is correct and therefore only need to implement that "get_string" for the UnManagedStruct PMC.. or theres something wrong with the code? Somehow I believe that the message (get_string not implemeted) is somewhat missleading? mean at least I dont understand why it enters this "get_string" function, as it dumps this message nomatther what signature I could make parrot beleive the callback function has. Also when trying to trace this with gdb, get_string gets called from a PerlInt PMC, even thaught I'm not using any PerlInt PMC. In GTK (using version 2) the calling function is: gulong g_signal_connect( gpointer *object, const gchar *name, GCallback func, gpointer func_data ); and the called: void callback_func( GtkWidget *widget, gpointer callback_data ); Any hints/help greatly appreciated :) Thanks, Stephane PS.: the attached file load "libgtk-x11-2.0" as this the GTK version 2 lib name on my RedHat.. please change that to libgtk or whatever GTKv2 libname on your system is to try it out. # -- Gtk Button Example. .sub _gtkcallback print "Hello\n" .end .sub main @MAIN .include "gtk.pasm" P0 = global "Gtk::gtk_init" I5 = 0 invoke P0 = global "Gtk::gtk_window_new" null I5 invoke P15 = P5 P0 = global "Gtk::gtk_button_new_with_label" S5 = "Parrot" invoke # -- Save it. P6 = P5 P11 = P5 # -- install callback? newsub P6, .Sub, _gtkcallback new P7, .Integer # -- just give it something even if dont care set P7, 42 new_callback P5, P6, P7, "U" P0 = global "Gtk::g_signal_connect" S5 = "clicked" P6 = P7 P5 = P11 invoke # -- . P5 = P11 P6 = P11 P0 = global "Gtk::gtk_widget_show" invoke # -- Set the container. P5 = P15 P0 = global "Gtk::gtk_container_add" invoke P0 = global "Gtk::gtk_widget_show" invoke P0 = global "Gtk::gtk_main" invoke end .end saveall loadlib P1, 'libgtk-x11-2.0' dlfunc P2, P1, 'gtk_init', 'vii' store_global 'Gtk::gtk_init', P2 dlfunc P2, P1, 'gtk_main', 'vv' store_global 'Gtk::gtk_main', P2 dlfunc P2, P1, 'gtk_widget_show', 'vp' store_global 'Gtk::gtk_widget_show', P2 dlfunc P2, P1, 'gtk_container_add', 'vpp' store_global 'Gtk::gtk_container_add', P2 dlfunc P2, P1, 'gtk_button_new_with_label', 'pt' store_global 'Gtk::gtk_button_new_with_label', P2 dlfunc P2, P1, 'gtk_window_new', 'pi' store_global 'Gtk::gtk_window_new', P2 dlfunc P2, P1, 'g_signal_connect', 'lptpP' store_global 'Gtk::g_signal_connect', P2 restoreall Summary of my parrot 0.1.0 configuration: configdate='Fri Aug 13 22:56:58 2004' Platform: osname=linux, archname=i386-linux-thread-multi jitcapable=1, jitarchname=i386-linux, jitosname=LINUX, jitcpuarch=i386 execcapable=1 perl=/usr/bin/perl Compiler: cc='gcc', ccflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm', Linker and Libraries: ld='gcc', ldflags=' -L/usr/local/lib', cc_ldflags='', libs='-lnsl -ldl -lm -lpthread -lcrypt -lutil -lrt -lgmp' Dynamic Linking: so='.so', ld_shared='-shared -L/usr/local/lib -fPIC', ld_shared_flags='' Types: iv=long, intvalsize=4, intsize=4, opcode_t=long, opcode_t_size=4, ptrsize=4, ptr_alignment=1 byteorder=1234, nv=double, numvalsize=8, doublesize=8