Skip to content

Commit 2371319

Browse files
committed
Add spec for memsize of typed data struct.
1 parent 3e8f3b2 commit 2371319

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

spec/ruby/optional/capi/ext/typed_data_spec.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ void sample_typed_wrapped_struct_mark(void* st) {
4343
}
4444

4545
size_t sample_typed_wrapped_struct_memsize(const void* st) {
46-
return sizeof(struct sample_typed_wrapped_struct);
46+
if (st == NULL) {
47+
return 0;
48+
} else {
49+
return ((struct sample_typed_wrapped_struct *)st)->foo;
50+
}
4751
}
4852

4953
static const rb_data_type_t sample_typed_wrapped_struct_data_type = {

spec/ruby/optional/capi/typed_data_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative 'spec_helper'
2+
require 'objspace'
23

34
load_extension("typed_data")
45

@@ -7,6 +8,11 @@
78
@s = CApiAllocTypedSpecs.new
89
@s.typed_wrapped_data.should == 42 # not defined in initialize
910
end
11+
12+
it "uses the specified memsize function for ObjectSpace.memsize" do
13+
@s = CApiAllocTypedSpecs.new
14+
ObjectSpace.memsize_of(@s).should > 42
15+
end
1016
end
1117

1218
describe "CApiWrappedTypedStruct" do

0 commit comments

Comments
 (0)