Skip to content

Commit 07b77f7

Browse files
committed
Add a new spec for native extensions that redefine frozen?.
1 parent a227095 commit 07b77f7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,16 @@ static VALUE object_spec_custom_alloc_func_p(VALUE self, VALUE klass) {
383383
return allocator ? Qtrue : Qfalse;
384384
}
385385

386+
static VALUE object_spec_redefine_frozen(VALUE self) {
387+
// The purpose of this spec is to verify that `frozen?`
388+
// and `RB_OBJ_FROZEN` do not mutually recurse infinitely.
389+
if (RB_OBJ_FROZEN(self)) {
390+
return Qtrue;
391+
}
392+
393+
return Qfalse;
394+
}
395+
386396
void Init_object_spec(void) {
387397
VALUE cls = rb_define_class("CApiObjectSpecs", rb_cObject);
388398
rb_define_method(cls, "FL_ABLE", object_spec_FL_ABLE, 1);
@@ -455,6 +465,9 @@ void Init_object_spec(void) {
455465
rb_define_method(cls, "custom_alloc_func?", object_spec_custom_alloc_func_p, 1);
456466
rb_define_method(cls, "not_implemented_method", rb_f_notimplement, -1);
457467
rb_define_method(cls, "rb_ivar_foreach", object_spec_rb_ivar_foreach, 1);
468+
469+
cls = rb_define_class("CApiObjectRedefinitionSpecs", rb_cObject);
470+
rb_define_method(cls, "frozen?", object_spec_redefine_frozen, 0);
458471
}
459472

460473
#ifdef __cplusplus

spec/ruby/optional/capi/object_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,16 @@ def reach
691691
end
692692
end
693693

694+
describe "redefining frozen? works" do
695+
it "allows an object to override frozen?" do
696+
obj = CApiObjectRedefinitionSpecs.new
697+
698+
obj.frozen?.should == false
699+
obj.freeze
700+
obj.frozen?.should == true
701+
end
702+
end
703+
694704
describe "rb_obj_taint" do
695705
end
696706

0 commit comments

Comments
 (0)