Re: Missing GObject.connect function in typelib, but present in gir
Marko Tasic <[email protected]> Sat, 26 Mar 2011 10:37:25 +0100
| Newsgroups | gmane.comp.gnome.language-bindings |
|---|---|
| Message-ID | <[email protected]> |
--===============0320563616== Content-Type: multipart/alternative; boundary=00235452e960793df5049f5f766d --00235452e960793df5049f5f766d Content-Type: text/plain; charset=UTF-8 Rotty, Thank you for the explanation. Last night, I implemented it this way, too, and it has worked without any problems. Hello World example is straight forward, and easy to understand for gtk, pygtk and pygobject devs. It is funny how both of us faced the same problem and had similar/same solution for it. Regards, Marko Tasic On Fri, Mar 25, 2011 at 2:54 PM, Andreas Rottmann <[email protected]> wrote: > Marko Tasic <[email protected]> writes: > > > Rotty, > > > > I took look at sbank, and I think it's more advance at this point than > > pygir-ctypes. > > Good job! However, I did it this way: > > > > * created new struct that extended GClosure called PyClosure > > * added notifiers for finalize and invalidate > > * instantiated PyClosure > > * connected with "hid = GObject.signal_connect_closure(window, 'destroy', > > closure, False)" > > * runned > > > > But, it fails with "Segmentation fault" on window close. > > > > Can you explain how you did this? > > > I didn't (anywhere in the code) mess with GClosure. Here's what I did > for signal connection (see gobject/signals.sls for the full code): > > - Manually pull out the relevant function from libgobject: > > (define-c-callouts libgobject > (connect-data% 'ulong "g_signal_connect_data" > '(pointer pointer fpointer pointer fpointer int)) > [...]) > > - Then invoke the Scheme procedure bound to that function; passing it an > appropriate callback-wrapper (a function pointer that calls back into > Scheme, I guess Python's ctypes does have these as well): > > (define (g-signal-connect instance signal callback) > (define (lose msg . irritants) > (apply error 'g-signal-connect msg irritants)) > (let*-values > (((signal detail detailed-signal) (parse-signal-spec signal lose)) > ((prepare) (gobject-class-get-signal-callback > (ginstance-class instance) > signal))) > (unless prepare > (lose "no such signal" detailed-signal)) > (receive (cb-ptr reclaim) (prepare callback) > (let* ((detailed-signal-ptr (string->utf8z-ptr detailed-signal)) > (id (connect-data% > (ginstance-ptr instance) > detailed-signal-ptr > cb-ptr > (null-pointer) > (callback-destroy-notify reclaim) > 0))) > (free detailed-signal-ptr) > id)))) > > The notable things here are: > > - I pull a callback-wrapper creation procedure using > `gobject-class-get-signal-callback' out of the class object > associated with the instance in question, and bind it to `prepare'. > The class object knows about the signals and their argument/return > types, so it can produce that callback-wrapper generator procedure. > > - Call `prepare', getting a function pointer (`cb-ptr') and a > procedure for reclaiming the callback (`reclaim'). > > - Finally, invoke g_signal_connect_data() (aka connect-data%), passing > the function pointer and a destroy notification function pointer > that will call `reclaim'. > > HTH, Rotty > -- > Andreas Rottmann -- <http://rotty.yi.org/> > --00235452e960793df5049f5f766d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Rotty,<div><br></div><div>Thank you for the explanation. Last night, I impl= emented it this way, too,</div><div>and it has worked without any problems.= Hello World example is straight</div><div>forward, and easy to understand = for gtk, pygtk and pygobject devs.</div> <div><br></div><div>It is funny how both of us faced the same problem and h= ad similar/same</div><div>solution for it.</div><div><br></div><div>Regards= ,</div><div>Marko Tasic<br> <br><br><div class=3D"gmail_quote">On Fri, Mar 25, 2011 at 2:54 PM, Andreas= Rottmann <span dir=3D"ltr"><<a href=3D"mailto:[email protected]">a.rott= [email protected]</a>></span> wrote:<br><blockquote class=3D"gmail_quote" styl= e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> <div class=3D"im">Marko Tasic <<a href=3D"mailto:[email protected]">mta= [email protected]</a>> writes:<br> <br> </div><div class=3D"im">> Rotty,<br> ><br> > I took look at sbank, and I think it's more advance at this point = than<br> > pygir-ctypes.<br> > Good job! However, I did it this way:<br> ><br> > * created new struct that extended GClosure called PyClosure<br> > * added notifiers for finalize and invalidate<br> > * instantiated PyClosure<br> > * connected with "hid =3D GObject.signal_connect_closure(window, = 'destroy',<br> > closure, False)"<br> > * runned<br> ><br> > But, it fails with "Segmentation fault" on window close.<br> ><br> > Can you explain how you did this?<br> ><br> </div>I didn't (anywhere in the code) mess with GClosure. =C2=A0Here= 9;s what I did<br> for signal connection (see gobject/signals.sls for the full code):<br> <br> - Manually pull out the relevant function from libgobject:<br> <br> =C2=A0(define-c-callouts libgobject<br> =C2=A0 =C2=A0(connect-data% 'ulong "g_signal_connect_data"<b= r> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 '(point= er pointer fpointer pointer fpointer int))<br> =C2=A0 =C2=A0[...])<br> <br> - Then invoke the Scheme procedure bound to that function; passing it an<br= > =C2=A0appropriate callback-wrapper (a function pointer that calls back int= o<br> =C2=A0Scheme, I guess Python's ctypes does have these as well):<br> <br> =C2=A0(define (g-signal-connect instance signal callback)<br> =C2=A0 =C2=A0(define (lose msg . irritants)<br> =C2=A0 =C2=A0 =C2=A0(apply error 'g-signal-connect msg irritants))<br> =C2=A0 =C2=A0(let*-values<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0(((signal detail detailed-signal) (parse-signal= -spec signal lose))<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ((prepare) (gobject-class-get-signal-callback<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (gin= stance-class instance)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sign= al)))<br> =C2=A0 =C2=A0 =C2=A0(unless prepare<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0(lose "no such signal" detailed-signa= l))<br> =C2=A0 =C2=A0 =C2=A0(receive (cb-ptr reclaim) (prepare callback)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0(let* ((detailed-signal-ptr (string->utf8z-p= tr detailed-signal))<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (id (connect-data%<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(gins= tance-ptr instance)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0detai= led-signal-ptr<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cb-pt= r<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(null= -pointer)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(call= back-destroy-notify reclaim)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0)))<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(free detailed-signal-ptr)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0id))))<br> <br> =C2=A0The notable things here are:<br> <br> =C2=A0- I pull a callback-wrapper creation procedure using<br> =C2=A0 =C2=A0`gobject-class-get-signal-callback' out of the class obje= ct<br> =C2=A0 =C2=A0associated with the instance in question, and bind it to `pre= pare'.<br> =C2=A0 =C2=A0The class object knows about the signals and their argument/r= eturn<br> =C2=A0 =C2=A0types, so it can produce that callback-wrapper generator proc= edure.<br> <br> =C2=A0- Call `prepare', getting a function pointer (`cb-ptr') and = a<br> =C2=A0 =C2=A0procedure for reclaiming the callback (`reclaim').<br> <br> =C2=A0- Finally, invoke g_signal_connect_data() (aka connect-data%), passi= ng<br> =C2=A0 =C2=A0the function pointer and a destroy notification function poin= ter<br> =C2=A0 =C2=A0that will call `reclaim'.<br> <br> HTH, Rotty<br> <div><div></div><div class=3D"h5">--<br> Andreas Rottmann -- <<a href=3D"http://rotty.yi.org/" target=3D"_blank">= http://rotty.yi.org/</a>><br> </div></div></blockquote></div><br></div> --00235452e960793df5049f5f766d-- --===============0320563616== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ language-bindings mailing list [email protected] http://mail.gnome.org/mailman/listinfo/language-bindings --===============0320563616==--