Skip to content

Instantly share code, notes, and snippets.

@lomereiter
Created April 12, 2012 11:23
Show Gist options
  • Save lomereiter/2366623 to your computer and use it in GitHub Desktop.
Save lomereiter/2366623 to your computer and use it in GitHub Desktop.
d & ruby: segfault
test: test_c.o test_d.o
gcc -m32 -g test_d.o test_c.o -o test.so -lphobos2 -lrt -shared -lpthread
test_c.o: test.c
gcc -c -g -m32 test.c -o test_c.o -fPIC
test_d.o: test.d
dmd -c -m32 -g test.d -oftest_d.o -fPIC
extern void attach(void);
extern void detach(void);
void __attach(void) __attribute__((constructor));
void __detach(void) __attribute__((destructor));
void __attach(void) { attach(); }
void __detach(void) { detach(); }
module test;
import core.runtime : Runtime;
extern (C) export void attach() { Runtime.initialize(); }
extern (C) export void detach() { Runtime.terminate(); }
import std.array : array;
import std.algorithm : splitter;
extern (C) void foo() {
array(splitter("abc", ' '));
}
void main() {}
#!/usr/bin/env ruby
require 'ffi'
module Bar
extend FFI::Library
ffi_lib './test.so'
attach_function :foo, [], :void
end
Bar.foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment