4#include "internal/class.h"
5#include "internal/eval.h"
6#include "internal/error.h"
7#include "internal/file.h"
8#include "internal/gc.h"
9#include "internal/hash.h"
10#include "internal/load.h"
11#include "internal/namespace.h"
12#include "internal/st.h"
13#include "internal/variable.h"
21VALUE rb_cNamespaceEntry = 0;
23VALUE rb_mNamespaceLoader = 0;
33static rb_namespace_t *
const builtin_namespace = &builtin_namespace_data;
36static bool tmp_dir_has_dirsep;
38#define NAMESPACE_TMP_PREFIX "_ruby_ns_"
41# define MAXPATHLEN 1024
50static int namespace_availability = 0;
56rb_namespace_available(
void)
59 if (namespace_availability) {
60 return namespace_availability > 0 ? 1 : 0;
62 env = getenv(
"RUBY_NAMESPACE");
63 if (env && strlen(env) > 0) {
64 if (strcmp(env,
"1") == 0) {
65 namespace_availability = 1;
69 namespace_availability = -1;
77rb_namespace_enable_builtin(
void)
79 VALUE require_stack = GET_VM()->require_stack;
81 rb_ary_push(require_stack,
Qnil);
86rb_namespace_disable_builtin(
void)
88 VALUE require_stack = GET_VM()->require_stack;
90 rb_ary_pop(require_stack);
97 VALUE require_stack = GET_VM()->require_stack;
98 rb_ary_push(require_stack, ns->ns_object);
104 VALUE require_stack = GET_VM()->require_stack;
107 rb_bug(
"popping on the empty require_stack");
109 if (latest != ns->ns_object)
110 rb_bug(
"Inconsistent loading namespace");
111 rb_ary_pop(require_stack);
115rb_root_namespace(
void)
117 return root_namespace;
121rb_builtin_namespace(
void)
127rb_main_namespace(
void)
129 return main_namespace;
135 if (!NAMESPACE_BUILTIN_P(ns)) {
142 if (def->type == VM_METHOD_TYPE_ISEQ) {
143 ID mid = def->original_id;
144 const char *path = RSTRING_PTR(pathobj_path(def->body.iseq.
iseqptr->body->location.pathobj));
145 if (strcmp(path,
"<internal:kernel>") == 0) {
146 if (mid == rb_intern(
"class") || mid == rb_intern(
"clone") ||
147 mid == rb_intern(
"tag") || mid == rb_intern(
"then") ||
148 mid == rb_intern(
"yield_self") || mid == rb_intern(
"loop") ||
149 mid == rb_intern(
"Float") || mid == rb_intern(
"Integer")
154 else if (strcmp(path,
"<internal:warning>") == 0) {
155 if (mid == rb_intern(
"warn")) {
159 else if (strcmp(path,
"<internal:marshal>") == 0) {
160 if (mid == rb_intern(
"load"))
168block_proc_namespace(
const VALUE procval)
173 GetProcPtr(procval, proc);
182current_namespace(
bool permit_calling_builtin)
195 if (!rb_namespace_available())
198 if (th->namespaces &&
RARRAY_LEN(th->namespaces) > 0) {
206 if (VM_FRAME_NS_SWITCH_P(cfp)) {
207 bh = rb_vm_frame_block_handler(cfp);
208 if (bh && vm_block_handler_type(bh) == block_handler_type_proc) {
209 proc_ns = block_proc_namespace(VM_BH_TO_PROC(bh));
210 if (permit_calling_builtin || NAMESPACE_USER_P(proc_ns))
214 cme = rb_vm_frame_method_entry(cfp);
215 if (cme && cme->def) {
220 if (!namespace_ignore_builtin_primitive_methods_p(ns, cme->def)) {
221 if (permit_calling_builtin || (proc_ns && NAMESPACE_USER_P(proc_ns)))
225 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
236 if (!main_namespace) {
238 return root_namespace;
240 return main_namespace;
244rb_current_namespace(
void)
246 return current_namespace(
true);
250rb_loading_namespace(
void)
254 VALUE require_stack = GET_VM()->require_stack;
256 if (!rb_namespace_available())
259 if (!require_stack) {
260 return current_namespace(
false);
263 return current_namespace(
false);
267 rb_bug(
"require_stack is not an array: %s", rb_type_str(
BUILTIN_TYPE(require_stack)));
270 return rb_get_namespace_t(
namespace);
274rb_definition_namespace(
void)
277 if (NAMESPACE_BUILTIN_P(ns)) {
278 return root_namespace;
284rb_current_namespace_details(
VALUE opt)
287 VALUE str, part, nsobj;
297 VALUE require_stack = vm->require_stack;
299 str = rb_namespace_inspect(ns ? ns->ns_object :
Qfalse);
300 if (
NIL_P(opt))
return str;
304 part = rb_namespace_inspect(th->ns ? th->ns->ns_object :
Qfalse);
305 snprintf(buf, 2048,
"main:%s, th->ns:%s, th->nss:%ld, rstack:%ld\n",
306 main_namespace ?
"t" :
"f",
308 th->namespaces ?
RARRAY_LEN(th->namespaces) : 0,
309 require_stack ?
RARRAY_LEN(require_stack) : 0);
313 if (th->namespaces &&
RARRAY_LEN(th->namespaces) > 0) {
314 for (i=0; i<
RARRAY_LEN(th->namespaces); i++) {
316 part = rb_namespace_inspect(nsobj);
317 snprintf(buf, 2048,
" th->nss[%ld] %s\n", i, RSTRING_PTR(part));
326 while (calling && cfp) {
329 if (VM_FRAME_NS_SWITCH_P(cfp)) {
330 bh = rb_vm_frame_block_handler(cfp);
331 if (bh && vm_block_handler_type(bh) == block_handler_type_proc) {
332 proc_ns = block_proc_namespace(VM_BH_TO_PROC(bh));
333 if (NAMESPACE_USER_P(ns)) {
334 part = rb_namespace_inspect(proc_ns->ns_object);
335 snprintf(buf, 2048,
" cfp->ns:%s", RSTRING_PTR(part));
342 cme = rb_vm_frame_method_entry(cfp);
343 if (cme && cme->def) {
344 if (cme->def->type == VM_METHOD_TYPE_ISEQ)
345 path = RSTRING_PTR(pathobj_path(cme->def->body.iseq.
iseqptr->body->location.pathobj));
350 part = rb_namespace_inspect(ns->ns_object);
351 if (!namespace_ignore_builtin_primitive_methods_p(ns, cme->def)) {
352 snprintf(buf, 2048,
" cfp cme->def id:%s, ns:%s, exprim:t, path:%s\n",
353 rb_id2name(cme->def->original_id),
362 snprintf(buf, 2048,
" cfp cme->def id:%s, ns:%s, exprim:f, path:%s\n",
363 rb_id2name(cme->def->original_id),
371 snprintf(buf, 2048,
" cfp cme->def id:%s, ns:null, path:%s\n",
372 rb_id2name(cme->def->original_id),
376 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
386static long namespace_id_counter = 0;
389namespace_generate_id(
void)
394 id = ++namespace_id_counter;
410 ns->load_path = rb_ary_dup(vm->load_path);
411 ns->expanded_load_path = rb_ary_dup(vm->expanded_load_path);
412 ns->load_path_snapshot = rb_ary_new();
413 ns->load_path_check_cache = 0;
414 ns->loaded_features = rb_ary_dup(vm->loaded_features);
415 ns->loaded_features_snapshot = rb_ary_new();
416 ns->loaded_features_index = st_init_numtable();
417 ns->loaded_features_realpaths = rb_hash_dup(vm->loaded_features_realpaths);
418 ns->loaded_features_realpath_map = rb_hash_dup(vm->loaded_features_realpath_map);
419 ns->loading_table = st_init_strtable();
420 ns->ruby_dln_libmap = rb_hash_new_with_size(0);
421 ns->gvar_tbl = rb_hash_new_with_size(0);
423 ns->is_builtin =
false;
425 ns->is_optional =
true;
428void rb_namespace_gc_update_references(
void *ptr)
431 if (!
NIL_P(ns->ns_object))
432 ns->ns_object = rb_gc_location(ns->ns_object);
433 ns->top_self = rb_gc_location(ns->top_self);
434 ns->load_path = rb_gc_location(ns->load_path);
435 ns->expanded_load_path = rb_gc_location(ns->expanded_load_path);
436 ns->load_path_snapshot = rb_gc_location(ns->load_path_snapshot);
437 if (ns->load_path_check_cache) {
438 ns->load_path_check_cache = rb_gc_location(ns->load_path_check_cache);
440 ns->loaded_features = rb_gc_location(ns->loaded_features);
441 ns->loaded_features_snapshot = rb_gc_location(ns->loaded_features_snapshot);
442 ns->loaded_features_realpaths = rb_gc_location(ns->loaded_features_realpaths);
443 ns->loaded_features_realpath_map = rb_gc_location(ns->loaded_features_realpath_map);
444 ns->ruby_dln_libmap = rb_gc_location(ns->ruby_dln_libmap);
445 ns->gvar_tbl = rb_gc_location(ns->gvar_tbl);
449rb_namespace_entry_mark(
void *ptr)
452 rb_gc_mark(ns->ns_object);
453 rb_gc_mark(ns->top_self);
454 rb_gc_mark(ns->load_path);
455 rb_gc_mark(ns->expanded_load_path);
456 rb_gc_mark(ns->load_path_snapshot);
457 rb_gc_mark(ns->load_path_check_cache);
458 rb_gc_mark(ns->loaded_features);
459 rb_gc_mark(ns->loaded_features_snapshot);
460 rb_gc_mark(ns->loaded_features_realpaths);
461 rb_gc_mark(ns->loaded_features_realpath_map);
462 if (ns->loading_table) {
463 rb_mark_tbl(ns->loading_table);
465 rb_gc_mark(ns->ruby_dln_libmap);
466 rb_gc_mark(ns->gvar_tbl);
469#define namespace_entry_free RUBY_TYPED_DEFAULT_FREE
472namespace_entry_memsize(
const void *ptr)
480 rb_namespace_entry_mark,
481 namespace_entry_free,
482 namespace_entry_memsize,
483 rb_namespace_gc_update_references,
485 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
489rb_namespace_entry_alloc(
VALUE klass)
493 namespace_entry_initialize(entry);
498get_namespace_struct_internal(
VALUE entry)
506rb_get_namespace_t(
VALUE namespace)
509 ID id_namespace_entry;
512 return root_namespace;
513 if (
NIL_P(
namespace))
514 return builtin_namespace;
516 CONST_ID(id_namespace_entry,
"__namespace_entry__");
517 entry = rb_attr_get(
namespace, id_namespace_entry);
518 return get_namespace_struct_internal(entry);
526 return ns->ns_object;
532namespace_initialize(
VALUE namespace)
537 ID id_namespace_entry;
538 CONST_ID(id_namespace_entry,
"__namespace_entry__");
540 if (!rb_namespace_available()) {
541 rb_raise(
rb_eRuntimeError,
"Namespace is disabled. Set RUBY_NAMESPACE=1 environment variable to use Namespace.");
545 ns = get_namespace_struct_internal(entry);
547 ns->ns_object =
namespace;
548 ns->ns_id = namespace_generate_id();
549 ns->load_path = rb_ary_dup(GET_VM()->load_path);
556 RCLASS_SET_PRIME_CLASSEXT_WRITABLE(
namespace,
true);
559 rb_evict_ivars_to_hash(
namespace);
563 object_classext = RCLASS_EXT_WRITABLE_IN_NS(rb_cObject, ns);
564 RCLASS_SET_CONST_TBL(
namespace, RCLASSEXT_CONST_TBL(object_classext),
true);
568 setup_pushing_loading_namespace(ns);
574rb_namespace_s_getenabled(
VALUE namespace)
576 return RBOOL(rb_namespace_available());
580rb_namespace_current(
VALUE klass)
583 if (NAMESPACE_USER_P(ns)) {
584 return ns->ns_object;
586 if (NAMESPACE_BUILTIN_P(ns)) {
593rb_namespace_s_is_builtin_p(
VALUE namespace,
VALUE klass)
595 if (RCLASS_PRIME_CLASSEXT_READABLE_P(klass) && !RCLASS_PRIME_CLASSEXT_WRITABLE_P(klass))
601rb_namespace_load_path(
VALUE namespace)
603 return rb_get_namespace_t(
namespace)->load_path;
607UINT rb_w32_system_tmpdir(WCHAR *path, UINT
len);
612system_default_tmpdir(
void)
616 WCHAR tmppath[_MAX_PATH];
617 UINT
len = rb_w32_system_tmpdir(tmppath, numberof(tmppath));
619 int blen = WideCharToMultiByte(CP_UTF8, 0, tmppath,
len, NULL, 0, NULL, NULL);
620 char *tmpdir =
xmalloc(blen + 1);
621 WideCharToMultiByte(CP_UTF8, 0, tmppath,
len, tmpdir, blen, NULL, NULL);
625#elif defined _CS_DARWIN_USER_TEMP_DIR
626 char path[MAXPATHLEN];
627 size_t len = confstr(_CS_DARWIN_USER_TEMP_DIR, path,
sizeof(path));
630 if (
len >
sizeof(path)) {
631 confstr(_CS_DARWIN_USER_TEMP_DIR, tmpdir,
len);
634 memcpy(tmpdir, path,
len);
643check_tmpdir(
const char *dir)
647 if (!dir)
return FALSE;
648 if (stat(dir, &st))
return FALSE;
650# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
652 if (!S_ISDIR(st.st_mode))
return FALSE;
657 if (st.st_mode & S_IWOTH) {
659 if (!(st.st_mode & S_ISVTX))
return FALSE;
664 if (access(dir, W_OK))
return FALSE;
673# define RETURN_ENV(name) \
674 if (check_tmpdir(tmpdir = getenv(name))) return ruby_strdup(tmpdir)
675 RETURN_ENV(
"TMPDIR");
677 tmpdir = system_default_tmpdir();
678 if (check_tmpdir(tmpdir))
return tmpdir;
686sprint_ext_filename(
char *str,
size_t size,
long namespace_id,
const char *prefix,
const char *basename)
688 if (tmp_dir_has_dirsep) {
689 return snprintf(str, size,
"%s%sp%"PRI_PIDT_PREFIX"u_%ld_%s", tmp_dir, prefix, getpid(), namespace_id, basename);
691 return snprintf(str, size,
"%s%s%sp%"PRI_PIDT_PREFIX"u_%ld_%s", tmp_dir, DIRSEP, prefix, getpid(), namespace_id, basename);
696copy_ext_file_error(
char *message,
size_t size)
698 int error = GetLastError();
700 size_t len = snprintf(message, size,
"%d: ", error);
702#define format_message(sublang) FormatMessage(\
703 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
704 NULL, error, MAKELANGID(LANG_NEUTRAL, (sublang)), \
705 message + len, size - len, NULL)
706 if (format_message(SUBLANG_ENGLISH_US) == 0)
707 format_message(SUBLANG_DEFAULT);
708 for (p = message +
len; *p; p++) {
709 if (*p ==
'\n' || *p ==
'\r')
716copy_ext_file_error(
char *message,
size_t size,
int copy_retvalue,
char *src_path,
char *dst_path)
718 switch (copy_retvalue) {
720 snprintf(message, size,
"can't open the extension path: %s", src_path);
722 snprintf(message, size,
"can't open the file to write: %s", dst_path);
724 snprintf(message, size,
"failed to read the extension path: %s", src_path);
726 snprintf(message, size,
"failed to write the extension path: %s", dst_path);
728 rb_bug(
"unkown return value of copy_ext_file: %d", copy_retvalue);
735copy_ext_file(
char *src_path,
char *dst_path)
740 WCHAR *w_src = rb_w32_mbstr_to_wstr(CP_UTF8, src_path, -1, NULL);
741 WCHAR *w_dst = rb_w32_mbstr_to_wstr(CP_UTF8, dst_path, -1, NULL);
742 if (!w_src || !w_dst) {
746 rvalue = CopyFileW(w_src, w_dst, FALSE) ? 0 : 1;
753 size_t read = 0, wrote, written = 0;
754 size_t maxread =
sizeof(buffer);
759 src = fopen(src_path,
"rb");
763 dst = fopen(dst_path,
"wb");
769 read = fread(buffer, 1,
sizeof(buffer), src);
773 wrote = fwrite(buffer+written, 1, read-written, dst);
774 if (wrote < read-written) {
788 if (read < maxread) {
789 if (clean_read && feof(src)) {
793 else if (ferror(src)) {
806#if defined __CYGWIN__ || defined DOSISH
807#define isdirsep(x) ((x) == '/' || (x) == '\\')
809#define isdirsep(x) ((x) == '/')
812#define IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0)
813#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
816fname_without_suffix(
char *fname,
char *rvalue)
819 strcpy(rvalue, fname);
820 for (pos = rvalue + strlen(fname); pos > rvalue; pos--) {
821 if (IS_SOEXT(pos) || IS_DLEXT(pos)) {
829escaped_basename(
char *path,
char *fname,
char *rvalue)
831 char *pos, *leaf, *found;
834 while ((found = strstr(leaf + 1, fname)) != NULL) {
837 strcpy(rvalue, leaf);
838 for (pos = rvalue; *pos; pos++) {
839 if (isdirsep(*pos)) {
848 char ext_path[MAXPATHLEN], fname2[MAXPATHLEN], basename[MAXPATHLEN];
849 int copy_error, wrote;
850 char *src_path = RSTRING_PTR(path), *fname_ptr = RSTRING_PTR(fname);
853 fname_without_suffix(fname_ptr, fname2);
854 escaped_basename(src_path, fname2, basename);
856 wrote = sprint_ext_filename(ext_path,
sizeof(ext_path), ns->ns_id, NAMESPACE_TMP_PREFIX, basename);
857 if (wrote >= (
int)
sizeof(ext_path)) {
858 rb_bug(
"Extension file path in namespace was too long");
860 copy_error = copy_ext_file(src_path, ext_path);
864 copy_ext_file_error(message,
sizeof(message));
866 copy_ext_file_error(message,
sizeof(message), copy_error, src_path, ext_path);
868 rb_raise(
rb_eLoadError,
"can't prepare the extension file for namespaces (%s from %s): %s", ext_path, src_path, message);
881 if (
RTEST(th->namespaces)) {
882 rb_ary_push(th->namespaces,
namespace);
885 th->namespaces = rb_ary_new_from_args(1,
namespace);
887 th->ns = rb_get_namespace_t(
namespace);
891namespace_pop(
VALUE th_value)
896 VALUE namespaces = th->namespaces;
898 rb_bug(
"Too many namespace pops");
900 rb_ary_pop(namespaces);
902 if (stack_len == 0) {
904 th->ns = main_namespace;
908 th->ns = rb_get_namespace_t(upper_ns);
917 namespace_push(th, ns ? ns->ns_object :
Qnil);
927namespace_both_pop(
VALUE arg)
930 namespace_pop((
VALUE) data->th);
931 rb_namespace_pop_loading_namespace(data->ns);
936rb_namespace_load(
int argc,
VALUE *argv,
VALUE namespace)
944 VALUE args = rb_ary_new_from_args(2, fname, wrap);
945 namespace_push(th,
namespace);
946 rb_namespace_push_loading_namespace(ns);
951 return rb_ensure(rb_load_entrypoint, args, namespace_both_pop, (
VALUE)&arg);
955rb_namespace_require(
VALUE namespace,
VALUE fname)
959 namespace_push(th,
namespace);
960 rb_namespace_push_loading_namespace(ns);
969rb_namespace_require_relative(
VALUE namespace,
VALUE fname)
973 namespace_push(th,
namespace);
974 rb_namespace_push_loading_namespace(ns);
979 return rb_ensure(rb_require_relative_entrypoint, fname, namespace_both_pop, (
VALUE)&arg);
982static int namespace_experimental_warned = 0;
985rb_initialize_main_namespace(
void)
992 if (!namespace_experimental_warned) {
994 "Namespace is experimental, and the behavior may change in the future!\n"
995 "See doc/namespace.md for known issues, etc.");
996 namespace_experimental_warned = 1;
1000 ns = rb_get_namespace_t(main_ns);
1001 ns->ns_object = main_ns;
1002 ns->ns_id = namespace_generate_id();
1003 ns->is_builtin =
false;
1005 ns->is_optional =
false;
1009 vm->main_namespace = th->ns = main_namespace = ns;
1013rb_namespace_inspect(
VALUE obj)
1021 ns = rb_get_namespace_t(obj);
1024 if (NAMESPACE_BUILTIN_P(ns)) {
1027 if (NAMESPACE_USER_P(ns)) {
1030 if (NAMESPACE_MAIN_P(ns)) {
1033 else if (NAMESPACE_OPTIONAL_P(ns)) {
1046namespace_builtin_refiner_calling_super(
VALUE arg)
1053namespace_builtin_refiner_loading_func_ensure(
VALUE _)
1056 if (!vm->require_stack)
1057 rb_bug(
"require_stack is not ready but the namespace refiner is called");
1058 rb_namespace_disable_builtin();
1063rb_namespace_builtin_refiner_loading_func(
int argc,
VALUE *argv,
VALUE _self)
1066 if (!vm->require_stack)
1067 rb_bug(
"require_stack is not ready but the namespace refiner is called");
1068 rb_namespace_enable_builtin();
1075 return rb_ensure(namespace_builtin_refiner_calling_super, (
VALUE)&data,
1076 namespace_builtin_refiner_loading_func_ensure,
Qnil);
1080setup_builtin_refinement(
VALUE mod)
1084 rb_define_method(data.refinement,
"require", rb_namespace_builtin_refiner_loading_func, -1);
1085 rb_define_method(data.refinement,
"require_relative", rb_namespace_builtin_refiner_loading_func, -1);
1086 rb_define_method(data.refinement,
"load", rb_namespace_builtin_refiner_loading_func, -1);
1090namespace_user_loading_func_calling_super(
VALUE arg)
1097namespace_user_loading_func_ensure(
VALUE arg)
1100 rb_namespace_pop_loading_namespace(ns);
1105rb_namespace_user_loading_func(
int argc,
VALUE *argv,
VALUE _self)
1109 if (!vm->require_stack)
1110 rb_bug(
"require_stack is not ready but require/load is called in user namespaces");
1111 ns = rb_current_namespace();
1112 VM_ASSERT(rb_namespace_available() || !ns);
1113 rb_namespace_push_loading_namespace(ns);
1118 return rb_ensure(namespace_user_loading_func_calling_super, (
VALUE)&data,
1119 namespace_user_loading_func_ensure, (
VALUE)ns);
1123setup_pushing_loading_namespace_include(
VALUE mod)
1132 rb_namespace_exec(ns, setup_pushing_loading_namespace_include, rb_mNamespaceLoader);
1136namespace_define_loader_method(
const char *name)
1145 tmp_dir = system_tmpdir();
1146 tmp_dir_has_dirsep = (strcmp(tmp_dir + (strlen(tmp_dir) - strlen(DIRSEP)), DIRSEP) == 0);
1155 if (rb_namespace_available()) {
1160 namespace_define_loader_method(
"require");
1161 namespace_define_loader_method(
"require_relative");
1162 namespace_define_loader_method(
"load");
1177 vm->require_stack = rb_ary_new();
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
Ruby-level global variables / constants, visible from C.
void rb_include_module(VALUE klass, VALUE module)
Includes a module to a class.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_define_module_under(VALUE outer, const char *name)
Defines a module under the namespace of outer.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
#define xmalloc
Old name of ruby_xmalloc.
#define LONG2NUM
Old name of RB_LONG2NUM.
#define Qtrue
Old name of RUBY_Qtrue.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define NIL_P
Old name of RB_NIL_P.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define CONST_ID
Old name of RUBY_CONST_ID.
void rb_category_warn(rb_warning_category_t category, const char *fmt,...)
Identical to rb_category_warning(), except it reports unless $VERBOSE is nil.
VALUE rb_eLoadError
LoadError exception.
VALUE rb_eRuntimeError
RuntimeError exception.
@ RB_WARN_CATEGORY_EXPERIMENTAL
Warning is for experimental features.
VALUE rb_mKernel
Kernel module.
VALUE rb_cNamespace
Namespace class.
VALUE rb_class_new_instance_pass_kw(int argc, const VALUE *argv, VALUE klass)
Identical to rb_class_new_instance(), except it passes the passed keywords if any to the #initialize ...
VALUE rb_cModule
Module class.
VALUE rb_mNamespaceRefiner
Namespace::Refiner module.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_call_super(int argc, const VALUE *argv)
This resembles ruby's super.
VALUE rb_require_string(VALUE feature)
Finds and loads the given feature, if absent.
VALUE rb_str_concat(VALUE dst, VALUE src)
Identical to rb_str_append(), except it also accepts an integer as a codepoint.
#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_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
void rb_const_set(VALUE space, ID name, VALUE val)
Names a constant.
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
int len
Length of the buffer.
char * ruby_strdup(const char *str)
This is our own version of strdup(3) that uses ruby_xmalloc() instead of system malloc (benefits our ...
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE rb_ensure(type *q, VALUE w, type *e, VALUE r)
An equivalent of ensure clause.
#define PRI_PIDT_PREFIX
A rb_sprintf() format prefix to be used for a pid_t parameter.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define TypedData_Get_Struct(obj, type, data_type, sval)
Obtains a C struct from inside of a wrapper Ruby object.
#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...
#define RTEST
This is an old name of RB_TEST.
#define _(args)
This was a transition path from K&R to ANSI.
This is the struct that holds necessary info for a struct.
const rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
Internal header for Namespace.
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.