Created
April 12, 2012 11:23
-
-
Save lomereiter/2366623 to your computer and use it in GitHub Desktop.
d & ruby: segfault
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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