Exemple #1
0
void*
dln_load(const char *file, bool call_init)
{
    if (ruby_is_miniruby) {
	rb_raise(rb_eLoadError,
		"miniruby can't load C extension bundles due to technical problems");
    }

    const char *error = 0;
#define DLN_ERROR() (error = dln_strerror(), strcpy(ALLOCA_N(char, strlen(error) + 1), error))

    char *buf;
    /* Load the file as an object one */
    init_funcname(&buf, file);

    {
	void *handle;

	/* Load file */
	__mrep__ = NULL;
	if ((handle = (void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) == NULL) {
	    error = dln_strerror();
	    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)();
	}
	else {
	    if (__mrep__ == NULL) {
		rb_raise(rb_eLoadError, "Can't load %s: entry point function not located (this can happen when you load twice the same .rbo file with a different case on a case-insensitive filesystem)", file);
	    }
	    ((IMP)__mrep__)((id)rb_vm_top_self(), 0);
	}

	return handle;
    }

  failed:
    rb_loaderror("%s - %s", error, file);

    return 0;			/* dummy return */
}
Exemple #2
0
void*
dln_load(const char *file)
{
    const char *error = 0;
#define DLN_ERROR() (error = dln_strerror(), strcpy(ALLOCA_N(char, strlen(error) + 1), error))

    char *buf;
    /* Load the file as an object one */
    init_funcname(&buf, 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;
	}
	/* Call the init code */
	(*init_fct)();

	return handle;
    }

  failed:
    rb_loaderror("%s - %s", error, file);

    return 0;			/* dummy return */
}