# SystemStackError when rb\_define\_module\_function() \* 3

**URL:** <https://www.ruby-forum.com/t/systemstackerror-when-rb-define-module-function-3/53932>\
**Category:** Ruby\
**Created:** [February 17, 2006, 7:22am UTC](https://www.ruby-forum.com/t/systemstackerror-when-rb-define-module-function-3/53932 "2006-02-17T07:22:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![snk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@snk](https://www.ruby-forum.com/u/snk)\
**Post date:** [February 17, 2006, 7:22am UTC](https://www.ruby-forum.com/t/systemstackerror-when-rb-define-module-function-3/53932/1 "2006-02-17T07:22:04Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hello,

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.

## begin extra info

The test.rb (actually “samp/test.rb”) file and the remaining source  
code is available in a Subversion repository at RubyForge:

svn checkout -r21 svn://rubyforge.org/var/svn/ruby-vpi/trunk

- -or-  
[http://rubyforge.org/plugins/scmsvn/viewcvs.php/trunk/?root=ruby-vpi&pathrev=21](http://rubyforge.org/plugins/scmsvn/viewcvs.php/trunk/?root=ruby-vpi&pathrev=21)

Also, I run “make ivl” inside the “samp/” directory to run the  
sample test bench (“test.v” and “test.rb”).

Finally, I am using this Ruby version:  
ruby 1.8.3 (2005-06-23) [i486-linux]

## end extra info

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

// register the VPI module  
RVPI\_\_rModuleDef = rb\_define\_module(“VPI”);

rb\_define\_module\_function( // first func  
RVPI\_\_rModuleDef  
, “relay\_verilog”  
, RVPI\_rb\_relay\_verilog  
, 0  
);

rb\_define\_module\_function( // second func  
RVPI\_\_rModuleDef  
, “register\_task”  
, RVPI\_rb\_register\_task  
, 1  
);

rb\_define\_module\_function( // third func  
RVPI\_\_rModuleDef  
, “handle\_by\_name”  
, RVPI\_rb\_handle\_by\_name  
, 2  
); // FIXME: causes “stack level too deep (SystemStackError)”

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:

// register the VPI module  
RVPI\_\_rModuleDef = rb\_define\_module(“VPI”);

rb\_define\_module\_function( // first func  
RVPI\_\_rModuleDef  
, “relay\_verilog”  
, RVPI\_rb\_relay\_verilog  
, 0  
);

rb\_define\_module\_function( // second func  
RVPI\_\_rModuleDef  
, “register\_task”  
, RVPI\_rb\_register\_task  
, 1  
);

rb\_define\_module\_function( // first func with different name  
RVPI\_\_rModuleDef  
, “foo”  
, RVPI\_rb\_relay\_verilog  
, 0  
);

What am I doing wrong?

Thank you.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFD9WgQmV9O7RYnKMcRAnv6AKCp2axs4vC3+n9h1vSmBIP7QL+ISgCdGH6X  
U6pkTj3RoLSsPNj0dL1xVQg=  
=18Ev  
-----END PGP SIGNATURE-----
