Created
February 24, 2015 17:17
-
-
Save asterite/0d11102b0b1aa1b579d6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// cc -c foo.c -o foo.o | |
#include <stdlib.h> | |
void** global_data; | |
void foo_set(void* data) { | |
void** ptr = (void**)malloc(sizeof(data)); | |
*ptr = data; | |
global_data = ptr; | |
} | |
void* foo_get() { | |
return *global_data; | |
} |
This file contains hidden or 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
@[Link(ldflags: "#{__DIR__}/foo.o")] | |
lib LibFoo | |
fun set = foo_set(Void*) | |
fun get = foo_get : Void* | |
end | |
$exit = false | |
class Foo | |
getter name | |
def initialize(@name) | |
end | |
def finalize | |
unless @name.empty? | |
puts "exit" | |
$exit = true | |
end | |
end | |
end | |
def bar | |
foo = Foo.new("1") | |
puts foo.name | |
LibFoo.set(foo as Void*) | |
end | |
bar | |
until $exit | |
Foo.new("") | |
end | |
1000.times do | |
Foo.new("") | |
end | |
foo = LibFoo.get as Foo | |
puts foo.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment