Ruby: include/ruby/internal/newobj.h File Reference

Ruby 3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0)

Macros | Functions
newobj.h File Reference

Defines NEWOBJ. More...

`#include "ruby/internal/attr/deprecated.h"`
`#include "ruby/internal/cast.h"`
`#include "ruby/internal/core/rbasic.h"`
`#include "ruby/internal/dllexport.h"`
`#include "ruby/internal/fl_type.h"`
`#include "ruby/internal/special_consts.h"`
`#include "ruby/internal/value.h"`
`#include "ruby/assert.h"`

Go to the source code of this file.

## Macros
#define | RB_NEWOBJ(obj, type)
| Declares, allocates, then assigns a new object to the given variable.
#define | RB_NEWOBJ_OF(obj, type, klass, flags)
| Identical to RB_NEWOBJ, except it also accepts the allocating object's class and flags.
#define | NEWOBJ RB_NEWOBJ
| Old name of RB_NEWOBJ.
#define | NEWOBJ_OF RB_NEWOBJ_OF
| Old name of RB_NEWOBJ_OF.
#define | OBJSETUP rb_obj_setup
| Old name of rb_obj_setup.
#define | CLONESETUP rb_clone_setup
| Old name of rb_clone_setup.
#define | DUPSETUP rb_dup_setup
| Old name of rb_dup_setup.

## Functions
VALUE | rb_newobj (void)
| This is the implementation detail of RB_NEWOBJ.
VALUE | rb_newobj_of (VALUE klass, VALUE flags)
| This is the implementation detail of RB_NEWOBJ_OF.
VALUE | rb_obj_setup (VALUE obj, VALUE klass, VALUE type)
| Fills common fields in the object.
VALUE | rb_obj_class (VALUE obj)
| Queries the class of an object.
VALUE | rb_singleton_class_clone (VALUE obj)
| Clones a singleton class.
void | rb_singleton_class_attached (VALUE klass, VALUE obj)
| Attaches a singleton class to its corresponding object.
void | rb_copy_generic_ivar (VALUE clone, VALUE obj)
| Copies the list of instance variables.
static void | rb_clone_setup (VALUE clone, VALUE obj)
static void | rb_dup_setup (VALUE dup, VALUE obj)

## Detailed Description

Defines NEWOBJ.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Warning
  Symbols prefixed with either `RBIMPL` or `rbimpl` are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.

Note
  To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance `__VA_ARGS__` is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file newobj.h.

## Macro Definition Documentation

## ◆ RB_NEWOBJ

#define RB_NEWOBJ | ( |  | obj,
|  |  | type )

Value:
type *(obj) = RBIMPL_CAST((type *)rb_newobj())
rb_newobj
VALUE rb_newobj(void)
This is the implementation detail of RB_NEWOBJ.
Definition gc.c:2968

Declares, allocates, then assigns a new object to the given variable.

Parameters

  obj | Variable name.
  type | Variable type.

Exceptions

  rb_eNoMemError | No space left.

Returns
  An allocated object, not initialised.

Note
  Modern programs tend to use NEWOBJ_OF instead.

Definition at line 45 of file newobj.h.

## ◆ RB_NEWOBJ_OF

#define RB_NEWOBJ_OF | ( |  | obj,
|  |  | type,
|  |  | klass,
|  |  | flags )

Value:
type *(obj) = RBIMPL_CAST((type *)rb_newobj_of(klass, flags))
rb_newobj_of
VALUE rb_newobj_of(VALUE klass, VALUE flags)
This is the implementation detail of RB_NEWOBJ_OF.
Definition gc.c:3006

Identical to RB_NEWOBJ, except it also accepts the allocating object's class and flags.

Parameters

  obj | Variable name.
  type | Variable type.
  klass | Object's class.
  flags | Object's flags.

Exceptions

  rb_eNoMemError | No space left.

Returns
  An allocated object, filled with the arguments.

Definition at line 58 of file newobj.h.

## Function Documentation

## ◆ rb_clone_setup()

static void rb_clone_setup | ( | VALUE | clone,
|  | VALUE | obj )
| inlinestatic

Deprecated
  Not sure exactly when but at some time, the implementation of `Object#clone` stopped using this function. It remained untouched for a while, and then @shyouhei realised that they are no longer doing the same thing. It seems nobody seriously uses this function any longer. Let's just abandon it.

Parameters

  [out] | clone | The destination object.
  [in] | obj | The source object.

Definition at line 173 of file newobj.h.

## ◆ rb_copy_generic_ivar()

void rb_copy_generic_ivar | ( | VALUE | clone,
|  | VALUE | obj )

Copies the list of instance variables.

3rd parties need not know, but there are several ways to store an object's instance variables, depending on its internal structure. This function makes sense when either of the passed objects are using so-called "generic" backend storage. This distinction is purely an implementation detail of rb_clone_setup(). People need not be aware of this working behind-the-scenes.

Parameters

  [out] | clone | The destination object.
  [in] | obj | The source object.

Definition at line 2031 of file variable.c.

Referenced by rb_copy_generic_ivar(), and rb_hash_dup().

## ◆ rb_dup_setup()

static void rb_dup_setup | ( | VALUE | dup,
|  | VALUE | obj )
| inlinestatic

Deprecated
  Not sure exactly when but at some time, the implementation of `Object#dup` stopped using this function. It remained untouched for a while, and then @shyouhei realised that they are no longer the same thing. It seems nobody seriously uses this function any longer. Let's just abandon it.

Parameters

  [out] | dup | The destination object.
  [in] | obj | The source object.

Definition at line 192 of file newobj.h.

## ◆ rb_newobj()

VALUE rb_newobj | ( | void |  | ) |

This is the implementation detail of RB_NEWOBJ.

Exceptions

  rb_eNoMemError | No space left.

Returns
  An allocated object, not initialised.

Definition at line 2968 of file gc.c.

## ◆ rb_newobj_of()

VALUE rb_newobj_of | ( | VALUE | klass,
|  | VALUE | flags )

This is the implementation detail of RB_NEWOBJ_OF.

Parameters

  klass | Object's class.
  flags | Object's flags.

Exceptions

  rb_eNoMemError | No space left.

Returns
  An allocated object, filled with the arguments.

Definition at line 3006 of file gc.c.