Merge pull request #5945 from dearblue/env-internal

Avoid exposure for `REnv` objects
This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-03-11 16:18:28 +09:00
committed by GitHub
5 changed files with 45 additions and 22 deletions
+36 -2
View File
@@ -136,12 +136,46 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx);
MRB_API mrb_value mrb_load_proc(mrb_state *mrb, const struct RProc *proc);
/**
* It can be used to isolate top-level scopes referenced by blocks generated by
* `mrb_load_string_cxt()` or similar called before entering the mruby VM (e.g. from `main()`).
* In that case, the `ci` parameter should be `mrb->c->cibase`.
*
* #include <mruby.h>
* #include <mruby/compile.h>
* #include <mruby/proc.h>
*
* int
* main(int argc, char **argv)
* {
* mrb_state *mrb;
* mrbc_context *cxt;
* mrb_value blk, ret;
*
* mrb = mrb_open();
* cxt = mrbc_context_new(mrb);
* blk = mrb_load_string_cxt(mrb, "x, y, z = 1, 2, 3; proc { [x, y, z] }", cxt);
* mrb_vm_ci_env_clear(mrb, mrb->c->cibase);
* mrb_load_string_cxt(mrb, "x, y, z = 4, 5, 6", cxt);
* ret = mrb_funcall(mrb, blk, "call", 0);
* mrb_p(mrb, ret); // => [1, 2, 3]
* // => [4, 5, 6] if `mrb_vm_ci_env_clear()` is commented out
* mrbc_context_free(mrb, cxt);
* mrb_close(mrb);
*
* return 0;
* }
*
* The top-level local variable names stored in `mrbc_context` are retained.
* Use also `mrbc_cleanup_local_variables()` at the same time, if necessary.
*/
MRB_API void mrb_vm_ci_env_clear(mrb_state *mrb, mrb_callinfo *ci);
void mrb_vm_ci_proc_set(mrb_callinfo *ci, const struct RProc *p);
struct RClass * mrb_vm_ci_target_class(const mrb_callinfo *ci);
void mrb_vm_ci_target_class_set(mrb_callinfo *ci, struct RClass *tc);
struct REnv * mrb_vm_ci_env(const mrb_callinfo *ci);
MRB_API void mrb_vm_ci_env_clear(mrb_callinfo *ci);
MRB_API void mrb_vm_ci_env_set(mrb_callinfo *ci, struct REnv *e);
void mrb_vm_ci_env_set(mrb_callinfo *ci, struct REnv *e);
MRB_END_DECL