ruby-changes:68362
From: Nobuyoshi <ko1@a...>
Date: Sun, 10 Oct 2021 23:34:33 +0900 (JST)
Subject: [ruby-changes:68362] a4876a563d (master): Pass the VM pointer as an argument
https://git.ruby-lang.org/ruby.git/commit/?id=a4876a563d From a4876a563d6c8011914504e186de8173f481e543 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 17 Sep 2021 01:20:10 +0900 Subject: Pass the VM pointer as an argument --- load.c | 157 ++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 83 insertions(+), 74 deletions(-) diff --git a/load.c b/load.c index 41e706b144..58f71b9d22 100644 --- a/load.c +++ b/load.c @@ -46,9 +46,8 @@ enum expand_type { https://github.com/ruby/ruby/blob/trunk/load.c#L46 string objects in $LOAD_PATH are frozen. */ static void -rb_construct_expanded_load_path(enum expand_type type, int *has_relative, int *has_non_cache) +rb_construct_expanded_load_path(rb_vm_t *vm, enum expand_type type, int *has_relative, int *has_non_cache) { - rb_vm_t *vm = GET_VM(); VALUE load_path = vm->load_path; VALUE expanded_load_path = vm->expanded_load_path; VALUE ary; @@ -93,16 +92,15 @@ rb_construct_expanded_load_path(enum expand_type type, int *has_relative, int *h https://github.com/ruby/ruby/blob/trunk/load.c#L92 rb_ary_replace(vm->load_path_snapshot, vm->load_path); } -VALUE -rb_get_expanded_load_path(void) +static VALUE +get_expanded_load_path(rb_vm_t *vm) { - rb_vm_t *vm = GET_VM(); const VALUE non_cache = Qtrue; if (!rb_ary_shared_with_p(vm->load_path_snapshot, vm->load_path)) { /* The load path was modified. Rebuild the expanded load path. */ int has_relative = 0, has_non_cache = 0; - rb_construct_expanded_load_path(EXPAND_ALL, &has_relative, &has_non_cache); + rb_construct_expanded_load_path(vm, EXPAND_ALL, &has_relative, &has_non_cache); if (has_relative) { vm->load_path_check_cache = rb_dir_getwd_ospath(); } @@ -117,7 +115,7 @@ rb_get_expanded_load_path(void) https://github.com/ruby/ruby/blob/trunk/load.c#L115 else if (vm->load_path_check_cache == non_cache) { int has_relative = 1, has_non_cache = 1; /* Expand only non-cacheable objects. */ - rb_construct_expanded_load_path(EXPAND_NON_CACHE, + rb_construct_expanded_load_path(vm, EXPAND_NON_CACHE, &has_relative, &has_non_cache); } else if (vm->load_path_check_cache) { @@ -127,18 +125,24 @@ rb_get_expanded_load_path(void) https://github.com/ruby/ruby/blob/trunk/load.c#L125 /* Current working directory or filesystem encoding was changed. Expand relative load path and non-cacheable objects again. */ vm->load_path_check_cache = cwd; - rb_construct_expanded_load_path(EXPAND_RELATIVE, + rb_construct_expanded_load_path(vm, EXPAND_RELATIVE, &has_relative, &has_non_cache); } else { /* Expand only tilde (User HOME) and non-cacheable objects. */ - rb_construct_expanded_load_path(EXPAND_HOME, + rb_construct_expanded_load_path(vm, EXPAND_HOME, &has_relative, &has_non_cache); } } return vm->expanded_load_path; } +VALUE +rb_get_expanded_load_path(void) +{ + return get_expanded_load_path(GET_VM()); +} + static VALUE load_path_getter(ID id, VALUE * p) { @@ -147,40 +151,39 @@ load_path_getter(ID id, VALUE * p) https://github.com/ruby/ruby/blob/trunk/load.c#L151 } static VALUE -get_loaded_features(void) +get_loaded_features(rb_vm_t *vm) { - return GET_VM()->loaded_features; + return vm->loaded_features; } static VALUE -get_loaded_features_realpaths(void) +get_loaded_features_realpaths(rb_vm_t *vm) { - return GET_VM()->loaded_features_realpaths; + return vm->loaded_features_realpaths; } static VALUE get_LOADED_FEATURES(ID _x, VALUE *_y) { - return get_loaded_features(); + return get_loaded_features(GET_VM()); } static void -reset_loaded_features_snapshot(void) +reset_loaded_features_snapshot(rb_vm_t *vm) { - rb_vm_t *vm = GET_VM(); rb_ary_replace(vm->loaded_features_snapshot, vm->loaded_features); } static struct st_table * -get_loaded_features_index_raw(void) +get_loaded_features_index_raw(rb_vm_t *vm) { - return GET_VM()->loaded_features_index; + return vm->loaded_features_index; } static st_table * -get_loading_table(void) +get_loading_table(rb_vm_t *vm) { - return GET_VM()->loading_table; + return vm->loading_table; } static st_data_t @@ -199,7 +202,7 @@ is_rbext_path(VALUE feature_path) https://github.com/ruby/ruby/blob/trunk/load.c#L202 } static void -features_index_add_single(const char* str, size_t len, VALUE offset, bool rb) +features_index_add_single(rb_vm_t *vm, const char* str, size_t len, VALUE offset, bool rb) { struct st_table *features_index; VALUE this_feature_index = Qnil; @@ -209,13 +212,13 @@ features_index_add_single(const char* str, size_t len, VALUE offset, bool rb) https://github.com/ruby/ruby/blob/trunk/load.c#L212 Check_Type(offset, T_FIXNUM); short_feature_key = feature_key(str, len); - features_index = get_loaded_features_index_raw(); + features_index = get_loaded_features_index_raw(vm); if (!st_lookup(features_index, short_feature_key, &data) || NIL_P(this_feature_index = (VALUE)data)) { st_insert(features_index, short_feature_key, (st_data_t)offset); } else if (FIXNUM_P(this_feature_index)) { - VALUE loaded_features = get_loaded_features(); + VALUE loaded_features = get_loaded_features(vm); VALUE this_feature_path = RARRAY_AREF(loaded_features, FIX2LONG(this_feature_index)); VALUE feature_indexes[2]; int top = (rb && !is_rbext_path(this_feature_path)) ? 1 : 0; @@ -231,7 +234,7 @@ features_index_add_single(const char* str, size_t len, VALUE offset, bool rb) https://github.com/ruby/ruby/blob/trunk/load.c#L234 Check_Type(this_feature_index, T_ARRAY); if (rb) { - VALUE loaded_features = get_loaded_features(); + VALUE loaded_features = get_loaded_features(vm); for (long i = 0; i < RARRAY_LEN(this_feature_index); ++i) { VALUE idx = RARRAY_AREF(this_feature_index, i); VALUE this_feature_path = RARRAY_AREF(loaded_features, FIX2LONG(idx)); @@ -264,7 +267,7 @@ features_index_add_single(const char* str, size_t len, VALUE offset, bool rb) https://github.com/ruby/ruby/blob/trunk/load.c#L267 relies on for its fast lookup. */ static void -features_index_add(VALUE feature, VALUE offset) +features_index_add(rb_vm_t *vm, VALUE feature, VALUE offset) { const char *feature_str, *feature_end, *ext, *p; bool rb = false; @@ -290,14 +293,14 @@ features_index_add(VALUE feature, VALUE offset) https://github.com/ruby/ruby/blob/trunk/load.c#L293 if (p < feature_str) break; /* Now *p == '/'. We reach this point for every '/' in `feature`. */ - features_index_add_single(p + 1, feature_end - p - 1, offset, false); + features_index_add_single(vm, p + 1, feature_end - p - 1, offset, false); if (ext) { - features_index_add_single(p + 1, ext - p - 1, offset, rb); + features_index_add_single(vm, p + 1, ext - p - 1, offset, rb); } } - features_index_add_single(feature_str, feature_end - feature_str, offset, false); + features_index_add_single(vm, feature_str, feature_end - feature_str, offset, false); if (ext) { - features_index_add_single(feature_str, ext - feature_str, offset, rb); + features_index_add_single(vm, feature_str, ext - feature_str, offset, rb); } } @@ -313,11 +316,10 @@ loaded_features_index_clear_i(st_data_t key, st_data_t val, st_data_t arg) https://github.com/ruby/ruby/blob/trunk/load.c#L316 } static st_table * -get_loaded_features_index(void) +get_loaded_features_index(rb_vm_t *vm) { VALUE features; int i; - rb_vm_t *vm = GET_VM(); if (!rb_ary_shared_with_p(vm->loaded_features_snapshot, vm->loaded_features)) { /* The sharing was broken; something (other than us in rb_provide_feature()) @@ -334,9 +336,9 @@ get_loaded_features_index(void) https://github.com/ruby/ruby/blob/trunk/load.c#L336 as_str = rb_fstring(rb_str_freeze(as_str)); if (as_str != entry) rb_ary_store(features, i, as_str); - features_index_add(as_str, INT2FIX(i)); + features_index_add(vm, as_str, INT2FIX(i)); } - reset_loaded_features_snapshot(); + reset_loaded_features_snapshot(vm); features = rb_ary_dup(vm->loaded_features_snapshot); long j = RARRAY_LEN(features); @@ -426,7 +428,7 @@ loaded_feature_path_i(st_data_t v, st_data_t b, st_data_t f) https://github.com/ruby/ruby/blob/trunk/load.c#L428 } static int -rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const char **fn) +rb_feature_p(rb_vm_t *vm, const char *feature, const char *ext, int rb, int expanded, const char **fn) { VALUE features, this_feature_index = Qnil, v, p, load_path = 0; const char *f, *e; @@ -447,8 +449,8 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const c https://github.com/ruby/ruby/blob/trunk/load.c#L449 elen = 0; type = 0; } - features = get_loaded_features(); - features_index = get_loaded_features_index(); + features = get_loaded_features(vm); + features_index = get_loaded_features_index(vm); key = feature_key(feature, strlen(feature)); /* We search `features` for an entry such that either @@ -496,7 +498,7 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const c https://github.com/ruby/ruby/blob/trunk/load.c#L498 if ((n = RSTRING_LEN(v)) < len) continue; if (strncmp(f, feature, len) != 0) { if (expanded) continue; - if (!load_path) load_path = rb_get_expanded_load_path(); + if (!load_path) load_path = get_expanded_load_path(vm); if (!(p = loaded_feature_path(f, n, feature, len, type, load_path))) continue; expanded = 1; @@ -516,14 +518,14 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const c https://github.com/ruby/ruby/blob/trunk/load.c#L518 } } - loading_tbl = get_loading_table(); + loading_tbl = get_loading_table(vm); f = 0; if (!expanded) { struct loaded_feature_ (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/