summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>2023-01-31 12:18:41 -0500
committerGitHub <noreply@github.com>2023-01-31 12:18:41 -0500
commit4ce642620f10ae18171b41e166aaad3944ef482a (patch)
tree2b8f04b8d50dabd35e4ca53fe5d163217ef3c608 /ruby.c
parent74e52c2a1723320423a776187cdf6360b7f44281 (diff)
downloadruby-4ce642620f10ae18171b41e166aaad3944ef482a.tar.gz
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>
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/ruby.c b/ruby.c
index c27f44edb3..a63cd4d24a 100644
--- a/ruby.c
+++ b/ruby.c
@@ -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