From: leon breedt Date: 2004-11-30T12:01:23+09:00 Subject: Re: multiple rb_require()s causing segmentation fault On Tue, 30 Nov 2004 11:17:49 +0900, zarawesome@gmail.com wrote: On the face of it, I can't immediately see the cause of the segfault, though I suspect you may have memory corruption somewhere else, which is just being exposed by ScriptLoadFile. There are some problems with the code you gave, though: > char *filename_safe_require; ^^^ not a good idea, thread-unsafe, so you'll run into problems when Ruby starts supporting native OS threads, and you're exporting the symbol "filename_safe_require", which may not strictly be necessary. it will be safer to use stack-allocated storage for the parameter passing from ScriptLoadFile. > void ScriptLoadFile(char *filename) this does not match up with the way you are calling ScriptLoadFile (you are passing a second parameter in your invocations). to use stack allocation, i'd do something like: char *args[1]; int error; args[0] = filename; error = 0; rb_protect(SafeRequire, (VALUE)args, &error); and modify SafeRequire to look something like: static VALUE SafeRequire(VALUE arg) { char **args; args = (char**)arg; rb_require(args[0]); } disclaimer: i haven't tested this code, i reserve the right to hide if brown paper bag errors are found :) leon