3#include "internal/parse.h"
4#include "internal/re.h"
5#include "internal/ruby_parser.h"
9#include "internal/error.h"
11#ifdef UNIVERSAL_PARSER
14#include "internal/array.h"
15#include "internal/bignum.h"
16#include "internal/compile.h"
17#include "internal/complex.h"
18#include "internal/encoding.h"
19#include "internal/gc.h"
20#include "internal/hash.h"
21#include "internal/io.h"
22#include "internal/rational.h"
23#include "internal/re.h"
24#include "internal/string.h"
25#include "internal/symbol.h"
26#include "internal/thread.h"
35#define parser_encoding const void
39syntax_error_append(
VALUE exc,
VALUE file,
int line,
int column,
40 parser_encoding *enc, const
char *fmt, va_list args)
42 return rb_syntax_error_append(exc, file, line, column, enc, fmt, args);
46local_defined(
ID id,
const void *p)
48 return rb_local_defined(
id, (
const rb_iseq_t *)p);
52dvar_defined(
ID id,
const void *p)
54 return rb_dvar_defined(
id, (
const rb_iseq_t *)p);
58is_usascii_enc(parser_encoding *enc)
60 return rb_is_usascii_enc(enc);
66 return is_local_id(
id);
72 return is_attrset_id(
id);
78 return is_notop_id(
id);
82enc_str_new(
const char *ptr,
long len, parser_encoding *enc)
84 return rb_enc_str_new(ptr,
len, enc);
88enc_isalnum(OnigCodePoint c, parser_encoding *enc)
90 return rb_enc_isalnum(c, enc);
94enc_precise_mbclen(
const char *p,
const char *e, parser_encoding *enc)
96 return rb_enc_precise_mbclen(p, e, enc);
100mbclen_charfound_p(
int len)
106mbclen_charfound_len(
int len)
112enc_name(parser_encoding *enc)
114 return rb_enc_name(enc);
118enc_prev_char(
const char *s,
const char *p,
const char *e, parser_encoding *enc)
120 return rb_enc_prev_char(s, p, e, enc);
123static parser_encoding *
126 return rb_enc_get(obj);
130enc_asciicompat(parser_encoding *enc)
132 return rb_enc_asciicompat(enc);
135static parser_encoding *
142enc_associate(
VALUE obj, parser_encoding *enc)
144 return rb_enc_associate(obj, enc);
147static parser_encoding *
148ascii8bit_encoding(
void)
154enc_codelen(
int c, parser_encoding *enc)
156 return rb_enc_codelen(c, enc);
160enc_mbcput(
unsigned int c,
void *buf, parser_encoding *enc)
162 return rb_enc_mbcput(c, buf, enc);
165static parser_encoding *
166enc_from_index(
int idx)
168 return rb_enc_from_index(idx);
172enc_isspace(OnigCodePoint c, parser_encoding *enc)
174 return rb_enc_isspace(c, enc);
178intern3(
const char *name,
long len, parser_encoding *enc)
180 return rb_intern3(name,
len, enc);
183static parser_encoding *
184usascii_encoding(
void)
190enc_symname_type(
const char *name,
long len, parser_encoding *enc,
unsigned int allowed_attrset)
192 return rb_enc_symname_type(name,
len, enc, allowed_attrset);
199 const rb_code_location_t *loc;
200 rb_parser_assignable_func assignable;
204reg_named_capture_assign_iter(
const OnigUChar *name,
const OnigUChar *name_end,
205 int back_num,
int *back_refs, OnigRegex regex,
void *arg0)
209 rb_encoding *enc = arg->enc;
210 const rb_code_location_t *loc = arg->loc;
211 long len = name_end - name;
212 const char *s = (
const char *)name;
214 return rb_reg_named_capture_assign_iter_impl(p, s,
len, enc, &arg->succ_block, loc, arg->assignable);
218reg_named_capture_assign(
struct parser_params* p,
VALUE regexp,
const rb_code_location_t *loc,
219 rb_parser_assignable_func assignable)
224 arg.enc = rb_enc_get(regexp);
227 arg.assignable = assignable;
228 onig_foreach_name(
RREGEXP_PTR(regexp), reg_named_capture_assign_iter, &arg);
230 if (!arg.succ_block)
return 0;
231 return RNODE_BLOCK(arg.succ_block)->nd_next;
243 return (
int)
NIL_P(obj);
247syntax_error_new(
void)
253memmove2(
void *dest,
const void *src,
size_t t,
size_t n)
255 return memmove(dest, src, rbimpl_size_mul_or_raise(t, n));
259nonempty_memcpy(
void *dest,
const void *src,
size_t t,
size_t n)
261 return ruby_nonempty_memcpy(dest, src, rbimpl_size_mul_or_raise(t, n));
277zalloc(
size_t elemsiz)
279 return ruby_xcalloc(1, elemsiz);
301str_coderange_scan_restartable(
const char *s,
const char *e, parser_encoding *enc,
int *cr)
307enc_mbminlen(parser_encoding *enc)
309 return rb_enc_mbminlen(enc);
313enc_isascii(OnigCodePoint c, parser_encoding *enc)
315 return rb_enc_isascii(c, enc);
319enc_mbc_to_codepoint(
const char *p,
const char *e, parser_encoding *enc)
321 const OnigUChar *up = RBIMPL_CAST((
const OnigUChar *)p);
322 const OnigUChar *ue = RBIMPL_CAST((
const OnigUChar *)e);
324 return ONIGENC_MBC_TO_CODE((rb_encoding *)enc, up, ue);
327extern VALUE rb_eArgError;
329static const rb_parser_config_t rb_global_parser_config = {
330 .malloc = ruby_xmalloc,
331 .calloc = ruby_xcalloc,
332 .realloc = ruby_xrealloc,
334 .alloc_n = ruby_xmalloc2,
335 .alloc = ruby_xmalloc,
336 .realloc_n = ruby_xrealloc2,
338 .rb_memmove = memmove2,
339 .nonempty_memcpy = nonempty_memcpy,
340 .xmalloc_mul_add = rb_xmalloc_mul_add,
342 .compile_callback = rb_suppress_tracing,
343 .reg_named_capture_assign = reg_named_capture_assign,
345 .attr_get = rb_attr_get,
347 .ary_push = rb_ary_push,
348 .ary_new_from_args = rb_ary_new_from_args,
349 .ary_unshift = rb_ary_unshift,
351 .make_temporary_id = rb_make_temporary_id,
352 .is_local_id = is_local_id2,
353 .is_attrset_id = is_attrset_id2,
354 .is_global_name_punct = is_global_name_punct,
356 .id_attrset = rb_id_attrset,
358 .intern2 = rb_intern2,
360 .intern_str = rb_intern_str,
361 .is_notop_id = is_notop_id2,
362 .enc_symname_type = enc_symname_type,
363 .id2name = rb_id2name,
368 .str_catf = rb_str_catf,
370 .str_resize = rb_str_resize,
373 .str_to_interned_str = rb_str_to_interned_str,
374 .enc_str_new = enc_str_new,
375 .str_vcatf = rb_str_vcatf,
376 .rb_sprintf = rb_sprintf,
377 .rstring_ptr = RSTRING_PTR,
378 .rstring_len = RSTRING_LEN,
379 .obj_as_string = rb_obj_as_string,
383 .stderr_tty_p = rb_stderr_tty_p,
384 .write_error_str = rb_write_error_str,
385 .io_write = rb_io_write,
386 .io_flush = rb_io_flush,
387 .io_puts = rb_io_puts,
389 .debug_output_stdout = rb_ractor_stdout,
390 .debug_output_stderr = rb_ractor_stderr,
392 .is_usascii_enc = is_usascii_enc,
393 .enc_isalnum = enc_isalnum,
394 .enc_precise_mbclen = enc_precise_mbclen,
395 .mbclen_charfound_p = mbclen_charfound_p,
396 .mbclen_charfound_len = mbclen_charfound_len,
397 .enc_name = enc_name,
398 .enc_prev_char = enc_prev_char,
400 .enc_asciicompat = enc_asciicompat,
401 .utf8_encoding = utf8_encoding,
402 .enc_associate = enc_associate,
403 .ascii8bit_encoding = ascii8bit_encoding,
404 .enc_codelen = enc_codelen,
405 .enc_mbcput = enc_mbcput,
406 .enc_find_index = rb_enc_find_index,
407 .enc_from_index = enc_from_index,
408 .enc_isspace = enc_isspace,
411 .usascii_encoding = usascii_encoding,
412 .enc_mbminlen = enc_mbminlen,
413 .enc_isascii = enc_isascii,
414 .enc_mbc_to_codepoint = enc_mbc_to_codepoint,
416 .local_defined = local_defined,
417 .dvar_defined = dvar_defined,
419 .syntax_error_append = syntax_error_append,
421 .syntax_error_new = syntax_error_new,
423 .errinfo = rb_errinfo,
424 .set_errinfo = rb_set_errinfo,
425 .exc_raise = rb_exc_raise,
426 .make_exception = rb_make_exception,
428 .sized_xfree = ruby_sized_xfree,
429 .sized_realloc_n = ruby_sized_realloc_n,
430 .gc_guard = gc_guard,
431 .gc_mark = rb_gc_mark,
433 .reg_compile = rb_reg_compile,
434 .reg_check_preprocess = rb_reg_check_preprocess,
435 .memcicmp = rb_memcicmp,
437 .compile_warn = rb_compile_warn,
438 .compile_warning = rb_compile_warning,
441 .verbose = ruby_verbose2,
442 .errno_ptr = rb_errno_ptr2,
444 .make_backtrace = rb_make_backtrace,
446 .scan_hex = ruby_scan_hex,
447 .scan_oct = ruby_scan_oct,
448 .scan_digits = ruby_scan_digits,
455 .eArgError = arg_error,
459 .static_id2sym = static_id2sym,
460 .str_coderange_scan_restartable = str_coderange_scan_restartable,
472 rb_parser_t *parser_params;
486parser_mark(
void *ptr)
489 rb_ruby_parser_mark(parser->parser_params);
491 switch (parser->type) {
493 rb_gc_mark(parser->data.lex_str.str);
496 rb_gc_mark(parser->data.lex_io.file);
499 rb_gc_mark(parser->data.lex_array.ary);
501 case lex_type_generic:
508parser_free(
void *ptr)
511 rb_ruby_parser_free(parser->parser_params);
516parser_memsize(
const void *ptr)
519 return rb_ruby_parser_memsize(parser->parser_params);
529 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
532#ifdef UNIVERSAL_PARSER
533const rb_parser_config_t *
534rb_ruby_parser_config(
void)
536 return &rb_global_parser_config;
540rb_parser_params_new(
void)
542 return rb_ruby_parser_new(&rb_global_parser_config);
546rb_parser_params_new(
void)
548 return rb_ruby_parser_new();
565 &ruby_parser_data_type, parser);
572rb_parser_set_options(
VALUE vparser,
int print,
int loop,
int chomp,
int split)
577 rb_ruby_parser_set_options(parser->parser_params, print, loop, chomp, split);
586 rb_ruby_parser_set_context(parser->parser_params, base, main);
591rb_parser_set_script_lines(
VALUE vparser)
596 rb_ruby_parser_set_script_lines(parser->parser_params);
600rb_parser_error_tolerant(
VALUE vparser)
605 rb_ruby_parser_error_tolerant(parser->parser_params);
609rb_parser_keep_tokens(
VALUE vparser)
614 rb_ruby_parser_keep_tokens(parser->parser_params);
620 char *beg, *end, *start;
622 VALUE s = ptr_str->str;
624 beg = RSTRING_PTR(s);
625 len = RSTRING_LEN(s);
628 if (
len == ptr_str->ptr)
return 0;
632 end = memchr(beg,
'\n',
len);
633 if (end)
len = ++end - beg;
638static rb_parser_string_t *
639lex_get_str(
struct parser_params *p, rb_parser_input_data input,
int line_count)
644static void parser_aset_script_lines_for(
VALUE path, rb_parser_ary_t *lines);
647parser_compile(rb_parser_t *p, rb_parser_lex_gets_func *gets,
VALUE fname, rb_parser_input_data input,
int line)
649 rb_ast_t *ast = rb_parser_compile(p, gets, fname, input, line);
650 parser_aset_script_lines_for(fname, ast->body.script_lines);
659 parser->type = lex_type_str;
660 parser->data.lex_str.str = str;
661 parser->data.lex_str.ptr = 0;
663 return parser_compile(parser->parser_params, lex_get_str, fname, (rb_parser_input_data)&parser->data, line);
667must_be_ascii_compatible(
VALUE s)
669 rb_encoding *enc = rb_enc_get(s);
670 if (!rb_enc_asciicompat(enc)) {
671 rb_raise(rb_eArgError,
"invalid source encoding");
679 must_be_ascii_compatible(s);
680 return parser_compile_string0(parser, f, s, line);
684parser_compile_string(
struct ruby_parser *parser,
const char *f,
VALUE s,
int line)
691static rb_parser_string_t *
692lex_io_gets(
struct parser_params *p, rb_parser_input_data input,
int line_count)
695 VALUE line = rb_io_gets_internal(io);
696 if (
NIL_P(line))
return 0;
697 return rb_str_to_parser_string(p, line);
700static rb_parser_string_t *
701lex_gets_array(
struct parser_params *p, rb_parser_input_data data,
int index)
704 VALUE str = rb_ary_entry(array, index);
707 if (!rb_enc_asciicompat(rb_enc_get(str))) {
708 rb_raise(rb_eArgError,
"invalid source encoding");
710 return rb_str_to_parser_string(p, str);
720 parser->type = lex_type_io;
721 parser->data.lex_io.file = file;
723 return parser_compile(parser->parser_params, lex_io_gets, fname, (rb_parser_input_data)file, start);
729 parser->type = lex_type_array;
730 parser->data.lex_array.ary = array;
732 return parser_compile(parser->parser_params, lex_gets_array, fname, (rb_parser_input_data)array, start);
736parser_compile_generic(
struct ruby_parser *parser, rb_parser_lex_gets_func *lex_gets,
VALUE fname,
VALUE input,
int start)
738 parser->type = lex_type_generic;
740 return parser_compile(parser->parser_params, lex_gets, fname, (rb_parser_input_data)input, start);
746 rb_ast_t *ast = (rb_ast_t *)ptr;
757 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
767rb_parser_compile_file_path(
VALUE vparser,
VALUE fname,
VALUE file,
int start)
770 VALUE ast_value = ast_alloc();
773 DATA_PTR(ast_value) = parser_compile_file_path(parser, fname, file, start);
780rb_parser_compile_array(
VALUE vparser,
VALUE fname,
VALUE array,
int start)
783 VALUE ast_value = ast_alloc();
786 DATA_PTR(ast_value) = parser_compile_array(parser, fname, array, start);
793rb_parser_compile_generic(
VALUE vparser, rb_parser_lex_gets_func *lex_gets,
VALUE fname,
VALUE input,
int start)
796 VALUE ast_value = ast_alloc();
799 DATA_PTR(ast_value) = parser_compile_generic(parser, lex_gets, fname, input, start);
806rb_parser_compile_string(
VALUE vparser,
const char *f,
VALUE s,
int line)
809 VALUE ast_value = ast_alloc();
812 DATA_PTR(ast_value) = parser_compile_string(parser, f, s, line);
819rb_parser_compile_string_path(
VALUE vparser,
VALUE f,
VALUE s,
int line)
822 VALUE ast_value = ast_alloc();
825 DATA_PTR(ast_value) = parser_compile_string_path(parser, f, s, line);
832rb_parser_encoding(
VALUE vparser)
837 return rb_enc_from_encoding(rb_ruby_parser_encoding(parser->parser_params));
841rb_parser_end_seen_p(
VALUE vparser)
846 return RBOOL(rb_ruby_parser_end_seen_p(parser->parser_params));
850rb_parser_set_yydebug(
VALUE vparser,
VALUE flag)
855 rb_ruby_parser_set_yydebug(parser->parser_params,
RTEST(flag));
860rb_set_script_lines_for(
VALUE vparser,
VALUE path)
865 CONST_ID(script_lines,
"SCRIPT_LINES__");
869 rb_hash_aset(hash, path,
Qtrue);
871 rb_ruby_parser_set_script_lines(parser->parser_params);
876rb_parser_build_script_lines_from(rb_parser_ary_t *lines)
879 if (!lines)
return Qnil;
880 if (lines->data_type != PARSER_ARY_DATA_SCRIPT_LINE) {
881 rb_bug(
"unexpected rb_parser_ary_data_type (%d) for script lines", lines->data_type);
883 VALUE script_lines = rb_ary_new_capa(lines->len);
884 for (i = 0; i < lines->len; i++) {
885 rb_parser_string_t *str = (rb_parser_string_t *)lines->data[i];
886 rb_ary_push(script_lines, rb_enc_str_new(str->ptr, str->len, str->enc));
892rb_str_new_parser_string(rb_parser_string_t *str)
894 VALUE string = rb_enc_literal_str(str->ptr, str->len, str->enc);
900rb_str_new_mutable_parser_string(rb_parser_string_t *str)
902 return rb_enc_str_new(str->ptr, str->len, str->enc);
906negative_numeric(
VALUE val)
922 val = rb_big_norm(val);
925 RATIONAL_SET_NUM(val, negative_numeric(RRATIONAL(val)->num));
928 RCOMPLEX_SET_REAL(val, negative_numeric(RCOMPLEX(val)->real));
929 RCOMPLEX_SET_IMAG(val, negative_numeric(RCOMPLEX(val)->imag));
936 rb_bug(
"unknown literal type (%s) passed to negative_numeric",
937 rb_builtin_class_name(val));
944integer_value(
const char *val,
int base)
946 return rb_cstr_to_inum(val, base, FALSE);
950rational_value(
const char *node_val,
int base,
int seen_point)
953 char* val =
strdup(node_val);
954 if (seen_point > 0) {
955 int len = (int)(strlen(val));
956 char *point = &val[seen_point];
957 size_t fraclen =
len-seen_point-1;
958 memmove(point, point+1, fraclen+1);
972rb_node_integer_literal_val(
const NODE *n)
974 const rb_node_integer_t *node = RNODE_INTEGER(n);
975 VALUE val = integer_value(node->val, node->base);
977 val = negative_numeric(val);
983rb_node_float_literal_val(
const NODE *n)
985 const rb_node_float_t *node = RNODE_FLOAT(n);
986 double d =
strtod(node->val, 0);
995rb_node_rational_literal_val(
const NODE *n)
998 const rb_node_rational_t *node = RNODE_RATIONAL(n);
1000 lit = rational_value(node->val, node->base, node->seen_point);
1003 lit = negative_numeric(lit);
1010rb_node_imaginary_literal_val(
const NODE *n)
1013 const rb_node_imaginary_t *node = RNODE_IMAGINARY(n);
1015 enum rb_numeric_type
type = node->type;
1018 case integer_literal:
1019 lit = integer_value(node->val, node->base);
1021 case float_literal:{
1022 double d =
strtod(node->val, 0);
1026 case rational_literal:
1027 lit = rational_value(node->val, node->base, node->seen_point);
1030 rb_bug(
"unreachable");
1033 lit = rb_complex_raw(
INT2FIX(0), lit);
1036 lit = negative_numeric(lit);
1042rb_node_str_string_val(
const NODE *node)
1044 rb_parser_string_t *str = RNODE_STR(node)->string;
1045 return rb_str_new_parser_string(str);
1049rb_node_sym_string_val(
const NODE *node)
1051 rb_parser_string_t *str = RNODE_SYM(node)->string;
1052 return ID2SYM(rb_intern3(str->ptr, str->len, str->enc));
1056rb_node_dstr_string_val(
const NODE *node)
1058 rb_parser_string_t *str = RNODE_DSTR(node)->string;
1059 return str ? rb_str_new_parser_string(str) :
Qnil;
1063rb_node_dregx_string_val(
const NODE *node)
1065 rb_parser_string_t *str = RNODE_DREGX(node)->string;
1066 return rb_str_new_parser_string(str);
1070rb_node_regx_string_val(
const NODE *node)
1072 rb_node_regx_t *node_reg = RNODE_REGX(node);
1073 rb_parser_string_t *
string = node_reg->string;
1074 VALUE str = rb_enc_str_new(string->ptr, string->len, string->enc);
1076 return rb_reg_compile(str, node_reg->options, NULL, 0);
1080rb_node_line_lineno_val(
const NODE *node)
1082 return INT2FIX(node->nd_loc.beg_pos.lineno);
1086rb_node_file_path_val(
const NODE *node)
1088 return rb_str_new_parser_string(RNODE_FILE(node)->path);
1092rb_node_encoding_val(
const NODE *node)
1094 return rb_enc_from_encoding(RNODE_ENCODING(node)->enc);
1098parser_aset_script_lines_for(
VALUE path, rb_parser_ary_t *lines)
1100 VALUE hash, script_lines;
1102 if (
NIL_P(path) || !lines)
return;
1103 CONST_ID(script_lines_id,
"SCRIPT_LINES__");
1107 if (rb_hash_lookup(hash, path) ==
Qnil)
return;
1108 script_lines = rb_parser_build_script_lines_from(lines);
1109 rb_hash_aset(hash, path, script_lines);
1113rb_ruby_ast_new(
const NODE *
const root)
1117#ifdef UNIVERSAL_PARSER
1118 ast->config = &rb_global_parser_config;
1120 ast->body = (rb_ast_body_t){
1122 .frozen_string_literal = -1,
1123 .coverage_enabled = -1,
1124 .script_lines = NULL,
1131rb_ruby_ast_data_get(
VALUE ast_value)
1134 if (
NIL_P(ast_value))
return NULL;
#define T_COMPLEX
Old name of RUBY_T_COMPLEX.
#define ENC_CODERANGE_7BIT
Old name of RUBY_ENC_CODERANGE_7BIT.
#define RFLOAT_VALUE
Old name of rb_float_value.
#define xfree
Old name of ruby_xfree.
#define INT2FIX
Old name of RB_INT2FIX.
#define T_FLOAT
Old name of RUBY_T_FLOAT.
#define ID2SYM
Old name of RB_ID2SYM.
#define T_BIGNUM
Old name of RUBY_T_BIGNUM.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define ENC_CODERANGE_UNKNOWN
Old name of RUBY_ENC_CODERANGE_UNKNOWN.
#define LONG2FIX
Old name of RB_INT2FIX.
#define SYMBOL_FLAG
Old name of RUBY_SYMBOL_FLAG.
#define T_RATIONAL
Old name of RUBY_T_RATIONAL.
#define T_HASH
Old name of RUBY_T_HASH.
#define MBCLEN_CHARFOUND_LEN(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_LEN.
#define FLONUM_P
Old name of RB_FLONUM_P.
#define Qtrue
Old name of RUBY_Qtrue.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define FIX2LONG
Old name of RB_FIX2LONG.
#define NIL_P
Old name of RB_NIL_P.
#define MBCLEN_CHARFOUND_P(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_P.
#define DBL2NUM
Old name of rb_float_new.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define CONST_ID
Old name of RUBY_CONST_ID.
#define ruby_verbose
This variable controls whether the interpreter is in debug mode.
VALUE rb_eSyntaxError
SyntaxError exception.
VALUE rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
Allocates, then initialises an instance of the given class.
rb_encoding * rb_utf8_encoding(void)
Queries the encoding that represents UTF-8.
rb_encoding * rb_ascii8bit_encoding(void)
Queries the encoding that represents ASCII-8BIT a.k.a.
rb_encoding * rb_usascii_encoding(void)
Queries the encoding that represents US-ASCII.
int rb_enc_str_coderange(VALUE str)
Scans the passed string to collect its code range.
long rb_str_coderange_scan_restartable(const char *str, const char *end, rb_encoding *enc, int *cr)
Scans the passed string until it finds something odd.
VALUE rb_int_positive_pow(long x, unsigned long y)
Raises the passed x to the power of y.
VALUE rb_rational_new(VALUE num, VALUE den)
Constructs a Rational, with reduction.
#define rb_rational_raw1(x)
Shorthand of (x/1)r.
VALUE rb_str_subseq(VALUE str, long beg, long len)
Identical to rb_str_substr(), except the numbers are interpreted as byte offsets instead of character...
#define rb_str_new(str, len)
Allocates an instance of rb_cString.
VALUE rb_str_new_frozen(VALUE str)
Creates a frozen copy of the string, if necessary.
VALUE rb_filesystem_str_new_cstr(const char *ptr)
Identical to rb_filesystem_str_new(), except it assumes the passed pointer is a pointer to a C string...
#define rb_str_cat_cstr(buf, str)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
VALUE rb_const_get_at(VALUE space, ID name)
Identical to rb_const_defined_at(), except it returns the actual defined value.
int rb_const_defined_at(VALUE space, ID name)
Identical to rb_const_defined(), except it doesn't look for parent classes.
VALUE rb_id2sym(ID id)
Allocates an instance of rb_cSymbol that has the given id.
ID rb_sym2id(VALUE obj)
Converts an instance of rb_cSymbol into an ID.
int len
Length of the buffer.
#define strtod(s, e)
Just another name of ruby_strtod.
double ruby_strtod(const char *str, char **endptr)
Our own locale-insensitive version of strtod(3).
#define strdup(s)
Just another name of ruby_strdup.
static VALUE rb_int2num_inline(int v)
Converts a C's int into an instance of rb_cInteger.
#define rb_long2int
Just another name of rb_long2int_inline.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE type(ANYARGS)
ANYARGS-ed function type.
#define DATA_PTR(obj)
Convenient getter macro.
#define RREGEXP_PTR(obj)
Convenient accessor macro.
#define StringValue(v)
Ensures that the parameter object is a String.
#define TypedData_Get_Struct(obj, type, data_type, sval)
Obtains a C struct from inside of a wrapper Ruby object.
#define TypedData_Wrap_Struct(klass, data_type, sval)
Converts sval, a pointer to your struct, into a Ruby object.
struct rb_data_type_struct rb_data_type_t
This is the struct that holds necessary info for a struct.
#define TypedData_Make_Struct(klass, type, data_type, sval)
Identical to TypedData_Wrap_Struct, except it allocates a new data region internally instead of takin...
int * rb_errno_ptr(void)
The location of errno
static bool RB_TEST(VALUE obj)
Emulates Ruby's "if" statement.
@ RUBY_SPECIAL_SHIFT
Least significant 8 bits are reserved.
#define RTEST
This is an old name of RB_TEST.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.