Skip to content

Commit

Permalink
[Feature #20265] Remove rb_newobj_of and RB_NEWOBJ_OF
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Feb 14, 2024
1 parent 3026e73 commit 6e721be
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 46 deletions.
11 changes: 0 additions & 11 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2994,17 +2994,6 @@ rb_class_instance_allocate_internal(VALUE klass, VALUE flags, bool wb_protected)
return obj;
}

VALUE
rb_newobj_of(VALUE klass, VALUE flags)
{
if ((flags & RUBY_T_MASK) == T_OBJECT) {
return rb_class_instance_allocate_internal(klass, (flags | ROBJECT_EMBED) & ~FL_WB_PROTECTED, flags & FL_WB_PROTECTED);
}
else {
return newobj_of(GET_RACTOR(), klass, flags & ~FL_WB_PROTECTED, 0, 0, 0, flags & FL_WB_PROTECTED, RVALUE_SIZE);
}
}

#define UNEXPECTED_NODE(func) \
rb_bug(#func"(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE, \
BUILTIN_TYPE(obj), (void*)(obj), RBASIC(obj)->flags)
Expand Down
25 changes: 0 additions & 25 deletions include/ruby/internal/newobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,11 @@
#include "ruby/internal/value.h"
#include "ruby/assert.h"

/**
* Identical to #RB_NEWOBJ, except it also accepts the allocating object's
* class and flags.
*
* @param obj Variable name.
* @param type Variable type.
* @param klass Object's class.
* @param flags Object's flags.
* @exception rb_eNoMemError No space left.
* @return An allocated object, filled with the arguments.
*/
#define RB_NEWOBJ_OF(obj,type,klass,flags) type *(obj) = RBIMPL_CAST((type *)rb_newobj_of(klass, flags))

#define NEWOBJ_OF RB_NEWOBJ_OF /**< @old{RB_NEWOBJ_OF} */
#define OBJSETUP rb_obj_setup /**< @old{rb_obj_setup} */
#define CLONESETUP rb_clone_setup /**< @old{rb_clone_setup} */
#define DUPSETUP rb_dup_setup /**< @old{rb_dup_setup} */

RBIMPL_SYMBOL_EXPORT_BEGIN()

/**
* This is the implementation detail of #RB_NEWOBJ_OF.
*
* @param klass Object's class.
* @param flags Object's flags.
* @exception rb_eNoMemError No space left.
* @return An allocated object, filled with the arguments.
*/
VALUE rb_newobj_of(VALUE klass, VALUE flags);

/**
* Fills common fields in the object.
*
Expand Down
12 changes: 2 additions & 10 deletions spec/ruby/optional/capi/ext/object_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,16 +388,8 @@ static VALUE object_spec_rb_ivar_foreach(VALUE self, VALUE obj) {
}

static VALUE speced_allocator(VALUE klass) {
VALUE flags = 0;
VALUE instance;
if (RTEST(rb_class_inherited_p(klass, rb_cString))) {
flags = T_STRING;
} else if (RTEST(rb_class_inherited_p(klass, rb_cArray))) {
flags = T_ARRAY;
} else {
flags = T_OBJECT;
}
instance = rb_newobj_of(klass, flags);
VALUE super = rb_class_get_superclass(klass);
VALUE instance = rb_get_alloc_func(super)(klass);
rb_iv_set(instance, "@from_custom_allocator", Qtrue);
return instance;
}
Expand Down

0 comments on commit 6e721be

Please sign in to comment.