1 #ifndef RBIMPL_RSTRING_H
2 #define RBIMPL_RSTRING_H
23 #include "ruby/internal/config.h"
27 #include "ruby/internal/cast.h"
41 #define RSTRING(obj) RBIMPL_CAST((struct RString *)(obj))
44 #define RSTRING_NOEMBED RSTRING_NOEMBED
45 #define RSTRING_FSTR RSTRING_FSTR
46 #define RSTRING_LEN RSTRING_LEN
47 #define RSTRING_LENINT RSTRING_LENINT
48 #define RSTRING_PTR RSTRING_PTR
49 #define RSTRING_END RSTRING_END
66 #define StringValue(v) rb_string_value(&(v))
76 #define StringValuePtr(v) rb_string_value_ptr(&(v))
89 #define StringValueCStr(v) rb_string_value_cstr(&(v))
98 #define SafeStringValue(v) StringValue(v)
117 #define ExportStringValue(v) do { \
119 (v) = rb_str_export(v); \
137 enum ruby_rstring_flags {
335 void rb_check_safe_str(
VALUE);
344 #define Check_SafeStr(v) rb_check_safe_str(RBIMPL_CAST((VALUE)(v)))
354 void rb_debug_rstring_null_ptr(
const char *func);
373 #if RBIMPL_COMPILER_IS(Intel)
389 rbimpl_rstring_getmem(
VALUE str)
400 retval.as.heap.ptr =
RSTRING(str)->as.embed.ary;
418 char *
ptr = rbimpl_rstring_getmem(str).
as.
heap.ptr;
427 rb_debug_rstring_null_ptr(
"RSTRING_PTR");
444 struct RString buf = rbimpl_rstring_getmem(str);
448 rb_debug_rstring_null_ptr(
"RSTRING_END");
480 #ifdef HAVE_STMT_AND_DECL_IN_EXPR
481 # define RSTRING_GETMEM(str, ptrvar, lenvar) \
483 struct RString rbimpl_str = rbimpl_rstring_getmem(str); \
484 (ptrvar) = rbimpl_str.as.heap.ptr; \
485 (lenvar) = rbimpl_str.len; \
488 # define RSTRING_GETMEM(str, ptrvar, lenvar) \
489 ((ptrvar) = RSTRING_PTR(str), \
490 (lenvar) = RSTRING_LEN(str))
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
#define RUBY_DEBUG
Define this macro when you want assertions.
#define RB_UNLIKELY(x)
Asserts that the given Boolean expression likely doesn't hold.
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Defines enum ruby_fl_type.
static bool RB_FL_ANY_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_ANY().
@ RUBY_FL_USER17
User-defined flag.
@ RUBY_FL_USER1
User-defined flag.
#define RBIMPL_ATTR_ERROR(msg)
Wraps (or simulates) __attribute__((error))
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
Arithmetic conversion between C's long and Ruby's.
#define rb_long2int
Just another name of rb_long2int_inline.
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Defines RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
#define StringValue(v)
Ensures that the parameter object is a String.
VALUE rb_str_export_locale(VALUE obj)
Identical to rb_str_export(), except it converts into the locale encoding instead.
static char * RSTRING_END(VALUE str)
Queries the end of the contents pointer of the string.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
static int RSTRING_LENINT(VALUE str)
Identical to RSTRING_LEN(), except it differs for the return type.
char * rb_string_value_ptr(volatile VALUE *ptr)
Identical to rb_str_to_str(), except it returns the converted string's backend memory region.
char * rb_string_value_cstr(volatile VALUE *ptr)
Identical to rb_string_value_ptr(), except it additionally checks for the contents for viability as a...
VALUE rb_string_value(volatile VALUE *ptr)
Identical to rb_str_to_str(), except it fills the passed pointer with the converted object.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
#define RSTRING(obj)
Convenient casting macro.
VALUE rb_str_export(VALUE obj)
Identical to rb_str_to_str(), except it additionally converts the string into default external encodi...
VALUE rb_str_to_str(VALUE obj)
Identical to rb_check_string_type(), except it raises exceptions in case of conversion failures.
Ruby object's base components.
struct RBasic basic
Basic part, including flags and class.
union RString::@48::@49::@51 aux
Auxiliary info.
long capa
Capacity of *ptr.
union RString::@48 as
String's specific fields.
long len
Length of the string, not including terminating NUL character.
struct RString::@48::@50 embed
Embedded contents.
struct RString::@48::@49 heap
Strings that use separated memory region for contents use this pattern.
VALUE shared
Parent of the string.
char * ptr
Pointer to the contents of the string.
uintptr_t VALUE
Type that represents a Ruby object.
Defines enum ruby_value_type.
Defines RBIMPL_WARNING_PUSH.
#define RBIMPL_WARNING_IGNORED(flag)
Suppresses a warning.
#define RBIMPL_WARNING_PUSH()
Pushes compiler warning state.
#define RBIMPL_WARNING_POP()
Pops compiler warning state.