Ruby
3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
|
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/gc.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 | 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 | RBIMPL_RARRAY_STMT(ary, var, expr) |
This is an implementation detail of RARRAY_PTR_USE. More... | |
#define | RARRAY_PTR_USE(ary, ptr_name, expr) RBIMPL_RARRAY_STMT(ary, ptr_name, expr) |
Declares a section of code where raw pointers are used. More... | |
#define | RARRAY_AREF(a, i) RARRAY_CONST_PTR(a)[i] |
Enumerations | |
enum | ruby_rarray_consts { RARRAY_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 3 } |
This is an enum because GDB wants it (rather than a macro). More... | |
Functions | |
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 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(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_LEN rb_array_len |
Just another name of rb_array_len.
#define RARRAY_PTR_USE | ( | ary, | |
ptr_name, | |||
expr | |||
) | RBIMPL_RARRAY_STMT(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 RBIMPL_RARRAY_STMT | ( | ary, | |
var, | |||
expr | |||
) |
This is an implementation detail of RARRAY_PTR_USE.
People do not use it directly.
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 281 of file rarray.h.
Referenced by rb_apply(), rb_eval_cmd_kw(), rb_struct_alloc(), rb_struct_initialize(), rb_yield_splat(), and rb_yield_splat_kw().
Wild use of a C pointer.
This function accesses the backend storage directly. This is slower than RARRAY_PTR_USE. 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 366 of file rarray.h.
Referenced by rb_struct_new().