From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-06-27T18:04:41+09:00 Subject: Re: collect info about ruby-api On Fri, 27 Jun 2003 18:21:28 +0900, ts wrote: >>>>>> "S" == Simon Strandgaard <0bz63fz3m1qt3001@sneakemail.com> writes: > > S> I don't know what plruby_call_handler() does.. but it definitly uses > S> Init_stack() > > plruby_call_handler() is the entry point for plruby : each time that > postgres need to call a procedural function written in ruby it will call > plruby_call_handler() > > S> int pl_call_level; hmmm, don't know what this is either. > > a procedural function written in ruby can call another procedural function > written in ruby : pl_call_level will say if it's the first call or if it's > a "recursive" call. If its a nested request, then Init_stack will only be invoked once (first request). If its not a nested request, then Init_stack is executed. OK? Browsing mod_ruby, I see that Init_stack is invoked within their library-bootstrap function (ruby_startup). It is not invoked per request. Why this difference ? BTW: In VIM/if_ruby.c Init_stack is not used at all! > S> Any hints ? :-) > > Normally ruby_init() (which call Init_stack()) must be called at the > beginning of the program (postgres in this case) to make sure that ruby > has the right value for the beginning of the stack. > > It's not possible (and I don't want) to modify postgres to be sure that > ruby_init() will be called at the right place (in main()). The > consequence is that plruby will call ruby_init() (to initialize ruby) the > first time that a procedural function written in ruby is called. > > Now where is the problem : imagine this case (the values for the stack are > just examples) > > * The first time that postgres call plruby_call_handler() the value of the > stack is 0xe0000000 > > - ruby_init() is called, and ruby will remember that the beginning of > the stack is 0xe0000000 > > - ruby will store VALUE from 0xe0000000 to 0xc0000000 (this is just an > example) > > * Another procedural function is called latter (and this is not a > "recursive" call) but this time the value for the stack is 0xf0000000 > (i.e. postgres use less stack when it call plruby_call_handler()) > > - ruby will store VALUE from 0xf0000000 to 0xd0000000 > > - if ruby call the GC, the GC will mark the objects from 0xe0000000 > (beginning of the stack when ruby_init() was called) to 0xd0000000. > When ruby run the sweep phase, it will remove all objects which are > stored in 0xf0000000-0xe0000000 > > - now after the GC, if plruby try to access objects stored in > 0xf0000000-0xe0000000, it just crash. Yes I see, the objects withing the range 0xf000-0xe000 is un-marked and will thus be sweept. I agree that trying to access destroyed instances can cause segfaults. > * To correct this : each time that plruby_call_handler() is called (and > this is not a "recursive" call) it call Init_stack() to be sure that > ruby has the right value for the beginning of the stack when it run the > GC Solution to the second request, am I right ??? Init_stack(0xf0000000); -- Simon Strandgaard