Ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e0ba6b95ab71a441357ed5484e33498)
|
Defines struct RArray. More...
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/attr/maybe_unused.h"
#include "ruby/internal/attr/pure.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/rgengc.h"
#include "ruby/internal/stdbool.h"
#include "ruby/internal/value.h"
#include "ruby/internal/value_type.h"
#include "ruby/assert.h"
Go to the source code of this file.
Data Structures | |
struct | RArray |
Ruby's array. More... | |
Macros | |
#define | USE_TRANSIENT_HEAP 1 |
#define | RARRAY(obj) RBIMPL_CAST((struct RArray *)(obj)) |
Convenient casting macro. More... | |
#define | RARRAY_LEN rb_array_len |
Just another name of rb_array_len. More... | |
#define | RARRAY_CONST_PTR rb_array_const_ptr |
Just another name of rb_array_const_ptr. More... | |
#define | RARRAY_CONST_PTR_TRANSIENT rb_array_const_ptr_transient |
Just another name of rb_array_const_ptr_transient. More... | |
#define | RBIMPL_RARRAY_STMT(flag, ary, var, expr) |
This is an implementation detail of RARRAY_PTR_USE. More... | |
#define | RARRAY_PTR_USE_START(a) rb_array_ptr_use_start(a, 0) |
This is an implementation detail of RARRAY_PTR_USE. More... | |
#define | RARRAY_PTR_USE_END(a) rb_array_ptr_use_end(a, 0) |
This is an implementation detail of RARRAY_PTR_USE. More... | |
#define | RARRAY_PTR_USE(ary, ptr_name, expr) RBIMPL_RARRAY_STMT(0, ary, ptr_name, expr) |
Declares a section of code where raw pointers are used. More... | |
#define | RARRAY_PTR_USE_START_TRANSIENT(a) rb_array_ptr_use_start(a, 1) |
This is an implementation detail of RARRAY_PTR_USE_TRANSIENT. More... | |
#define | RARRAY_PTR_USE_END_TRANSIENT(a) rb_array_ptr_use_end(a, 1) |
This is an implementation detail of RARRAY_PTR_USE_TRANSIENT. More... | |
#define | RARRAY_PTR_USE_TRANSIENT(ary, ptr_name, expr) RBIMPL_RARRAY_STMT(1, ary, ptr_name, expr) |
Identical to RARRAY_PTR_USE, except the pointer can be a transient one. More... | |
#define | RARRAY_AREF(a, i) RARRAY_CONST_PTR_TRANSIENT(a)[i] |
Enumerations | |
enum | ruby_rarray_consts { RARRAY_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 3 , RARRAY_EMBED_LEN_MAX = ((int)(sizeof(VALUE[3]) / (sizeof(VALUE)))) , RARRAY_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 3 , RARRAY_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE) } |
This is an enum because GDB wants it (rather than a macro). More... | |
Functions | |
void | rb_ary_detransient (VALUE a) |
Destructively converts an array of transient backend into ordinal one. More... | |
static long | RARRAY_EMBED_LEN (VALUE ary) |
Queries the length of the array. More... | |
static long | rb_array_len (VALUE a) |
Queries the length of the array. More... | |
static int | RARRAY_LENINT (VALUE ary) |
Identical to rb_array_len(), except it differs for the return type. More... | |
static bool | RARRAY_TRANSIENT_P (VALUE ary) |
Queries if the array is a transient array. More... | |
static VALUE * | RARRAY_PTR (VALUE ary) |
Wild use of a C pointer. More... | |
static void | RARRAY_ASET (VALUE ary, long i, VALUE v) |
Assigns an object in an array. More... | |
Defines struct RArray.
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. __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 rarray.h.
#define RARRAY | ( | obj | ) | RBIMPL_CAST((struct RArray *)(obj)) |
#define RARRAY_AREF | ( | a, | |
i | |||
) | RARRAY_CONST_PTR_TRANSIENT(a)[i] |
:FIXME: we want to convert RARRAY_AREF into an inline function (to add rooms for more sanity checks). However there were situations where the address of this macro is taken i.e. &RARRAY_AREF(...). They cannot be possible if this is not a macro. Such usages are abuse, and we eliminated them internally. However we are afraid of similar things to remain in the wild. This macro remains as it is due to that. If we could warn such usages we can set a transition path, but currently no way is found to do so.
#define RARRAY_CONST_PTR rb_array_const_ptr |
#define RARRAY_CONST_PTR_TRANSIENT rb_array_const_ptr_transient |
#define RARRAY_LEN rb_array_len |
Just another name of rb_array_len.
#define RARRAY_PTR_USE | ( | ary, | |
ptr_name, | |||
expr | |||
) | RBIMPL_RARRAY_STMT(0, ary, ptr_name, expr) |
Declares a section of code where raw pointers are used.
In case you need to touch the raw C array instead of polite CAPIs, then that operation shall be wrapped using this macro.
ary | An object of RArray. |
ptr_name | A variable name which points the C array in expr . |
expr | The expression that touches ptr_name . |
#define RARRAY_PTR_USE_END | ( | a | ) | rb_array_ptr_use_end(a, 0) |
This is an implementation detail of RARRAY_PTR_USE.
People do not use it directly.
#define RARRAY_PTR_USE_END_TRANSIENT | ( | a | ) | rb_array_ptr_use_end(a, 1) |
This is an implementation detail of RARRAY_PTR_USE_TRANSIENT.
People do not use it directly.
#define RARRAY_PTR_USE_START | ( | a | ) | rb_array_ptr_use_start(a, 0) |
This is an implementation detail of RARRAY_PTR_USE.
People do not use it directly.
#define RARRAY_PTR_USE_START_TRANSIENT | ( | a | ) | rb_array_ptr_use_start(a, 1) |
This is an implementation detail of RARRAY_PTR_USE_TRANSIENT.
People do not use it directly.
#define RARRAY_PTR_USE_TRANSIENT | ( | ary, | |
ptr_name, | |||
expr | |||
) | RBIMPL_RARRAY_STMT(1, ary, ptr_name, expr) |
Identical to RARRAY_PTR_USE, except the pointer can be a transient one.
ary | An object of RArray. |
ptr_name | A variable name which points the C array in expr . |
expr | The expression that touches ptr_name . |
#define RBIMPL_RARRAY_STMT | ( | flag, | |
ary, | |||
var, | |||
expr | |||
) |
This is an implementation detail of RARRAY_PTR_USE.
People do not use it directly.
#define USE_TRANSIENT_HEAP 1 |
enum ruby_rarray_consts |
Assigns an object in an array.
[out] | ary | Destination array object. |
[in] | i | Index of ary . |
[in] | v | Arbitrary ruby object. |
ary
must be an instance of RArray. ary
's length must be longer than or equal to i
. i
must be greater than or equal to zero. ary
's i
th element is set to v
.
|
inlinestatic |
|
inlinestatic |
Identical to rb_array_len(), except it differs for the return type.
[in] | ary | Array in question. |
rb_eRangeError | Too long. |
ary
must be an instance of RArray. Definition at line 324 of file rarray.h.
Referenced by rb_apply(), rb_eval_cmd_kw(), and rb_struct_initialize().
Wild use of a C pointer.
This function accesses the backend storage directly. This is slower than RARRAY_PTR_USE_TRANSIENT. It exercises extra manoeuvres to protect our generational GC. Use of this function is considered archaic. Use a modern way instead.
[in] | ary | An object of RArray. |
Definition at line 551 of file rarray.h.
Referenced by rb_struct_new().
|
inlinestatic |
Queries if the array is a transient array.
[in] | ary | Array in question. |
true | Yes it is. |
false | No it isn't. |
ary
must be an instance of RArray. Definition at line 345 of file rarray.h.
Referenced by rb_ary_detransient(), and rb_ary_free().
|
inlinestatic |