Skip to content

Commit

Permalink
kill CLONESETUP and DUPSETUP
Browse files Browse the repository at this point in the history
They are no longer how Object#clone/Object#dup are defined.  In fact
DUPSETUP is not used from anywhere.  CLONESETUP has only one usage.
Let's not expose them to extension libraries.

cf #4100 (comment)
  • Loading branch information
shyouhei committed Jan 27, 2021
1 parent 73e948a commit f8a117f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
14 changes: 13 additions & 1 deletion include/ruby/internal/fl_type.h
Expand Up @@ -227,7 +227,19 @@ ruby_fl_type {
RUBY_FL_SINGLETON = RUBY_FL_USER0,
};

enum { RUBY_FL_DUPPED = RUBY_T_MASK | RUBY_FL_EXIVAR | RUBY_FL_SHAREABLE };
enum {
RUBY_FL_DUPPED

#if RBIMPL_HAS_EXTENSION(enumerator_attributes)
RBIMPL_ATTR_DEPRECATED(("It seems there is no actual usage of this enum."))
#elif RBIMPL_COMPILER_SINCE(GCC, 6, 0, 0)
RBIMPL_ATTR_DEPRECATED(("It seems there is no actual usage of this enum."))
#elif defined(_MSC_VER)
# pragma deprecated(RUBY_FL_UNTRUSTED)
#endif

= RUBY_T_MASK | RUBY_FL_EXIVAR
};

RBIMPL_SYMBOL_EXPORT_BEGIN()
void rb_obj_infect(VALUE victim, VALUE carrier);
Expand Down
18 changes: 5 additions & 13 deletions include/ruby/internal/newobj.h
Expand Up @@ -20,6 +20,7 @@
* extension libraries. They could be written in C++98.
* @brief Defines #NEWOBJ.
*/
#include "ruby/internal/attr/deprecated.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/dllexport.h"
Expand Down Expand Up @@ -47,27 +48,18 @@ void rb_singleton_class_attached(VALUE,VALUE);
void rb_copy_generic_ivar(VALUE,VALUE);
RBIMPL_SYMBOL_EXPORT_END()

RBIMPL_ATTR_DEPRECATED(("This is no longer how Object#clone works."))
static inline void
rb_clone_setup(VALUE clone, VALUE obj)
{
RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj));
RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(clone));

const VALUE flags = RUBY_FL_PROMOTED0 | RUBY_FL_PROMOTED1 | RUBY_FL_FINALIZE;
rb_obj_setup(clone, rb_singleton_class_clone(obj),
RB_FL_TEST_RAW(obj, ~flags));
rb_singleton_class_attached(RBASIC_CLASS(clone), clone);
if (RB_FL_TEST(obj, RUBY_FL_EXIVAR)) rb_copy_generic_ivar(clone, obj);
return;
}

RBIMPL_ATTR_DEPRECATED(("This is no longer how Object#dup works."))
static inline void
rb_dup_setup(VALUE dup, VALUE obj)
{
RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj));
RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(dup));

rb_obj_setup(dup, rb_obj_class(obj), RB_FL_TEST_RAW(obj, RUBY_FL_DUPPED));
if (RB_FL_TEST(obj, RUBY_FL_EXIVAR)) rb_copy_generic_ivar(dup, obj);
return;
}

#endif /* RBIMPL_NEWOBJ_H */
17 changes: 17 additions & 0 deletions proc.c
Expand Up @@ -56,6 +56,23 @@ static VALUE proc_binding(VALUE self);

#define IS_METHOD_PROC_IFUNC(ifunc) ((ifunc)->func == bmcall)

/* :FIXME: The way procs are cloned has been historically different from the
* way everything else are. @shyouhei is not sure for the intention though.
*/
#undef CLONESETUP
static inline void
CLONESETUP(VALUE clone, VALUE obj)
{
RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj));
RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(clone));

const VALUE flags = RUBY_FL_PROMOTED0 | RUBY_FL_PROMOTED1 | RUBY_FL_FINALIZE;
rb_obj_setup(clone, rb_singleton_class_clone(obj),
RB_FL_TEST_RAW(obj, ~flags));
rb_singleton_class_attached(RBASIC_CLASS(clone), clone);
if (RB_FL_TEST(obj, RUBY_FL_EXIVAR)) rb_copy_generic_ivar(clone, obj);
}

static void
block_mark(const struct rb_block *block)
{
Expand Down

0 comments on commit f8a117f

Please sign in to comment.