From: ts Date: 2003-06-27T17:21:28+09:00 Subject: Re: collect info about ruby-api >>>>> "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. 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. * 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 Guy Decoux