Ruby: internal/box.h Source File

Ruby 4.0.5p0 (2026-05-20 revision 64336ffd0ee9e1f4c05891695a3d7b49cb709721)

box.h
1#ifndef INTERNAL_BOX_H /*-*-C-*-vi:se ft=c:*/
2#define INTERNAL_BOX_H
3
4#include "ruby/ruby.h" /* for VALUE */
5
14 struct rb_box_struct {
15 /*
16 * To retrieve Ruby::Box object that provides #require and so on.
17 * That is used from load.c, etc., that uses rb_box_t internally.
18 */
19 VALUE box_object;
20 long box_id; // box_id to generate ext filenames
21
22 VALUE top_self;
23
24 VALUE load_path;
25 VALUE load_path_snapshot;
26 VALUE load_path_check_cache;
27 VALUE expanded_load_path;
28 VALUE loaded_features;
29 VALUE loaded_features_snapshot;
30 VALUE loaded_features_realpaths;
31 VALUE loaded_features_realpath_map;
32 struct st_table *loaded_features_index;
33 struct st_table *loading_table;
34 VALUE ruby_dln_libmap;
35
36 VALUE gvar_tbl;
37 struct st_table *classext_cow_classes;
38
39 bool is_user;
40 bool is_optional;
41};
42typedef struct rb_box_struct rb_box_t;
43
44#define BOX_OBJ_P(obj) (rb_obj_class(obj) == rb_cBox)
45
46#define BOX_ROOT_P(box) (box && !box->is_user)
47#define BOX_USER_P(box) (box && box->is_user)
48#define BOX_OPTIONAL_P(box) (box && box->is_optional)
49#define BOX_MAIN_P(box) (box && box->is_user && !box->is_optional)
50
51#define BOX_METHOD_DEFINITION(mdef) (mdef ? mdef->ns : NULL)
52#define BOX_METHOD_ENTRY(me) (me ? BOX_METHOD_DEFINITION(me->def) : NULL)
53#define BOX_CC(cc) (cc ? BOX_METHOD_ENTRY(cc->cme_) : NULL)
54#define BOX_CC_ENTRIES(ccs) (ccs ? BOX_METHOD_ENTRY(ccs->cme) : NULL)
55
56 RUBY_EXTERN bool ruby_box_enabled;
57 RUBY_EXTERN bool ruby_box_init_done;
58 RUBY_EXTERN bool ruby_box_crashed;
59
60static inline bool
61rb_box_available(void)
62{
63 return ruby_box_enabled;
64}
65
66const rb_box_t * rb_root_box(void);
67const rb_box_t * rb_main_box(void);
68const rb_box_t * rb_current_box(void);
69const rb_box_t * rb_loading_box(void);
70const rb_box_t * rb_current_box_in_crash_report(void);
71
72void rb_box_entry_mark(void *);
73void rb_box_gc_update_references(void *ptr);
74
75rb_box_t * rb_get_box_t(VALUE ns);
76 VALUE rb_get_box_object(rb_box_t *ns);
77
78 VALUE rb_box_local_extension(VALUE box, VALUE fname, VALUE path, VALUE *cleanup);
79void rb_box_cleanup_local_extension(VALUE cleanup);
80
81void rb_initialize_main_box(void);
82void rb_box_init_done(void);
83#endif /* INTERNAL_BOX_H */
RUBY_EXTERN
#define RUBY_EXTERN
Declaration of externally visible global variables.
Definition dllexport.h:45
ruby.h
rb_box_struct
Internal header for Ruby Box.
Definition box.h:14
st_table
Definition st.h:79
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40