Skip to content

Commit a981f5a

Browse files
committed
Add more const qualifier for RProc
1 parent ab3abdf commit a981f5a

File tree

8 files changed

+36
-35
lines changed

8 files changed

+36
-35
lines changed

include/mruby.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ typedef struct {
234234
uint32_t flags; /* compatible with mt keys in class.c */
235235

236236
union {
237-
struct RProc *proc;
237+
const struct RProc *proc;
238238
mrb_func_t func;
239239
} as;
240240
} mrb_method_t;

include/mruby/internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ int mrb_rational_mark(mrb_state *mrb, struct RBasic *rat);
132132

133133
#ifdef MRUBY_PROC_H
134134
struct RProc *mrb_closure_new(mrb_state*, const mrb_irep*);
135-
void mrb_proc_copy(mrb_state *mrb, struct RProc *a, struct RProc *b);
135+
void mrb_proc_copy(mrb_state *mrb, struct RProc *a, const struct RProc *b);
136136
mrb_int mrb_proc_arity(const struct RProc *p);
137137
struct REnv *mrb_env_new(mrb_state *mrb, struct mrb_context *c, mrb_callinfo *ci, int nstacks, mrb_value *stack, struct RClass *tc);
138138
void mrb_proc_merge_lvar(mrb_state *mrb, mrb_irep *irep, struct REnv *env, int num, const mrb_sym *lv, const mrb_value *stack);
139139
mrb_value mrb_proc_local_variables(mrb_state *mrb, const struct RProc *proc);
140140
const struct RProc *mrb_proc_get_caller(mrb_state *mrb, struct REnv **env);
141-
mrb_value mrb_proc_get_self(mrb_state *mrb, struct RProc *p, struct RClass **target_class_p);
141+
mrb_value mrb_proc_get_self(mrb_state *mrb, const struct RProc *p, struct RClass **target_class_p);
142142
mrb_bool mrb_proc_eql(mrb_state *mrb, mrb_value self, mrb_value other);
143143
#endif
144144

@@ -192,7 +192,7 @@ void mrb_gc_free_iv(mrb_state*, struct RObject*);
192192
/* VM */
193193
mrb_int mrb_ci_bidx(mrb_callinfo *ci);
194194
mrb_int mrb_ci_nregs(mrb_callinfo *ci);
195-
mrb_value mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p);
195+
mrb_value mrb_exec_irep(mrb_state *mrb, mrb_value self, const struct RProc *p);
196196
mrb_value mrb_obj_instance_eval(mrb_state*, mrb_value);
197197
mrb_value mrb_object_exec(mrb_state *mrb, mrb_value self, struct RClass *target_class);
198198
mrb_value mrb_mod_module_eval(mrb_state*, mrb_value);

include/mruby/proc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx);
119119
#define MRB_METHOD_FUNC(m) ((m).as.func)
120120
#define MRB_METHOD_NOARG_SET(m) do{(m).flags|=MRB_METHOD_NOARG_FL;}while(0)
121121
#define MRB_METHOD_FROM_FUNC(m,fn) do{(m).flags=MRB_METHOD_FUNC_FL;(m).as.func=(fn);}while(0)
122-
#define MRB_METHOD_FROM_PROC(m,pr) do{(m).flags=0;(m).as.proc=(struct RProc*)(pr);}while(0)
122+
#define MRB_METHOD_FROM_PROC(m,pr) do{(m).flags=0;(m).as.proc=(pr);}while(0)
123123
#define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m))
124124
#define MRB_METHOD_PROC(m) ((m).as.proc)
125125
#define MRB_METHOD_UNDEF_P(m) ((m).as.proc==NULL)

mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ load_file(mrb_state *mrb, struct mrbc_args *args)
258258
}
259259

260260
static int
261-
dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, struct RProc *proc, struct mrbc_args *args)
261+
dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, const struct RProc *proc, struct mrbc_args *args)
262262
{
263263
int n = MRB_DUMP_OK;
264264
const mrb_irep *irep = proc->body.irep;

mrbgems/mruby-method/src/method.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ args_unshift(mrb_state *mrb, mrb_value obj)
6363
mrb_ary_unshift(mrb, *argv, obj);
6464
}
6565

66-
static struct RProc*
66+
static const struct RProc*
6767
method_missing_prepare(mrb_state *mrb, mrb_sym *mid, mrb_value recv, struct RClass **tc)
6868
{
6969
const mrb_sym id_method_missing = MRB_SYM(method_missing);
@@ -83,10 +83,11 @@ method_missing_prepare(mrb_state *mrb, mrb_sym *mid, mrb_value recv, struct RCla
8383
goto method_missing;
8484
}
8585

86-
struct RProc *proc;
86+
const struct RProc *proc;
8787
if (MRB_METHOD_FUNC_P(m)) {
88-
proc = mrb_proc_new_cfunc(mrb, MRB_METHOD_FUNC(m));
89-
MRB_PROC_SET_TARGET_CLASS(proc, *tc);
88+
struct RProc *p = mrb_proc_new_cfunc(mrb, MRB_METHOD_FUNC(m));
89+
MRB_PROC_SET_TARGET_CLASS(p, *tc);
90+
proc = p;
9091
}
9192
else {
9293
proc = MRB_METHOD_PROC(m);
@@ -104,7 +105,7 @@ method_object_alloc(mrb_state *mrb, struct RClass *mclass)
104105
return MRB_OBJ_ALLOC(mrb, MRB_TT_OBJECT, mclass);
105106
}
106107

107-
static struct RProc*
108+
static const struct RProc*
108109
method_extract_proc(mrb_state *mrb, mrb_value self)
109110
{
110111
mrb_value obj = mrb_iv_get(mrb, self, MRB_SYM(_proc));
@@ -230,7 +231,7 @@ method_eql(mrb_state *mrb, mrb_value self)
230231
static mrb_value
231232
mcall(mrb_state *mrb, mrb_value self, mrb_value recv)
232233
{
233-
struct RProc *proc = method_extract_proc(mrb, self);
234+
const struct RProc *proc = method_extract_proc(mrb, self);
234235
mrb_sym mid = method_extract_mid(mrb, self);
235236
struct RClass *tc = method_extract_owner(mrb, self);
236237

@@ -282,7 +283,7 @@ method_unbind(mrb_state *mrb, mrb_value self)
282283
return mrb_obj_value(ume);
283284
}
284285

285-
static struct RProc *
286+
static const struct RProc *
286287
method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
287288
{
288289
mrb_method_t m = mrb_method_search_vm(mrb, cp, mid);
@@ -320,7 +321,7 @@ method_super_method(mrb_state *mrb, mrb_value self)
320321
super = mrb_class_ptr(owner)->super;
321322
}
322323

323-
struct RProc *proc = method_search_vm(mrb, &super, mrb_symbol(name));
324+
const struct RProc *proc = method_search_vm(mrb, &super, mrb_symbol(name));
324325
if (!proc) return mrb_nil_value();
325326

326327
if (!super) return mrb_nil_value();
@@ -330,7 +331,7 @@ method_super_method(mrb_state *mrb, mrb_value self)
330331
mrb_obj_iv_set(mrb, me, MRB_SYM(_owner), mrb_obj_value(super));
331332
mrb_obj_iv_set(mrb, me, MRB_SYM(_recv), recv);
332333
mrb_obj_iv_set(mrb, me, MRB_SYM(_name), name);
333-
mrb_obj_iv_set(mrb, me, MRB_SYM(_proc), mrb_obj_value(proc));
334+
mrb_obj_iv_set(mrb, me, MRB_SYM(_proc), mrb_obj_value((void*)proc));
334335
mrb_obj_iv_set(mrb, me, MRB_SYM(_klass), mrb_obj_value(super));
335336

336337
return mrb_obj_value(me);
@@ -432,7 +433,7 @@ method_to_s(mrb_state *mrb, mrb_value self)
432433
}
433434

434435
static mrb_bool
435-
search_method_owner(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, struct RClass **owner, struct RProc **proc, mrb_bool unbound)
436+
search_method_owner(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, struct RClass **owner, const struct RProc **proc, mrb_bool unbound)
436437
{
437438
*owner = c;
438439
*proc = method_search_vm(mrb, owner, name);
@@ -462,7 +463,7 @@ static mrb_value
462463
method_alloc(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, mrb_bool unbound, mrb_bool singleton)
463464
{
464465
struct RClass *owner;
465-
struct RProc *proc;
466+
const struct RProc *proc;
466467

467468
if (!search_method_owner(mrb, c, obj, name, &owner, &proc, unbound)) {
468469
if (singleton) {
@@ -482,7 +483,7 @@ method_alloc(mrb_state *mrb, struct RClass *c, mrb_value obj, mrb_sym name, mrb_
482483
mrb_obj_iv_set(mrb, me, MRB_SYM(_owner), mrb_obj_value(owner));
483484
mrb_obj_iv_set(mrb, me, MRB_SYM(_recv), unbound ? mrb_nil_value() : obj);
484485
mrb_obj_iv_set(mrb, me, MRB_SYM(_name), mrb_symbol_value(name));
485-
mrb_obj_iv_set(mrb, me, MRB_SYM(_proc), proc ? mrb_obj_value(proc) : mrb_nil_value());
486+
mrb_obj_iv_set(mrb, me, MRB_SYM(_proc), proc ? mrb_obj_value((void*)proc) : mrb_nil_value());
486487
mrb_obj_iv_set(mrb, me, MRB_SYM(_klass), mrb_obj_value(c));
487488

488489
return mrb_obj_value(me);

src/class.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define METHOD_MID(m) MT_KEY_SYM((m).flags)
2323

2424
union mt_ptr {
25-
struct RProc *proc;
25+
const struct RProc *proc;
2626
mrb_func_t func;
2727
};
2828

@@ -285,7 +285,7 @@ mrb_gc_mark_mt(mrb_state *mrb, struct RClass *c)
285285
union mt_ptr *vals = t->ptr;
286286
for (int i=0; i<t->alloc; i++) {
287287
if (MT_KEY_P(keys[i]) && (keys[i] & MT_FUNC) == 0) { /* Proc pointer */
288-
struct RProc *p = vals[i].proc;
288+
const struct RProc *p = vals[i].proc;
289289
mrb_gc_mark(mrb, (struct RBasic*)p);
290290
}
291291
}
@@ -755,7 +755,7 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_method_
755755
}
756756
if (!h) h = c->mt = mt_new(mrb);
757757
if (MRB_METHOD_PROC_P(m)) {
758-
struct RProc *p = MRB_METHOD_PROC(m);
758+
struct RProc *p = (struct RProc*)MRB_METHOD_PROC(m);
759759

760760
ptr.proc = p;
761761
if (p) {
@@ -2217,7 +2217,7 @@ mrb_alias_method(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b)
22172217
mrb_method_t m = mrb_method_search(mrb, c, b);
22182218

22192219
if (!MRB_METHOD_CFUNC_P(m)) {
2220-
struct RProc *p = MRB_METHOD_PROC(m);
2220+
const struct RProc *p = MRB_METHOD_PROC(m);
22212221
if (!MRB_PROC_CFUNC_P(p) && !MRB_PROC_ALIAS_P(p)) {
22222222
struct RProc *pnew = MRB_OBJ_ALLOC(mrb, MRB_TT_PROC, mrb->proc_class);
22232223

src/proc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx)
199199
}
200200

201201
mrb_value
202-
mrb_proc_get_self(mrb_state *mrb, struct RProc *p, struct RClass **target_class_p)
202+
mrb_proc_get_self(mrb_state *mrb, const struct RProc *p, struct RClass **target_class_p)
203203
{
204204
if (MRB_PROC_CFUNC_P(p)) {
205205
*target_class_p = mrb->object_class;
@@ -222,7 +222,7 @@ mrb_proc_get_self(mrb_state *mrb, struct RProc *p, struct RClass **target_class_
222222
}
223223

224224
void
225-
mrb_proc_copy(mrb_state *mrb, struct RProc *a, struct RProc *b)
225+
mrb_proc_copy(mrb_state *mrb, struct RProc *a, const struct RProc *b)
226226
{
227227
if (a->body.irep) {
228228
/* already initialized proc */
@@ -288,8 +288,8 @@ mrb_proc_eql(mrb_state *mrb, mrb_value self, mrb_value other)
288288
if (mrb_type(self) != MRB_TT_PROC) return FALSE;
289289
if (mrb_type(other) != MRB_TT_PROC) return FALSE;
290290

291-
struct RProc *p1 = mrb_proc_ptr(self);
292-
struct RProc *p2 = mrb_proc_ptr(other);
291+
const struct RProc *p1 = mrb_proc_ptr(self);
292+
const struct RProc *p2 = mrb_proc_ptr(other);
293293
if (MRB_PROC_CFUNC_P(p1)) {
294294
if (!MRB_PROC_CFUNC_P(p1)) return FALSE;
295295
if (p1->body.func != p2->body.func) return FALSE;
@@ -308,7 +308,7 @@ proc_eql(mrb_state *mrb, mrb_value self)
308308
static mrb_value
309309
proc_hash(mrb_state *mrb, mrb_value self)
310310
{
311-
struct RProc *p = mrb_proc_ptr(self);
311+
const struct RProc *p = mrb_proc_ptr(self);
312312
return mrb_int_value(mrb, (mrb_int)(((intptr_t)p->body.irep)^MRB_TT_PROC));
313313
}
314314

@@ -325,7 +325,7 @@ static mrb_value
325325
proc_lambda(mrb_state *mrb, mrb_value self)
326326
{
327327
mrb_value blk;
328-
struct RProc *p;
328+
const struct RProc *p;
329329

330330
mrb_get_args(mrb, "&", &blk);
331331
if (mrb_nil_p(blk)) {

src/vm.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ exec_irep(mrb_state *mrb, mrb_value self, const struct RProc *p)
810810
}
811811

812812
mrb_value
813-
mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p)
813+
mrb_exec_irep(mrb_state *mrb, mrb_value self, const struct RProc *p)
814814
{
815815
mrb_callinfo *ci = mrb->c->ci;
816816
if (ci->cci == CINFO_NONE) {
@@ -968,7 +968,7 @@ eval_under(mrb_state *mrb, mrb_value self, mrb_value blk, struct RClass *c)
968968
return mrb_yield_with_class(mrb, blk, 1, &self, self, c);
969969
}
970970
ci->u.target_class = c;
971-
struct RProc *p = mrb_proc_ptr(blk);
971+
const struct RProc *p = mrb_proc_ptr(blk);
972972
/* just in case irep is NULL; #6065 */
973973
if (p->body.irep == NULL) return mrb_nil_value();
974974
CI_PROC_SET(ci, p);
@@ -1053,7 +1053,7 @@ mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value
10531053

10541054
mrb_callinfo *ci = mrb->c->ci;
10551055
mrb_int n = mrb_ci_nregs(ci);
1056-
struct RProc *p = mrb_proc_ptr(b);
1056+
const struct RProc *p = mrb_proc_ptr(b);
10571057
mrb_sym mid;
10581058

10591059
if (MRB_PROC_ENV_P(p)) {
@@ -1087,7 +1087,7 @@ mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value
10871087
MRB_API mrb_value
10881088
mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv)
10891089
{
1090-
struct RProc *p = mrb_proc_ptr(b);
1090+
const struct RProc *p = mrb_proc_ptr(b);
10911091
struct RClass *tc;
10921092
mrb_value self = mrb_proc_get_self(mrb, p, &tc);
10931093

@@ -1097,7 +1097,7 @@ mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv)
10971097
MRB_API mrb_value
10981098
mrb_yield(mrb_state *mrb, mrb_value b, mrb_value arg)
10991099
{
1100-
struct RProc *p = mrb_proc_ptr(b);
1100+
const struct RProc *p = mrb_proc_ptr(b);
11011101
struct RClass *tc;
11021102
mrb_value self = mrb_proc_get_self(mrb, p, &tc);
11031103

@@ -1109,7 +1109,7 @@ mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const
11091109
{
11101110
check_block(mrb, b);
11111111

1112-
struct RProc *p = mrb_proc_ptr(b);
1112+
const struct RProc *p = mrb_proc_ptr(b);
11131113
mrb_callinfo *ci = mrb->c->ci;
11141114

11151115
stack_extend_adjust(mrb, 4, &argv);
@@ -2951,7 +2951,7 @@ mrb_vm_exec(mrb_state *mrb, const struct RProc *begin_proc, const mrb_code *iseq
29512951

29522952
CASE(OP_DEF, BB) {
29532953
struct RClass *target = mrb_class_ptr(regs[a]);
2954-
struct RProc *p = mrb_proc_ptr(regs[a+1]);
2954+
const struct RProc *p = mrb_proc_ptr(regs[a+1]);
29552955
mrb_method_t m;
29562956
mrb_sym mid = irep->syms[b];
29572957

0 commit comments

Comments
 (0)