3#include "eval_intern.h"
5#include "internal/box.h"
6#include "internal/class.h"
7#include "internal/eval.h"
8#include "internal/error.h"
9#include "internal/file.h"
10#include "internal/gc.h"
11#include "internal/hash.h"
12#include "internal/io.h"
13#include "internal/load.h"
14#include "internal/st.h"
15#include "internal/variable.h"
26#ifdef HAVE_SYS_SENDFILE_H
27# include <sys/sendfile.h>
34VALUE rb_cBoxEntry = 0;
35VALUE rb_mBoxLoader = 0;
37static rb_box_t master_box[1];
38static rb_box_t *root_box;
39static rb_box_t *main_box;
41static rb_box_gem_flags_t box_gem_flags[1];
44static bool tmp_dir_has_dirsep;
46#define BOX_TMP_PREFIX "_ruby_box_"
49# define MAXPATHLEN 1024
58bool ruby_box_enabled =
false;
59bool ruby_box_init_done =
false;
60bool ruby_box_crashed =
false;
64static void cleanup_all_local_extensions(
VALUE libmap);
67rb_box_set_gem_flags(rb_box_gem_flags_t *flags)
70 box_gem_flags->gem = flags->gem;
71 box_gem_flags->error_highlight = flags->error_highlight;
72 box_gem_flags->did_you_mean = flags->did_you_mean;
73 box_gem_flags->syntax_suggest = flags->syntax_suggest;
79 ruby_box_init_done =
true;
117 return rb_vm_current_box(GET_EC());
128 return rb_vm_loading_box(GET_EC());
132rb_current_box_in_crash_report(
void)
134 if (ruby_box_crashed)
136 return rb_current_box();
139static long box_id_counter = 0;
146 id = ++box_id_counter;
152box_main_to_s(
VALUE obj)
158box_entry_initialize(rb_box_t *box)
160 const rb_box_t *master = rb_master_box();
169 box->load_path =
rb_ary_dup(master->load_path);
170 box->expanded_load_path =
rb_ary_dup(master->expanded_load_path);
172 box->load_path_check_cache = 0;
173 box->loaded_features =
rb_ary_dup(master->loaded_features);
175 box->loaded_features_index = st_init_numtable();
176 box->loaded_features_realpaths = rb_hash_dup(master->loaded_features_realpaths);
177 box->loaded_features_realpath_map = rb_hash_dup(master->loaded_features_realpath_map);
178 box->loading_table = st_init_strtable();
179 box->ruby_dln_libmap = rb_hash_new_with_size(0);
180 box->gvar_tbl = rb_hash_new_with_size(0);
181 box->classext_cow_classes = st_init_numtable();
184 box->is_optional =
true;
188rb_box_gc_update_references(
void *ptr)
190 rb_box_t *box = (rb_box_t *)ptr;
194 box->box_object = rb_gc_location(box->box_object);
196 box->top_self = rb_gc_location(box->top_self);
197 box->load_path = rb_gc_location(box->load_path);
198 box->expanded_load_path = rb_gc_location(box->expanded_load_path);
199 box->load_path_snapshot = rb_gc_location(box->load_path_snapshot);
200 if (box->load_path_check_cache) {
201 box->load_path_check_cache = rb_gc_location(box->load_path_check_cache);
203 box->loaded_features = rb_gc_location(box->loaded_features);
204 box->loaded_features_snapshot = rb_gc_location(box->loaded_features_snapshot);
205 box->loaded_features_realpaths = rb_gc_location(box->loaded_features_realpaths);
206 box->loaded_features_realpath_map = rb_gc_location(box->loaded_features_realpath_map);
207 box->ruby_dln_libmap = rb_gc_location(box->ruby_dln_libmap);
208 box->gvar_tbl = rb_gc_location(box->gvar_tbl);
212rb_box_entry_mark(
void *ptr)
214 const rb_box_t *box = (rb_box_t *)ptr;
217 rb_gc_mark(box->box_object);
218 rb_gc_mark(box->top_self);
219 rb_gc_mark(box->load_path);
220 rb_gc_mark(box->expanded_load_path);
221 rb_gc_mark(box->load_path_snapshot);
222 rb_gc_mark(box->load_path_check_cache);
223 rb_gc_mark(box->loaded_features);
224 rb_gc_mark(box->loaded_features_snapshot);
225 rb_gc_mark(box->loaded_features_realpaths);
226 rb_gc_mark(box->loaded_features_realpath_map);
227 if (box->loading_table) {
228 rb_mark_tbl(box->loading_table);
230 rb_gc_mark(box->ruby_dln_libmap);
231 rb_gc_mark(box->gvar_tbl);
232 if (box->classext_cow_classes) {
233 rb_mark_set(box->classext_cow_classes);
238free_loading_table_entry(st_data_t key, st_data_t value, st_data_t arg)
245free_loaded_feature_index_i(st_data_t key, st_data_t value, st_data_t arg)
248 rb_darray_free((
void *)value);
254free_box_st_tables(
void *ptr)
256 rb_box_t *box = (rb_box_t *)ptr;
257 if (box->loading_table) {
258 st_foreach(box->loading_table, free_loading_table_entry, 0);
259 st_free_table(box->loading_table);
260 box->loading_table = 0;
263 if (box->loaded_features_index) {
264 st_foreach(box->loaded_features_index, free_loaded_feature_index_i, 0);
265 st_free_table(box->loaded_features_index);
270free_classext_for_box(st_data_t key, st_data_t _value, st_data_t box_arg)
274 const rb_box_t *box = (
const rb_box_t *)box_arg;
277 ext = rb_class_unlink_classext(obj, box);
278 rb_class_classext_free(obj, ext,
false);
281 ext = rb_class_unlink_classext(obj, box);
282 rb_iclass_classext_free(obj, ext,
false);
285 rb_bug(
"Invalid type of object in classext_cow_classes: %s", rb_type_str(
BUILTIN_TYPE(obj)));
291box_entry_free(
void *ptr)
293 const rb_box_t *box = (
const rb_box_t *)ptr;
295 if (box->classext_cow_classes) {
296 st_foreach(box->classext_cow_classes, free_classext_for_box, (st_data_t)box);
299 cleanup_all_local_extensions(box->ruby_dln_libmap);
301 free_box_st_tables(ptr);
306box_entry_memsize(
const void *ptr)
308 size_t size =
sizeof(rb_box_t);
309 const rb_box_t *box = (
const rb_box_t *)ptr;
310 if (box->loaded_features_index) {
311 size += rb_st_memsize(box->loaded_features_index);
313 if (box->loading_table) {
314 size += rb_st_memsize(box->loading_table);
325 rb_box_gc_update_references,
327 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
336 rb_box_gc_update_references,
338 &rb_box_data_type, 0, RUBY_TYPED_FREE_IMMEDIATELY
342rb_box_entry_alloc(
VALUE klass)
346 box_entry_initialize(entry);
351get_box_struct_internal(
VALUE entry)
359rb_get_box_t(
VALUE box)
367 return (rb_box_t *)rb_root_box();
369 VM_ASSERT(BOX_OBJ_P(box));
371 CONST_ID(id_box_entry,
"__box_entry__");
372 entry = rb_attr_get(box, id_box_entry);
373 return get_box_struct_internal(entry);
377rb_get_box_object(rb_box_t *box)
379 VM_ASSERT(box && box->box_object);
380 return box->box_object;
390box_initialize(
VALUE box_value)
393 rb_classext_t *object_classext;
396 CONST_ID(id_box_entry,
"__box_entry__");
398 if (!rb_box_available()) {
399 rb_raise(
rb_eRuntimeError,
"Ruby Box is disabled. Set RUBY_BOX=1 environment variable to use Ruby::Box.");
403 box = get_box_struct_internal(entry);
405 box->box_object = box_value;
406 box->box_id = box_generate_id();
412 RCLASS_SET_PRIME_CLASSEXT_WRITABLE(box_value,
true);
416 object_classext = RCLASS_EXT_WRITABLE_IN_BOX(rb_cObject, box);
417 RCLASS_SET_CONST_TBL(box_value, RCLASSEXT_CONST_TBL(object_classext),
true);
421 if (ruby_box_init_done) {
422 if (box_gem_flags->gem) {
423 rb_vm_call_cfunc_in_box(
Qnil, rb_define_gem_modules, (
VALUE)box_gem_flags,
Qnil,
425 rb_load_gem_prelude((
VALUE)box);
439rb_box_s_getenabled(
VALUE recv)
441 return RBOOL(rb_box_available());
452rb_box_s_current(
VALUE recv)
456 if (!rb_box_available())
459 box = rb_vm_current_box(GET_EC());
460 VM_ASSERT(box && box->box_object);
461 return box->box_object;
471rb_box_load_path(
VALUE box)
473 VM_ASSERT(BOX_OBJ_P(box));
474 return rb_get_box_t(box)->load_path;
478UINT rb_w32_system_tmpdir(WCHAR *path, UINT
len);
483system_default_tmpdir(
void)
487 WCHAR tmppath[_MAX_PATH];
488 UINT
len = rb_w32_system_tmpdir(tmppath, numberof(tmppath));
490 int blen = WideCharToMultiByte(CP_UTF8, 0, tmppath,
len, NULL, 0, NULL, NULL);
491 char *tmpdir =
xmalloc(blen + 1);
492 WideCharToMultiByte(CP_UTF8, 0, tmppath,
len, tmpdir, blen, NULL, NULL);
496#elif defined _CS_DARWIN_USER_TEMP_DIR
497 char path[MAXPATHLEN];
498 size_t len = confstr(_CS_DARWIN_USER_TEMP_DIR, path,
sizeof(path));
501 if (
len >
sizeof(path)) {
502 confstr(_CS_DARWIN_USER_TEMP_DIR, tmpdir,
len);
505 memcpy(tmpdir, path,
len);
514check_tmpdir(
const char *dir)
518 if (!dir)
return FALSE;
519 if (stat(dir, &st))
return FALSE;
521# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
523 if (!S_ISDIR(st.st_mode))
return FALSE;
528 if (st.st_mode & S_IWOTH) {
530 if (!(st.st_mode & S_ISVTX))
return FALSE;
535 if (access(dir, W_OK))
return FALSE;
544# define RETURN_ENV(name) \
545 if (check_tmpdir(tmpdir = getenv(name))) return ruby_strdup(tmpdir)
546 RETURN_ENV(
"TMPDIR");
548 tmpdir = system_default_tmpdir();
549 if (check_tmpdir(tmpdir))
return tmpdir;
557sprint_ext_filename(
char *str,
size_t size,
long box_id,
const char *prefix,
const char *basename)
559 if (tmp_dir_has_dirsep) {
560 return snprintf(str, size,
"%s%sp%"PRI_PIDT_PREFIX"u_%ld_%s", tmp_dir, prefix, getpid(), box_id, basename);
562 return snprintf(str, size,
"%s%s%sp%"PRI_PIDT_PREFIX"u_%ld_%s", tmp_dir, DIRSEP, prefix, getpid(), box_id, basename);
565enum copy_error_type {
570 COPY_ERROR_DST_WRITE,
572 COPY_ERROR_DST_CHMOD,
577copy_ext_file_error(
char *message,
size_t size,
int copy_retvalue)
580 int error = GetLastError();
582 size_t len = snprintf(message, size,
"%d: ", error);
584#define format_message(sublang) FormatMessage(\
585 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
586 NULL, error, MAKELANGID(LANG_NEUTRAL, (sublang)), \
587 message + len, size - len, NULL)
588 if (format_message(SUBLANG_ENGLISH_US) == 0)
589 format_message(SUBLANG_DEFAULT);
590 for (p = message +
len; *p; p++) {
591 if (*p ==
'\n' || *p ==
'\r')
595 switch (copy_retvalue) {
596 case COPY_ERROR_SRC_OPEN:
597 strlcpy(message,
"can't open the extension path", size);
599 case COPY_ERROR_DST_OPEN:
600 strlcpy(message,
"can't open the file to write", size);
602 case COPY_ERROR_SRC_READ:
603 strlcpy(message,
"failed to read the extension path", size);
605 case COPY_ERROR_DST_WRITE:
606 strlcpy(message,
"failed to write the extension path", size);
608 case COPY_ERROR_SRC_STAT:
609 strlcpy(message,
"failed to stat the extension path to copy permissions", size);
611 case COPY_ERROR_DST_CHMOD:
612 strlcpy(message,
"failed to set permissions to the copied extension path", size);
614 case COPY_ERROR_SYSERR:
615 strlcpy(message, strerror(
errno), size);
617 case COPY_ERROR_NONE:
619 rb_bug(
"unknown return value of copy_ext_file: %d", copy_retvalue);
626static enum copy_error_type
627copy_stream(
int src_fd,
int dst_fd)
632 while ((rsize = read(src_fd, buffer,
sizeof(buffer))) != 0) {
633 if (rsize < 0)
return COPY_ERROR_SRC_READ;
634 for (
size_t written = 0; written < (size_t)rsize;) {
635 ssize_t wsize = write(dst_fd, buffer+written, rsize-written);
636 if (wsize < 0)
return COPY_ERROR_DST_WRITE;
637 written += (size_t)wsize;
640 return COPY_ERROR_NONE;
644static enum copy_error_type
645copy_ext_file(
const char *src_path,
const char *dst_path)
648 WCHAR *w_src = rb_w32_mbstr_to_wstr(CP_UTF8, src_path, -1, NULL);
649 WCHAR *w_dst = rb_w32_mbstr_to_wstr(CP_UTF8, dst_path, -1, NULL);
650 if (!w_src || !w_dst) {
656 enum copy_error_type rvalue = CopyFileW(w_src, w_dst, TRUE) ?
657 COPY_ERROR_NONE : COPY_ERROR_SYSERR;
663 const int bin = O_BINARY;
668 const int cloexec = O_CLOEXEC;
670 const int cloexec = 0;
672 const int src_fd = open(src_path, O_RDONLY|cloexec|bin);
673 if (src_fd < 0)
return COPY_ERROR_SRC_OPEN;
674 if (!cloexec) rb_maygvl_fd_fix_cloexec(src_fd);
677 if (fstat(src_fd, &src_st)) {
679 return COPY_ERROR_SRC_STAT;
682 const int dst_fd = open(dst_path, O_WRONLY|O_CREAT|O_EXCL|cloexec|bin, S_IRWXU);
685 return COPY_ERROR_DST_OPEN;
687 if (!cloexec) rb_maygvl_fd_fix_cloexec(dst_fd);
689 enum copy_error_type ret = COPY_ERROR_NONE;
691 if (fchmod(dst_fd, src_st.st_mode & 0777)) {
692 ret = COPY_ERROR_DST_CHMOD;
696 const size_t count_max = (SIZE_MAX >> 1) + 1;
699# ifdef HAVE_COPY_FILE_RANGE
701 ssize_t written = copy_file_range(src_fd, NULL, dst_fd, NULL, count_max, 0);
702 if (written == 0)
goto done;
703 if (written < 0)
break;
706# ifdef HAVE_FCOPYFILE
707 if (fcopyfile(src_fd, dst_fd, NULL, COPYFILE_DATA) == 0) {
713 ssize_t written = sendfile(src_fd, dst_fd, NULL count_max);
714 if (written == 0)
goto done;
715 if (written < 0)
break;
718 ret = copy_stream(src_fd, dst_fd);
722 if (dst_fd >= 0) close(dst_fd);
723 if (ret != COPY_ERROR_NONE) unlink(dst_path);
728#if defined __CYGWIN__ || defined DOSISH
729#define isdirsep(x) ((x) == '/' || (x) == '\\')
731#define isdirsep(x) ((x) == '/')
734#define IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0)
735#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
738fname_without_suffix(
const char *fname,
char *rvalue,
size_t rsize)
740 size_t len = strlen(fname);
742 for (pos = fname +
len; pos > fname; pos--) {
743 if (IS_SOEXT(pos) || IS_DLEXT(pos)) {
747 if (fname +
len - pos > DLEXT_MAXLEN)
break;
749 if (
len > rsize - 1)
len = rsize - 1;
750 memcpy(rvalue, fname,
len);
755escaped_basename(
const char *path,
const char *fname,
char *rvalue,
size_t rsize)
758 const char *leaf = path, *found;
760 while ((found = strstr(leaf + 1, fname)) != NULL) {
763 strlcpy(rvalue, leaf, rsize);
764 for (pos = rvalue; *pos; pos++) {
765 if (isdirsep(*pos)) {
772box_ext_cleanup_mark(
void *p)
774 rb_gc_mark((
VALUE)p);
778box_ext_cleanup_free(
void *p)
781 unlink(RSTRING_PTR(path));
786 {box_ext_cleanup_mark, box_ext_cleanup_free},
787 .flags = RUBY_TYPED_FREE_IMMEDIATELY,
791rb_box_cleanup_local_extension(
VALUE cleanup)
796 if (p) box_ext_cleanup_free(p);
805 HMODULE h = (HMODULE)NUM2PTR(value);
806 WCHAR module_path[MAXPATHLEN];
807 DWORD
len = GetModuleFileNameW(h, module_path, numberof(module_path));
810 if (
len > 0 &&
len < numberof(module_path)) DeleteFileW(module_path);
816cleanup_all_local_extensions(
VALUE libmap)
824 char ext_path[MAXPATHLEN], fname2[MAXPATHLEN], basename[MAXPATHLEN];
826 const char *src_path = RSTRING_PTR(path), *fname_ptr = RSTRING_PTR(fname);
827 rb_box_t *box = rb_get_box_t(box_value);
829 fname_without_suffix(fname_ptr, fname2,
sizeof(fname2));
830 escaped_basename(src_path, fname2, basename,
sizeof(basename));
832 wrote = sprint_ext_filename(ext_path,
sizeof(ext_path), box->box_id, BOX_TMP_PREFIX, basename);
833 if (wrote >= (
int)
sizeof(ext_path)) {
834 rb_bug(
"Extension file path in the box was too long");
838 enum copy_error_type copy_error = copy_ext_file(src_path, ext_path);
841 copy_ext_file_error(message,
sizeof(message), copy_error);
842 rb_raise(
rb_eLoadError,
"can't prepare the extension file for Ruby Box (%s from %"PRIsVALUE
"): %s", ext_path, path, message);
844 DATA_PTR(*cleanup) = (
void *)new_path;
854 rb_vm_frame_flag_set_box_require(GET_EC());
856 return rb_load_entrypoint(fname, wrap);
862 rb_vm_frame_flag_set_box_require(GET_EC());
868rb_box_require_relative(
VALUE box,
VALUE fname)
870 rb_vm_frame_flag_set_box_require(GET_EC());
872 return rb_require_relative_entrypoint(fname);
876initialize_master_box(
void)
878 rb_vm_t *vm = GET_VM();
879 rb_box_t *master = (rb_box_t *)rb_master_box();
884 master->load_path_check_cache = 0;
889 master->loaded_features_index = st_init_numtable();
892 master->loaded_features_realpath_map =
rb_hash_new();
895 master->ruby_dln_libmap = rb_hash_new_with_size(0);
896 master->gvar_tbl = rb_hash_new_with_size(0);
897 master->classext_cow_classes = NULL;
899 vm->master_box = master;
901 if (rb_box_available()) {
902 VALUE master_box, entry;
904 CONST_ID(id_box_entry,
"__box_entry__");
907 RCLASS_SET_PRIME_CLASSEXT_WRITABLE(master_box,
true);
908 RCLASS_SET_CONST_TBL(master_box, RCLASSEXT_CONST_TBL(RCLASS_EXT_PRIME(rb_cObject)),
true);
910 master->box_id = box_generate_id();
911 master->box_object = master_box;
916 rb_gc_register_mark_object(master_box);
917 rb_gc_register_mark_object(entry);
921 master->box_object =
Qnil;
928 const rb_iseq_t *iseq;
936 box = (
const rb_box_t *)rb_get_box_t(box_value);
938 return rb_iseq_eval(iseq, box);
941static int box_experimental_warned = 0;
946box_value_initialize(
bool root,
bool user,
bool optional)
951 VM_ASSERT(BOX_OBJ_P(box_value));
953 box = rb_get_box_t(box_value);
954 box->box_object = box_value;
957 box->is_optional = optional;
962rb_initialize_mandatory_boxes(
void)
964 VALUE root_box_value, main_box_value;
965 rb_vm_t *vm = GET_VM();
967 VM_ASSERT(rb_box_available());
969 if (!box_experimental_warned) {
971 "Ruby::Box is experimental, and the behavior may change in the future!\n"
972 "See https://docs.ruby-lang.org/en/%s/Ruby/Box.html for known issues, etc.",
973 ruby_api_version_name);
974 box_experimental_warned = 1;
977 root_box_value = box_value_initialize(
true,
false,
false);
978 main_box_value = box_value_initialize(
false,
true,
false);
983 vm->root_box = root_box = rb_get_box_t(root_box_value);
984 vm->main_box = main_box = rb_get_box_t(main_box_value);
987 RCLASS_EXT_WRITABLE_IN_BOX(rb_cObject, root_box);
988 RCLASS_EXT_WRITABLE_IN_BOX(rb_cObject, main_box);
992rb_box_inspect(
VALUE obj)
1000 box = rb_get_box_t(obj);
1003 if (BOX_MASTER_P(box)) {
1006 if (BOX_ROOT_P(box)) {
1009 if (BOX_USER_P(box)) {
1012 if (BOX_MAIN_P(box)) {
1015 else if (BOX_OPTIONAL_P(box)) {
1023rb_box_loading_func(
int argc,
VALUE *argv,
VALUE _self)
1025 rb_vm_frame_flag_set_box_require(GET_EC());
1030box_define_loader_method(
const char *name)
1037Init_master_box(
void)
1039 master_box->loading_table = st_init_strtable();
1043Init_enable_box(
void)
1045 const char *env = getenv(
"RUBY_BOX");
1046 if (env && strlen(env) == 1 && env[0] ==
'1') {
1047 ruby_box_enabled =
true;
1050 ruby_box_init_done =
true;
1056rb_box_s_master(
VALUE recv)
1058 return master_box->box_object;
1063rb_box_s_root(
VALUE recv)
1065 return root_box->box_object;
1070rb_box_s_main(
VALUE recv)
1072 return main_box->box_object;
1077rb_box_master_p(
VALUE box_value)
1079 const rb_box_t *box = (
const rb_box_t *)rb_get_box_t(box_value);
1080 return RBOOL(BOX_MASTER_P(box));
1085rb_box_root_p(
VALUE box_value)
1087 const rb_box_t *box = (
const rb_box_t *)rb_get_box_t(box_value);
1088 return RBOOL(BOX_ROOT_P(box));
1093rb_box_main_p(
VALUE box_value)
1095 const rb_box_t *box = (
const rb_box_t *)rb_get_box_t(box_value);
1096 return RBOOL(BOX_MAIN_P(box));
1102classname(
VALUE klass)
1108 p = RCLASSEXT_CLASSPATH(RCLASS_EXT_PRIME(klass));
1110 return RSTRING_PTR(p);
1112 return "AnyClassValue";
1113 return "NonClassValue";
1116static enum rb_id_table_iterator_result
1117dump_classext_methods_i(
ID mid,
VALUE _val,
void *data)
1121 return ID_TABLE_CONTINUE;
1124static enum rb_id_table_iterator_result
1125dump_classext_constants_i(
ID mid,
VALUE _val,
void *data)
1129 return ID_TABLE_CONTINUE;
1133dump_classext_i(rb_classext_t *ext,
bool is_prime,
VALUE _recv,
void *data)
1139 snprintf(buf, 4096,
"Ruby::Box %ld:%s classext %p\n",
1140 RCLASSEXT_BOX(ext)->box_id, is_prime ?
" prime" :
"", (
void *)ext);
1143 snprintf(buf, 2048,
" Super: %s\n", classname(RCLASSEXT_SUPER(ext)));
1146 tbl = RCLASSEXT_M_TBL(ext);
1149 rb_id_table_foreach(RCLASSEXT_M_TBL(ext), dump_classext_methods_i, (
void *)ary);
1151 snprintf(buf, 4096,
" Methods(%ld): ",
RARRAY_LEN(ary));
1160 tbl = RCLASSEXT_CONST_TBL(ext);
1163 rb_id_table_foreach(tbl, dump_classext_constants_i, (
void *)ary);
1165 snprintf(buf, 4096,
" Constants(%ld): ",
RARRAY_LEN(ary));
1195 const rb_classext_t *ext;
1196 const rb_box_t *box;
1197 st_table *classext_tbl;
1200 snprintf(buf, 2048,
"Non-class/module value: %p (%s)\n", (
void *)klass, rb_type_str(
BUILTIN_TYPE(klass)));
1205 snprintf(buf, 2048,
"Class: %p (%s)%s\n",
1206 (
void *)klass, classname(klass), RCLASS_SINGLETON_P(klass) ?
" [singleton]" :
"");
1209 snprintf(buf, 2048,
"Module: %p (%s)\n", (
void *)klass, classname(klass));
1213 ext = RCLASS_EXT_PRIME(klass);
1214 box = RCLASSEXT_BOX(ext);
1215 snprintf(buf, 2048,
"Prime classext box(%ld,%s), readable(%s), writable(%s)\n",
1217 BOX_MASTER_P(box) ?
"master" : (BOX_ROOT_P(box) ?
"root" : (BOX_MAIN_P(box) ?
"main" :
"optional")),
1218 RCLASS_PRIME_CLASSEXT_READABLE_P(klass) ?
"t" :
"f",
1219 RCLASS_PRIME_CLASSEXT_WRITABLE_P(klass) ?
"t" :
"f");
1222 classext_tbl = RCLASS_CLASSEXT_TBL(klass);
1223 if (!classext_tbl) {
1227 snprintf(buf, 2048,
"Non-prime classexts: %zu\n", st_table_size(classext_tbl));
1231 rb_class_classext_foreach(klass, dump_classext_i, (
void *)res);
1247 tmp_dir = system_tmpdir();
1248 tmp_dir_has_dirsep = (strcmp(tmp_dir + (strlen(tmp_dir) - strlen(DIRSEP)), DIRSEP) == 0);
1259 initialize_master_box();
1263 box_define_loader_method(
"require");
1264 box_define_loader_method(
"require_relative");
1265 box_define_loader_method(
"load");
1267 if (rb_box_available()) {
#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.
#define rb_define_global_function(mid, func, arity)
Defines rb_mKernel #mid.
#define RUBY_EXTERN
Declaration of externally visible global variables.
Ruby-level global variables / constants, visible from C.
void rb_include_module(VALUE klass, VALUE module)
Includes a module to a class.
VALUE rb_singleton_class(VALUE obj)
Finds or creates the singleton class of the passed object.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *name)
Defines a top-level module.
VALUE rb_define_module_under(VALUE outer, const char *name)
Defines a module under the namespace of outer.
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
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 rb_str_new2
Old name of rb_str_new_cstr.
#define xfree
Old name of ruby_xfree.
#define xmalloc
Old name of ruby_xmalloc.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define LONG2NUM
Old name of RB_LONG2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define NIL_P
Old name of RB_NIL_P.
#define T_CLASS
Old name of RUBY_T_CLASS.
#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.
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_obj_alloc(VALUE klass)
Allocates an instance of the given class.
VALUE rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
Allocates, then initialises an instance of the given class.
VALUE rb_cBox
Ruby::Box class.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
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_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_call_super(int argc, const VALUE *argv)
This resembles ruby's super.
void rb_memerror(void)
Triggers out-of-memory error.
VALUE rb_ary_dup(VALUE ary)
Duplicates an array.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_new_capa(long capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_hidden_new(long capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_sort_bang(VALUE ary)
Destructively sorts the passed array in-place, according to each elements' <=> result.
VALUE rb_ary_join(VALUE ary, VALUE sep)
Recursively stringises the elements of the passed array, flattens that result, then joins the sequenc...
VALUE rb_hash_new(void)
Creates a new, empty hash object.
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 ...
int st_foreach(st_table *q, int_type *w, st_data_t e)
Iteration over the given table.
void rb_hash_foreach(VALUE q, int_type *w, VALUE e)
Iteration over the given hash.
#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 DATA_PTR(obj)
Convenient getter 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...
#define errno
Ractor-aware version of errno.
#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.