Skip to content
Browse files

.rbo files are now initialized using a gcc constructor instead of an …

…Init_ function which was a bad idea (because the name is not unique)

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@2644 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent f839250 commit ec9446931b9f34f11c9e0fe50ddd21f47bfe76dc Laurent Sansonetti committed Sep 26, 2009
Showing with 17 additions and 14 deletions.
  1. +1 −3 bin/rubyc
  2. +11 −9 dln.c
  3. +1 −1 dln.h
  4. +4 −1 load.c
View
4 bin/rubyc
@@ -121,13 +121,11 @@ class Compiler
die "can't guess the init function of Ruby object file `#{obj}'"
end
- init_func = "Init_" + base.gsub(/-/, '_')
main_txt = <<EOS
extern "C" {
void *#{real_init_func}(void *, void *);
void *rb_vm_top_self(void);
- void
- #{init_func}(void) {
+ __attribute__((constructor)) static void __init__(void) {
#{real_init_func}(rb_vm_top_self(), 0);
}
}
View
20 dln.c
@@ -74,7 +74,7 @@ dln_strerror(void)
bool ruby_is_miniruby = false;
void*
-dln_load(const char *file)
+dln_load(const char *file, bool call_init)
{
if (ruby_is_miniruby) {
rb_raise(rb_eLoadError,
@@ -90,22 +90,24 @@ dln_load(const char *file)
{
void *handle;
- void (*init_fct)();
/* Load file */
if ((handle = (void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) == NULL) {
error = dln_strerror();
goto failed;
}
- init_fct = (void(*)())dlsym(handle, buf);
- if (init_fct == NULL) {
- error = DLN_ERROR();
- dlclose(handle);
- goto failed;
+ if (call_init) {
+ void (*init_fct)();
+ init_fct = (void(*)())dlsym(handle, buf);
+ if (init_fct == NULL) {
+ error = DLN_ERROR();
+ dlclose(handle);
+ goto failed;
+ }
+ /* Call the init code */
+ (*init_fct)();
}
- /* Call the init code */
- (*init_fct)();
return handle;
}
View
2 dln.h
@@ -37,5 +37,5 @@ char *dln_find_file_r(const char*,const char*,char*,int);
extern char *dln_argv0;
#endif
-void *dln_load(const char*);
+void *dln_load(const char*, bool);
#endif
View
5 load.c
@@ -272,8 +272,11 @@ rb_require_safe(VALUE fname, int safe)
break;
case TYPE_RBO:
+ dln_load(RSTRING_PTR(path), false);
+ break;
+
case TYPE_BUNDLE:
- dln_load(RSTRING_PTR(path));
+ dln_load(RSTRING_PTR(path), true);
break;
default:

0 comments on commit ec94469

Please sign in to comment.
Something went wrong with that request. Please try again.