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
46#define RSTRING_EMBED_LEN_MASK RSTRING_EMBED_LEN_MASK
47#define RSTRING_EMBED_LEN_SHIFT RSTRING_EMBED_LEN_SHIFT
48#define RSTRING_EMBED_LEN_MAX RSTRING_EMBED_LEN_MAX
50#define RSTRING_FSTR RSTRING_FSTR
51#define RSTRING_EMBED_LEN RSTRING_EMBED_LEN
52#define RSTRING_LEN RSTRING_LEN
53#define RSTRING_LENINT RSTRING_LENINT
54#define RSTRING_PTR RSTRING_PTR
55#define RSTRING_END RSTRING_END
72#define StringValue(v) rb_string_value(&(v))
82#define StringValuePtr(v) rb_string_value_ptr(&(v))
95#define StringValueCStr(v) rb_string_value_cstr(&(v))
104#define SafeStringValue(v) StringValue(v)
123#define ExportStringValue(v) do { \
125 (v) = rb_str_export(v); \
143enum ruby_rstring_flags {
383void rb_check_safe_str(
VALUE);
392#define Check_SafeStr(v) rb_check_safe_str(RBIMPL_CAST((VALUE)(v)))
402void rb_debug_rstring_null_ptr(
const char *func);
429 long f =
RSTRING(str)->as.embed.len;
433 f &= RSTRING_EMBED_LEN_MASK;
435 return RBIMPL_CAST((
long)f);
440#if RBIMPL_COMPILER_IS(Intel)
456rbimpl_rstring_getmem(
VALUE str)
460 if (RB_FL_ANY_RAW(str, RSTRING_NOEMBED)) {
466 retval.
as.
heap.
len = RSTRING_EMBED_LEN(str);
467 retval.as.heap.ptr =
RSTRING(str)->as.embed.ary;
486 return rbimpl_rstring_getmem(str).
as.
heap.
len;
502 if (RB_UNLIKELY(!
ptr)) {
513 rb_debug_rstring_null_ptr(
"RSTRING_PTR");
530 struct RString buf = rbimpl_rstring_getmem(str);
532 if (RB_UNLIKELY(! buf.as.heap.ptr)) {
534 rb_debug_rstring_null_ptr(
"RSTRING_END");
537 return &buf.as.heap.ptr[buf.as.heap.len];
566#ifdef HAVE_STMT_AND_DECL_IN_EXPR
567# define RSTRING_GETMEM(str, ptrvar, lenvar) \
569 struct RString rbimpl_str = rbimpl_rstring_getmem(str); \
570 (ptrvar) = rbimpl_str.as.heap.ptr; \
571 (lenvar) = rbimpl_str.as.heap.len; \
574# define RSTRING_GETMEM(str, ptrvar, lenvar) \
575 ((ptrvar) = RSTRING_PTR(str), \
576 (lenvar) = RSTRING_LEN(str))
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
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.
@ RUBY_FL_USHIFT
Number of bits in ruby_fl_type that are not open to users.
@ RUBY_FL_USER5
User-defined flag.
@ RUBY_FL_USER3
User-defined flag.
@ RUBY_FL_USER17
User-defined flag.
@ RUBY_FL_USER6
User-defined flag.
@ RUBY_FL_USER2
User-defined flag.
@ RUBY_FL_USER4
User-defined flag.
@ RUBY_FL_USER1
User-defined flag.
#define RBIMPL_ATTR_ERROR(msg)
Wraps (or simulates) __attribute__((error))
Arithmetic conversion between C's long and Ruby's.
#define rb_long2int
Just another name of rb_long2int_inline.
Defines RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
#define RBASIC(obj)
Convenient casting macro.
ruby_rstring_consts
This is an enum because GDB wants it (rather than a macro).
@ RSTRING_EMBED_LEN_SHIFT
Where RSTRING_EMBED_LEN_MASK resides.
@ RSTRING_EMBED_LEN_MAX
Max possible number of characters that can be embedded.
#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.
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.
#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...
char * rb_string_value_ptr(volatile VALUE *ptr)
Identical to rb_str_to_str(), except it returns the converted string's backend memory region.
VALUE rb_str_to_str(VALUE obj)
Identical to rb_check_string_type(), except it raises exceptions in case of conversion failures.
Ruby's object's, base components.
union RString::@50 as
String's specific fields.
struct RString::@50::@51 heap
Strings that use separated memory region for contents use this pattern.
struct RBasic basic
Basic part, including flags and class.
long capa
Capacity of *ptr.
long len
Length of the string, not including terminating NUL character.
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.