diff options
author | Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> | 2023-01-31 12:18:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-31 12:18:41 -0500 |
commit | 4ce642620f10ae18171b41e166aaad3944ef482a (patch) | |
tree | 2b8f04b8d50dabd35e4ca53fe5d163217ef3c608 /ruby.c | |
parent | 74e52c2a1723320423a776187cdf6360b7f44281 (diff) |
Make sure RUBY_YJIT_ENABLE only enables YJIT for truthy values (#7208)
* Make sure RUBY_YJIT_ENABLE only enables YJIT for truthy values
Addresses bug reported in: https://github.com/Shopify/yjit/issues/309
* Update ruby.c
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
---------
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Notes
Notes:
Merged-By: maximecb <maximecb@ruby-lang.org>
Diffstat (limited to 'ruby.c')
-rw-r--r-- | ruby.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -1798,6 +1798,24 @@ copy_str(VALUE str, rb_encoding *enc, bool intern) return rb_enc_interned_str(RSTRING_PTR(str), RSTRING_LEN(str), enc); } +// Check that an environment variable is set to a truthy value +static bool +env_var_truthy(const char *name) +{ + const char *value = getenv(name); + + if (!value) + return false; + if (strcmp(value, "1") == 0) + return true; + if (strcmp(value, "true") == 0) + return true; + if (strcmp(value, "yes") == 0) + return true; + + return false; +} + static VALUE process_options(int argc, char **argv, ruby_cmdline_options_t *opt) { @@ -1907,7 +1925,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) if (!(FEATURE_SET_BITS(opt->features) & feature_jit_mask)) { #if USE_YJIT - if (!FEATURE_USED_P(opt->features, yjit) && getenv("RUBY_YJIT_ENABLE")) { + if (!FEATURE_USED_P(opt->features, yjit) && env_var_truthy("RUBY_YJIT_ENABLE")) { FEATURE_SET(opt->features, FEATURE_BIT(yjit)); } #endif |