Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
newobj.h
Go to the documentation of this file.
1#ifndef RBIMPL_NEWOBJ_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_NEWOBJ_H
23#include "ruby/internal/cast.h"
28#include "ruby/internal/value.h"
29#include "ruby/assert.h"
30
31#define RB_NEWOBJ(obj,type) type *(obj) = RBIMPL_CAST((type *)rb_newobj())
32#define RB_NEWOBJ_OF(obj,type,klass,flags) type *(obj) = RBIMPL_CAST((type *)rb_newobj_of(klass, flags))
33
34#define NEWOBJ RB_NEWOBJ
35#define NEWOBJ_OF RB_NEWOBJ_OF /* core has special NEWOBJ_OF() in internal.h */
36#define OBJSETUP rb_obj_setup /* use NEWOBJ_OF instead of NEWOBJ()+OBJSETUP() */
37#define CLONESETUP rb_clone_setup
38#define DUPSETUP rb_dup_setup
39
41VALUE rb_newobj(void);
43VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type);
49
50static inline void
51rb_clone_setup(VALUE clone, VALUE obj)
52{
53 RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj));
54 RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(clone));
55
58 RB_FL_TEST_RAW(obj, ~flags));
60 if (RB_FL_TEST(obj, RUBY_FL_EXIVAR)) rb_copy_generic_ivar(clone, obj);
61}
62
63static inline void
64rb_dup_setup(VALUE dup, VALUE obj)
65{
66 RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj));
67 RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(dup));
68
69 rb_obj_setup(dup, rb_obj_class(obj), RB_FL_TEST_RAW(obj, RUBY_FL_DUPPED));
70 if (RB_FL_TEST(obj, RUBY_FL_EXIVAR)) rb_copy_generic_ivar(dup, obj);
71}
72
73#endif /* RBIMPL_NEWOBJ_H */
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition: assert.h:229
Defines RBIMPL_CAST.
Tewaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:86
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:77
Defines enum ruby_fl_type.
@ RUBY_FL_DUPPED
Definition: fl_type.h:207
@ RUBY_FL_PROMOTED1
Definition: fl_type.h:165
@ RUBY_FL_PROMOTED0
Definition: fl_type.h:164
@ RUBY_FL_EXIVAR
Definition: fl_type.h:172
@ RUBY_FL_FINALIZE
Definition: fl_type.h:167
VALUE rb_singleton_class_clone(VALUE)
Definition: class.c:459
void rb_singleton_class_attached(VALUE, VALUE)
Attach a object to a singleton class.
Definition: class.c:530
VALUE rb_obj_class(VALUE)
Definition: object.c:245
VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type)
Fills common (RBasic) fields in obj.
Definition: object.c:126
void rb_copy_generic_ivar(VALUE, VALUE)
Definition: variable.c:1638
VALUE rb_newobj(void)
Definition: gc.c:2365
VALUE rb_newobj_of(VALUE, VALUE)
Definition: gc.c:2371
Defines struct RBasic.
#define RBASIC_CLASS
Definition: rbasic.h:35
Defines enum ruby_special_consts.
Defines VALUE and ID.
unsigned long VALUE
Definition: value.h:38