Skip to content

Commit

Permalink
rb_require narray on modshogun module load
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Sonnenburg committed Nov 23, 2011
1 parent fd6b20d commit ecdb955
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Makefile.template
Expand Up @@ -303,7 +303,7 @@ install-java_modular: $(TEMPLATE_TARGET)

install-ruby_modular: $(TEMPLATE_TARGET)
install -d -m755 "$(DESTDIR)/$(RUBY_EXTENSIONS_INSTALL_DIR)"
install -m755 modshogun.$(EXT_LIB) "$(DESTDIR)/$(RUBY_EXTENSIONS_INSTALL_DIR)/modshogun$(EXT_LIB_SWIG_RUBY_MODULAR)"
install -m755 modshogun$(EXT_LIB_SWIG_RUBY_MODULAR) "$(DESTDIR)/$(RUBY_EXTENSIONS_INSTALL_DIR)/"

install-lua_modular: $(TEMPLATE_TARGET)
install -d -m755 "$(DESTDIR)/$(LUA_EXTENSIONS_INSTALL_DIR)"
Expand Down Expand Up @@ -428,7 +428,7 @@ run-testsuite-ruby_modular:
check-examples-ruby_modular:
cd $(CONFIGPATH)/../examples/undocumented/ruby_modular && \
( $(LIBRARY_PATH)=$(DESTDIR)$(LIBDIR) \
RUBYLIB="$(DESTDIR)$(RUBY_EXTENSIONS_INSTALL_DIR):." ./check.sh )
RUBYLIB="$$RUBYLIB:$(DESTDIR)$(RUBY_EXTENSIONS_INSTALL_DIR):." ./check.sh )

lib/versionstring.h: $(GITHEAD)
sh $(CONFIGPATH)/.version.sh > $@
Expand Down
38 changes: 37 additions & 1 deletion src/interfaces/modular/SGBase.i
Expand Up @@ -78,6 +78,7 @@ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, jav
%{
#ifdef SWIGRUBY
extern "C" {
#include <ruby.h>
#include <narray.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down Expand Up @@ -140,15 +141,50 @@ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, jav
#endif

#ifdef SWIGRUBY
extern VALUE ruby_class;
rb_require("narray");
cNArray = rb_const_get(ruby_class, rb_intern("NArray"));

char* error=NULL;

void* handle = dlopen(NARRAY_LIB, RTLD_LAZY);
if (!handle) {
fprintf(stderr, "%s\n", dlerror());
exit(EXIT_FAILURE);
}

dlerror(); /* Clear any existing error */

*(void **) (&na_to_array_dl) = dlsym(handle, "na_to_array");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "na_to_array %s\n", error);
exit(EXIT_FAILURE);
}

/*if (cNArray==0)
{
void (*Init_narray)();
*(void **) (&Init_narray) = dlsym(handle, "Init_narray");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "Init_narray %s\n", error);
exit(EXIT_FAILURE);
}
fprintf(stderr, "initing narray\n");
(*Init_narray)();
}*/

*(void **) (&na_to_narray_dl) = dlsym(handle, "na_to_narray");
*(void **) (&cNArray) = dlsym(handle, "cNArray");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "na_to_narray %s\n", error);
exit(EXIT_FAILURE);
}

/* cNArray = (*(VALUE*)(dlsym(handle, "cNArray")));
if ((error = dlerror()) != NULL) {
fprintf(stderr, "cNArray %s\n", error);
exit(EXIT_FAILURE);
}*/
#endif
%}

Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/ruby_modular/swig_typemaps.i
Expand Up @@ -35,7 +35,7 @@
else {
if (NA_IsNArray($input)) {

VALUE v = na_to_array_dl($input);
VALUE v = (*na_to_array_dl)($input);
len = RARRAY_LEN(v);
array = SG_MALLOC(SGTYPE, len);

Expand All @@ -61,7 +61,7 @@

$1.free_vector();

$result = na_to_narray_dl(arr);
$result = (*na_to_narray_dl)(arr);
}

%enddef
Expand Down Expand Up @@ -98,7 +98,7 @@ TYPEMAP_SGVECTOR(float64_t, NUM2DBL, rb_float_new)

if (rb_obj_is_kind_of($input,rb_cArray) || NA_IsNArray($input)) {
if (NA_IsNArray($input)) {
v = na_to_array_dl($input);
v = (*na_to_array_dl)($input);
}
else {
v = $input;
Expand Down Expand Up @@ -145,7 +145,7 @@ TYPEMAP_SGVECTOR(float64_t, NUM2DBL, rb_float_new)

$1.free_matrix();

$result = na_to_narray_dl(arr);
$result = (*na_to_narray_dl)(arr);
}

%enddef
Expand Down

0 comments on commit ecdb955

Please sign in to comment.