From: Eric Hodel Date: 2006-08-01T10:39:29+09:00 Subject: Re: Ruby2CExtension (Was: converting some autogenerated ruby code to C) On Jul 31, 2006, at 5:19 PM, Dominik Bathon wrote: > On Tue, 01 Aug 2006 01:19:57 +0200, Eric Hodel > wrote: > >> On Jul 31, 2006, at 12:54 PM, Dominik Bathon wrote: >> >>> You could try Ruby2CExtension (http://ruby2cext.rubyforge.org/), >>> it is similar to rubyToRubyC but supports blocks and closures and >>> tries to match Ruby's semantics as close as possible. It can >>> handle most Ruby code. >> >> I tried it, it doesn't work. > > Thanks for the report. > >> $ svn info . | egrep 'Revision|URL' >> URL: svn://rubyforge.org/var/svn/ruby2cext/trunk >> Revision: 10 >> $ svn info ../../rubynode/trunk/ | egrep 'Revision|URL' >> URL: svn://rubyforge.org/var/svn/rubynode/trunk >> Revision: 4 >> $ ruby stuff/builtin_methods_test.rb >> 433 >> cc -dynamic -bundle -undefined suppress -flat_namespace -fno- >> common -O -pipe -fno-common -g -I. -I /usr/local/lib/ruby/1.8/ >> powerpc-darwin8.7.0 -o bm_test.bundle bm_test.c -lruby185-static - >> ldl -lobjc >> $ ruby -rbm_test -e0 >> ./bm_test.bundle: [BUG] Bus Error >> ruby 1.8.5 (2006-07-25) [powerpc-darwin8.7.0] > > This might be the problem, it is explicitly only for 1.8.4 (the > official release). There seem to have been some changes with > rbconfig so the build command (the line below 433) might be wrong. > > Future versions will support 1.8.5. > >> #0 st_lookup (table=0x0, key=6005024, value=0xbfffe938) at st.c:250 >> #1 0x00566c04 in rb_intern (name=0x5ba120 "abs") at parse.y:6006 > > This line is > > if (st_lookup(sym_tbl, (st_data_t)name, (st_data_t *)&id)) > > So sym_tbl seems to be NULL, which definitely shouldn't be the > case, so as I said, I think it's a build problem. > > Could you please try to build bm_test.c with the following > extconf.rb (with ruby 1.8.5 (2006-07-25) [powerpc-darwin8.7.0]): > > require "mkmf" > create_makefile "bm_test" > > And please also post the output of make. > > And could you also try with 1.8.4 official release? $ gdb `which ruby184` GNU gdb 6.3.50-20050815 (Apple version gdb-477) (Sun Apr 30 20:06:22 GMT 2006) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "powerpc-apple-darwin"...Reading symbols for shared libraries .... done (gdb) run -r bm_test -e0 Starting program: /usr/local/bin/ruby184 -r bm_test -e0 Reading symbols for shared libraries .. done Reading symbols for shared libraries . done Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_PROTECTION_FAILURE at address: 0x00000000 st_lookup (table=0x0, key=5874688, value=0xbfffe928) at st.c:245 245 st.c: No such file or directory. in st.c (gdb) bt #0 st_lookup (table=0x0, key=5874688, value=0xbfffe928) at st.c:245 #1 0x00533294 in rb_intern (name=0x59a400 "abs") at parse.y:5996 #2 0x00505f80 in Init_bm_test () at bm_test.c:9 #3 0x0001e498 in dln_load (file=0x420580 "./bm_test.bundle") at dln.c:1482 #4 0x00019c40 in rb_require_safe (fname=1898796, safe=0) at eval.c:7044 #5 0x00003480 in rb_protect (proc=0x19d4c , data=4325664, state=0xbffff1e8) at eval.c:5335 #6 0x0005fc60 in require_libraries () at ruby.c:356 #7 0x0006115c in proc_options (argc=0, argv=0x59a400) at ruby.c:812 #8 0x0006139c in ruby_process_options (argc=4, argv=0xbffff790) at ruby.c:1192 #9 0x0001ae04 in ruby_options (argc=4, argv=0xbffff790) at eval.c:1460 #10 0x000027ec in main (argc=4, argv=0xbffff790, envp=0xbfffe928) at main.c:45 (gdb) $ ruby184 -v ruby 1.8.4 (2005-12-24) [powerpc-darwin8.4.0] But if I create extconf.rb it seems to work: $ ruby184 extconf.rb creating Makefile $ make gcc -I. -I/usr/local/lib/ruby/1.8/powerpc-darwin8.4.0 -I/usr/local/ lib/ruby/1.8/powerpc-darwin8.4.0 -I. -fno-common -g -O2 -pipe -fno- common -c bm_test.c cc -dynamic -bundle -undefined suppress -flat_namespace -L"/usr/ local/lib" -o bm_test.bundle bm_test.o -ldl -lobjc $ ruby -r bm_test -e0 $ echo $? 0 $ Same for 1.8.5. rb2cx exhibits the same problems as not using mkmf. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com