From: Daniel Andersson Date: 2001-09-26T17:11:33+09:00 Subject: [ruby-talk:21713] Embedding woes Hello, I'm trying to embed ruby in a windows application. Ruby crashes when I try to define a class (rb_define_class). A detailed explaination: First I download and build ruby: ----8x----8x----8x----8x----8x----8x---- D:\Download\>gzip -d ruby-1.6.5.tar.gz D:\Download\>tar xf ruby-1.6.5.tar D:\Download\>cd ruby-1.6.5 D:\Download\ruby-1.6.5>win32\configure.bat type `nmake' to make ruby for mswin32. D:\Download\ruby-1.6.5>nmake D:\Download\ruby-1.6.5>nmake test Microsoft (R) Program Maintenance Utility Version 6.00.8168.0 Copyright (C) Microsoft Corp 1988-1998. All rights reserved. test succeeded D:\Download\ruby-1.6.5>ls -l mswin32-ruby16.dll mswin32-ruby16.lib -rw-rw-rw- 1 user group 983098 Sep 25 22:31 mswin32-ruby16.dll -rw-rw-rw- 1 user group 684534 Sep 25 22:31 mswin32-ruby16.lib D:\Download\ruby-1.6.5> ----8x----8x----8x----8x----8x----8x---- Then the test program (doesn't do much but it shows the problem) ----8x----8x----8x----8x----8x----8x---- #include "ruby.h" #pragma comment(lib,"D:\\Download\\ruby-1.6.5\\mswin32-ruby16.lib") int main(int argc, char **argv) { VALUE classtest; ruby_init(); ruby_script("embedded"); rb_eval_string("puts \"foo\""); classtest = rb_define_class("TestClass", rb_cObject); return 0; } ----8x----8x----8x----8x----8x----8x---- It compiles and links just fine. After putting the dll somewhere where it can be found (ie the same dir as the .exe) I try to run the program and the output is: foo and then it crashes. Running it through a debugger shows that it crashes here: class.c: 134 RBASIC(klass)->klass = rb_singleton_class_new(RBASIC(super)->klass); id 0x0000200d klass 0x00a3b4e8 super 0x42ac25ff in this function, super is whatever I supplied as the super-class in my call to rb_define_class (rb_cObject). Now I looked at line 130 in class.c: if (!super) super = rb_cObject; So it defaults to rb_cObject if I supply 0 as super-class. When I try this (classtest = rb_define_class("TestClass", 0);) the app doesn't crash. Further debugging shows that the rb_cObject in my test app and the one in class.c aren't the same: in class.c: rb_cObject 0x00a4a998 in my test main.c: rb_cObject 0x42a025ff What have I done wrong? The program is compiled with Visual C++ 6.0 Any comments are welcome Daniel Andersson