Skip to main content

Module macros

Module macros 

Source
Expand description

Implementation of Ruby macros.

Since macros are rely on the C preprocessor, or defined as inline C functions, they are not available when linking libruby. In order to use the libruby macros from Rust, rb-sys implements them using the following strategies:

  1. For stable versions of Ruby, the macros are implemented as Rust functions
  2. For ruby-head, the macros are implemented as C functions that are linked into the crate.

Functions§

DATA_PTR
Get data pointer from RData/TypedData object (akin to DATA_PTR).
DBL2NUM
Convert C double to Ruby Float VALUE (akin to DBL2NUM).
ENCODING_GET
Get encoding index from object (akin to ENCODING_GET).
FIX2LONG
Convert Fixnum to long (akin to FIX2LONG).
FIX2ULONG
Convert Fixnum to unsigned long (akin to FIX2ULONG).
FIXABLE
Check if long value can be represented as Fixnum (akin to FIXABLE).
FIXNUM_P
Checks if the given object is a so-called Fixnum.
FLONUM_P
Checks if the given object is a so-called Flonum.
FL_ABLE
Check if an object can have flags (akin to RB_FL_ABLE).
ID2SYM
Convert ID to Symbol (akin to ID2SYM or RB_ID2SYM).
IMMEDIATE_P
Checks if the given object is an immediate i.e. an object which has no corresponding storage inside of the object space.
LONG2FIX
Convert long to Fixnum (akin to LONG2FIX).
LONG2NUM
Convert long to Ruby Integer (akin to LONG2NUM).
NIL_P
Checks if the given object is nil.
NUM2DBL
Convert Ruby numeric to C double (akin to NUM2DBL).
NUM2LONG
Convert Ruby Integer to long (akin to NUM2LONG).
NUM2ULONG
Convert Ruby Integer to unsigned long (akin to NUM2ULONG).
POSFIXABLE
Check if unsigned long value can be represented as positive Fixnum (akin to POSFIXABLE).
RARRAY_AREF
Read array element at index (akin to RARRAY_AREF).
RARRAY_ASET
Write array element at index (akin to RARRAY_ASET).
RARRAY_CONST_PTR
Get the backend storage of a Ruby array.
RARRAY_LEN
Get the length of a Ruby array.
RBIGNUM_NEGATIVE_P
Checks if the bignum is negative.
RBIGNUM_POSITIVE_P
Checks if the bignum is positive.
RB_BUILTIN_TYPE
Queries the type of the object.
RB_DYNAMIC_SYM_P
Queries if the object is a dynamic symbol.
RB_FLOAT_TYPE_P
Queries if the object is an instance of ::rb_cFloat.
RB_ID2SYM
Alias for ID2SYM for compatibility with Ruby naming conventions.
RB_INTEGER_TYPE_P
Queries if the object is an instance of ::rb_cInteger.
RB_OBJ_FREEZE
Freeze an object (akin to RB_OBJ_FREEZE).
RB_OBJ_PROMOTED
Check if object is promoted to old GC generation (akin to RB_OBJ_PROMOTED).
RB_OBJ_PROMOTED_RAW
Raw version assuming FL_ABLE (akin to RB_OBJ_PROMOTED_RAW).
RB_OBJ_WRITE
Execute GC write barrier when storing a reference (akin to RB_OBJ_WRITE).
RB_OBJ_WRITTEN
Declare a write barrier without actually writing (akin to RB_OBJ_WRITTEN).
RB_SYM2ID
Alias for SYM2ID for compatibility with Ruby naming conventions.
RB_SYMBOL_P
Queries if the object is an instance of ::rb_cSymbol.
RB_TYPE
Identical to RB_BUILTIN_TYPE(), except it can also accept special constants.
RB_TYPE_P
Queries if the given object is of given type.
RHASH_EMPTY_P
Check if hash is empty (akin to RHASH_EMPTY_P).
RHASH_SIZE
Get hash size (akin to RHASH_SIZE).
RSTRING_END
Get pointer to end of string contents (akin to RSTRING_END).
RSTRING_LEN
Get the length of a Ruby string.
RSTRING_PTR
Get the backend storage of a Ruby string.
RTYPEDDATA_GET_DATA
Gets the data pointer from an RTypedData object.
RTYPEDDATA_P
Checks if the given object is an RTypedData.
RTYPEDDATA_TYPE
Gets the data type information from an RTypedData object.
SPECIAL_CONST_P
Checks if the given object is of enum ::ruby_special_consts.
STATIC_SYM_P
Checks if the given object is a static symbol.
SYM2ID
Convert Symbol to ID (akin to SYM2ID or RB_SYM2ID).
TEST
Emulates Ruby’s “if” statement.
ULONG2NUM
Convert unsigned long to Ruby Integer (akin to ULONG2NUM).