Introduce `MRB_GC_RED`
Replaces the magic number `7` except in `src/gc.c`.
MODIFY
include/mruby/gc.h
include/mruby/gc.h
@@ -87,6 +87,8 @@ typedef struct mrb_gc {
MRB_API mrb_bool
mrb_object_dead_p(struct mrb_state *mrb, struct RBasic *object);
+#define MRB_GC_RED 7
+
MRB_END_DECL
#endif /* MRUBY_GC_H */

MODIFY
mrbgems/mruby-catch/src/catch.c
mrbgems/mruby-catch/src/catch.c
@@ -62,7 +62,7 @@ static const mrb_irep catch_irep = {
};
static const struct RProc catch_proc = {
- NULL, NULL, MRB_TT_PROC, 7 /* GC_RED */, MRB_FL_OBJ_IS_FROZEN | MRB_PROC_SCOPE | MRB_PROC_STRICT,
+ NULL, NULL, MRB_TT_PROC, MRB_GC_RED, MRB_FL_OBJ_IS_FROZEN | MRB_PROC_SCOPE | MRB_PROC_STRICT,
{ &catch_irep }, NULL, { NULL }
};

MODIFY
src/class.c
src/class.c
@@ -736,7 +736,7 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_method_
ptr.proc = p;
if (p) {
- if (p->color != 7 /* GC_RED */) {
+ if (p->color != MRB_GC_RED) {
p->flags |= MRB_PROC_SCOPE;
p->c = NULL;
mrb_field_write_barrier(mrb, (struct RBasic*)c, (struct RBasic*)p);
@@ -2205,7 +2205,7 @@ mrb_alias_method(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b)
if (MRB_PROC_ENV_P(p)) {
MRB_PROC_ENV(p)->mid = b;
}
- else if (p->color != 7 /* GC_RED */) {
+ else if (p->color != MRB_GC_RED) {
struct RClass *tc = MRB_PROC_TARGET_CLASS(p);
struct REnv *e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, NULL);
@@ -2819,7 +2819,7 @@ static const mrb_irep new_irep = {
};
static const struct RProc new_proc = {
- NULL, NULL, MRB_TT_PROC, 7 /* GC_RED */, MRB_FL_OBJ_IS_FROZEN | MRB_PROC_SCOPE | MRB_PROC_STRICT,
+ NULL, NULL, MRB_TT_PROC, MRB_GC_RED, MRB_FL_OBJ_IS_FROZEN | MRB_PROC_SCOPE | MRB_PROC_STRICT,
{ &new_irep }, NULL, { NULL }
};

MODIFY
src/dump.c
src/dump.c
@@ -1344,7 +1344,7 @@ mrb_dump_irep_cstruct(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE
"extern\n"
"#endif",
initname);
- fprintf(fp, "NULL,NULL,MRB_TT_PROC,7,0,{&%s_irep_0},NULL,{NULL},\n}};\n", initname);
+ fprintf(fp, "NULL,NULL,MRB_TT_PROC,MRB_GC_RED,0,{&%s_irep_0},NULL,{NULL},\n}};\n", initname);
fputs("static void\n", fp);
fprintf(fp, "%s_init_syms(mrb_state *mrb)\n", initname);
fputs("{\n", fp);

MODIFY
src/gc.c
src/gc.c
@@ -200,9 +200,10 @@ gettimeofday_time(void)
#define GC_WHITE_A 1
#define GC_WHITE_B (1 << 1)
#define GC_BLACK (1 << 2)
-#define GC_RED 7
+#define GC_RED MRB_GC_RED
#define GC_WHITES (GC_WHITE_A | GC_WHITE_B)
#define GC_COLOR_MASK 7
+mrb_static_assert1(MRB_GC_RED <= GC_COLOR_MASK);
#define paint_gray(o) ((o)->color = GC_GRAY)
#define paint_black(o) ((o)->color = GC_BLACK)

MODIFY
src/proc.c
src/proc.c
@@ -36,7 +36,7 @@ static const mrb_irep call_irep = {
};
static const struct RProc call_proc = {
- NULL, NULL, MRB_TT_PROC, 7 /* GC_RED */, MRB_FL_OBJ_IS_FROZEN | MRB_PROC_SCOPE | MRB_PROC_STRICT,
+ NULL, NULL, MRB_TT_PROC, MRB_GC_RED, MRB_FL_OBJ_IS_FROZEN | MRB_PROC_SCOPE | MRB_PROC_STRICT,
{ &call_irep }, NULL, { NULL }
};
@@ -51,7 +51,7 @@ mrb_proc_new(mrb_state *mrb, const mrb_irep *irep)
struct RClass *tc = NULL;
if (ci->proc) {
- if (ci->proc->color != 7 /* GC_RED */) {
+ if (ci->proc->color != MRB_GC_RED) {
tc = MRB_PROC_TARGET_CLASS(ci->proc);
}
else {

MODIFY
src/vm.c
src/vm.c
@@ -558,7 +558,7 @@ exec_irep_prepare_posthook(mrb_state *mrb, mrb_callinfo *ci, int nregs, mrb_func
0, 0, 0, 0
};
static const struct RProc hook_caller = {
- NULL, NULL, MRB_TT_PROC, 7 /* GC_RED */, MRB_FL_OBJ_IS_FROZEN, { &hook_irep }, NULL, { NULL }
+ NULL, NULL, MRB_TT_PROC, MRB_GC_RED, MRB_FL_OBJ_IS_FROZEN, { &hook_irep }, NULL, { NULL }
};
struct RProc *hook = mrb_proc_new_cfunc(mrb, posthook);

Introduce `MRB_GC_RED`

Replaces the magic number `7` except in `src/gc.c`.