Search
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby
All Projects
Ruby
Overview
Activity
Roadmap
Issues
Repository
Like
Download (653 Bytes)
Bug #17023
» string-relocate.rb
larskanis (Lars Kanis)
, 07/10/2020 05:27 PM
File
.
write
"string-relocate.c"
,
<<-
EOC
static char *g_str;
void set(char* str) {
g_str = str;
}
char* get() {
return g_str;
}
EOC
system
"gcc -shared -fPIC string-relocate.c -o string-relocate.so"
require
'ffi'
class
Foo
extend
FFI
::
Library
ffi_lib
File
.
expand_path
(
'string-relocate.so'
)
attach_function
:set
,
[
:string
],
:void
attach_function
:get
,
[],
:string
def
initialize
(
count
)
proc
{}
# necessary to trigger relocation
a
=
"a"
*
count
set
(
a
)
GC
.
verify_compaction_references
(
toward: :empty
,
double_heap:
true
)
puts
"get(
#{
count
}
):
#{
get
}
(should be:
#{
a
}
)"
end
end
Foo
.
new
(
23
)
Foo
.
new
(
24
)
« Previous
1
2
Next »
(1-1/2)
Loading...