Ruby: include/ruby/internal/core/rregexp.h Source File

Ruby 3.4.6p54 (2025-09-16 revision dbd83256b1cec76c69756ecb8758b9e1079833de)

rregexp.h
Go to the documentation of this file.
1#ifndef RBIMPL_RREGEXP_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_RREGEXP_H
23#include "ruby/internal/attr/artificial.h"
24#include "ruby/internal/attr/pure.h"
25#include "ruby/internal/cast.h"
26#include "ruby/internal/core/rbasic.h"
27#include "ruby/internal/core/rstring.h"
28#include "ruby/internal/value.h"
29#include "ruby/internal/value_type.h"
30
37#define RREGEXP(obj) RBIMPL_CAST((struct RRegexp *)(obj))
38
45#define RREGEXP_PTR(obj) (RREGEXP(obj)->ptr)
47#define RREGEXP_SRC RREGEXP_SRC
48#define RREGEXP_SRC_PTR RREGEXP_SRC_PTR
49#define RREGEXP_SRC_LEN RREGEXP_SRC_LEN
50#define RREGEXP_SRC_END RREGEXP_SRC_END
52
53struct re_patter_buffer; /* a.k.a. OnigRegexType, defined in onigmo.h */
54
60 struct RRegexp {
61
63 struct RBasic basic;
64
71 struct re_pattern_buffer *ptr;
72
74 const VALUE src;
75
90 unsigned long usecnt;
91};
92
93 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
94 RBIMPL_ATTR_ARTIFICIAL()
102static inline VALUE
103RREGEXP_SRC(VALUE rexp)
104{
105 RBIMPL_ASSERT_TYPE(rexp, RUBY_T_REGEXP);
106 VALUE ret = RREGEXP(rexp)->src;
107 RBIMPL_ASSERT_TYPE(ret, RUBY_T_STRING);
108 return ret;
109}
110
111 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
112 RBIMPL_ATTR_ARTIFICIAL()
124static inline char *
125RREGEXP_SRC_PTR(VALUE rexp)
126{
127 return RSTRING_PTR(RREGEXP_SRC(rexp));
128}
129
130 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
131 RBIMPL_ATTR_ARTIFICIAL()
143static inline long
144RREGEXP_SRC_LEN(VALUE rexp)
145{
146 return RSTRING_LEN(RREGEXP_SRC(rexp));
147}
148
149 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
150 RBIMPL_ATTR_ARTIFICIAL()
162static inline char *
163RREGEXP_SRC_END(VALUE rexp)
164{
165 return RSTRING_END(RREGEXP_SRC(rexp));
166}
167
168#endif /* RBIMPL_RREGEXP_H */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition artificial.h:43
inline
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition defines.h:91
pure.h
Defines RBIMPL_ATTR_PURE.
RBIMPL_ATTR_PURE_UNLESS_DEBUG
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
Definition pure.h:38
rbasic.h
Defines struct RBasic.
RREGEXP
#define RREGEXP(obj)
Convenient casting macro.
Definition rregexp.h:37
RREGEXP_SRC
static VALUE RREGEXP_SRC(VALUE rexp)
Convenient getter function.
Definition rregexp.h:103
RREGEXP_SRC_END
static char * RREGEXP_SRC_END(VALUE rexp)
Convenient getter function.
Definition rregexp.h:163
RREGEXP_SRC_LEN
static long RREGEXP_SRC_LEN(VALUE rexp)
Convenient getter function.
Definition rregexp.h:144
RREGEXP_SRC_PTR
static char * RREGEXP_SRC_PTR(VALUE rexp)
Convenient getter function.
Definition rregexp.h:125
rstring.h
Defines struct RString.
RSTRING_END
static char * RSTRING_END(VALUE str)
Queries the end of the contents pointer of the string.
Definition rstring.h:442
RBasic
Ruby object's base components.
Definition rbasic.h:63
RRegexp
Ruby's regular expression.
Definition rregexp.h:60
RRegexp::basic
struct RBasic basic
Basic part, including flags and class.
Definition rregexp.h:63
RRegexp::src
const VALUE src
Source code of this expression.
Definition rregexp.h:74
RRegexp::usecnt
unsigned long usecnt
Reference count.
Definition rregexp.h:90
RRegexp::ptr
struct re_pattern_buffer * ptr
The pattern buffer.
Definition rregexp.h:71
re_pattern_buffer
Definition onigmo.h:756
value.h
Defines VALUE and ID.
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
value_type.h
Defines enum ruby_value_type.
RUBY_T_STRING
@ RUBY_T_STRING
Definition value_type.h:120
RUBY_T_REGEXP
@ RUBY_T_REGEXP
Definition value_type.h:121