diff options
Diffstat (limited to 'include/ruby/internal/core/rmatch.h')
| -rw-r--r-- | include/ruby/internal/core/rmatch.h | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/include/ruby/internal/core/rmatch.h b/include/ruby/internal/core/rmatch.h index a528c2999e..ae93755531 100644 --- a/include/ruby/internal/core/rmatch.h +++ b/include/ruby/internal/core/rmatch.h @@ -67,23 +67,6 @@ struct rmatch_offset { long end; /**< End of a group. */ }; -/** Represents a match. */ -struct rb_matchext_struct { - /** - * "Registers" of a match. This is a quasi-opaque struct that holds - * execution result of a match. Roughly resembles `&~`. - */ - struct re_registers regs; - - /** Capture group offsets, in C array. */ - struct rmatch_offset *char_offset; - - /** Number of ::rmatch_offset that ::rmatch::char_offset holds. */ - int char_offset_num_allocated; -}; - -typedef struct rb_matchext_struct rb_matchext_t; - /** * Regular expression execution context. When a regular expression "matches" * to a string, it generates capture groups etc. This struct holds that info. @@ -107,12 +90,41 @@ struct RMatch { * The expression of this match. */ VALUE regexp; /* RRegexp */ + + /** Number of ::rmatch_offset that ::rmatch::char_offset holds. */ + int char_offset_num_allocated; + + /** Capture group offsets, in C array. */ + struct rmatch_offset *char_offset; + + /** Number of capture-group registers. */ + int num_regs; + + /** Capacity of `as.embed`, in OnigPosition slots. */ + int capa; + + /** + * "Registers" of a match. This is a quasi-opaque struct that holds + * execution result of a match. Roughly resembles `$~`. + */ + union { + OnigPosition embed[1]; + struct re_registers onig; + } as; }; -#define RMATCH_EXT(m) ((rb_matchext_t *)((char *)(m) + sizeof(struct RMatch))) +RBIMPL_SYMBOL_EXPORT_BEGIN() +/** + * @private + * + * Converts an embedded match to onig form. This is an implementation + * detail of #RMATCH_REGS. People don't use it directly. + * + * @param[out] match A match object, possibly in embedded form. + */ +void rb_match_ensure_onig(VALUE match); +RBIMPL_SYMBOL_EXPORT_END() -RBIMPL_ATTR_PURE_UNLESS_DEBUG() -RBIMPL_ATTR_ARTIFICIAL() /** * Queries the raw ::re_registers. * @@ -138,7 +150,8 @@ static inline struct re_registers * RMATCH_REGS(VALUE match) { RBIMPL_ASSERT_TYPE(match, RUBY_T_MATCH); - return &RMATCH_EXT(match)->regs; + rb_match_ensure_onig(match); + return &RMATCH(match)->as.onig; } #endif /* RBIMPL_RMATCH_H */ |
