From: "Suraj N. Kurapati" Date: 2008-04-18T10:57:14+09:00 Subject: Re: ruby_init() and C call stack in Ruby 1.9 Paul Brannan wrote: > On Fri, Apr 18, 2008 at 12:22:52AM +0900, Suraj N. Kurapati wrote: >> I really wish Ruby's C API was like OpenGL: a state machine. >> It doesn't matter from what stack position you query/modify the >> machine state. > > This would perhaps allow you to run multiple interpreters in the same > process, I don't think this would allow multiple interpreters because there is still only one global instance of the state machine (like in OpenGL). Instead, multiple interpreters would be possible if ruby_init() returned a token (which identifies a particular instance of the interpreter) and you used the token whenever calling Ruby's C API. Alternatively, you could attach/detach a particular Ruby instance to/from the global state machine. This is similar to pushing and popping ModelView matrices in OpenGL and operating on one matrix at a time. > but it would not solve the stack initialization problem. Ruby > needs to know the size and location of the stack so the GC can mark > objects on the stack. If ruby_init() dynamically allocated its own stack region, then it would know both the size and location of the stack. As a result, you could use Ruby's C API from any C call stack without causing trouble for Ruby (since Ruby has its own private stack which is hidden and isolated from the user).