SystemStackError when rb_define_module_function() * 3

I'm getting a "test.rb:46: stack level too deep (SystemStackError)"
when defining three or more functions for a module, which is created
& given to Ruby via the Ruby C API. The test.rb (actually
"trunk/src/samp/test.rb") file and the remaining source code is
available in a Subversion repository here:

I originally thought the problem was with the third module function
(named "RVPI_rb_handle_by_name") that I was trying to register. But
this was not the case, because the SystemStackError occurred even
when I registered the first module function under a different name:

Advertisements

|In particular, the error occurs when I register a third module
|function with Ruby C API inside line 25 of the file
|"trunk/src/RVPI.cin":

Did SystemStackError happened during rb_define_module_function()?
What OS are you using?

There's no explicit limitation for number of rb_define_module_function()
calls, except for OS resource limit. SystemStackError is caused when
call stack is too deep, and the max depth is calculated in Init_stack().
Since you are using embedded Ruby, you may fail to call Init_stack()
in the interpreter initialization.

No, it happened later, when the Ruby interpreter was executing a script.
> What OS are you using?

Linux 2.6.12-10-386 #1 Mon Jan 16 17:18:08 UTC 2006 i686 GNU/Linux
> Since you are using embedded Ruby, you may fail to call Init_stack()
> in the interpreter initialization.

Ah, thank you. I tried putting a call to Init_stack() in my
initialization code but no luck. However, the problem is neither
with embedded Ruby nor with my initialization of the Ruby interpreter:

After some more investigation I happened upon the answer. There was
indeed a heap/stack limitation upon the Ruby interpreter embedded in
my C program!

(my C program, inside its own process
.. unlimited stack space ..

(Ruby interpreter, inside a pthread
.. 2 MiB of stack space ..

)
)

I was using the pthread library, with default attribute values
(thread stack size = 2 MiB) for pthread_create(), to launch the Ruby
interpreter. Naturally, the interpreter eventually ran out of stack
space and produced the SystemStackError.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!