rubygem-bootsnap/fix-no-implicit-conversion-of-String-into-Integer.patch

61 lines
2.1 KiB
Diff

From 97dd9c266fbaac188d39f7d545aa54aef80c3070 Mon Sep 17 00:00:00 2001
From: wu-leilei <wu18740459704@163.com>
Date: Thu, 27 Jan 2022 09:35:50 +0800
Subject: [PATCH] test 3
---
ext/bootsnap/bootsnap.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/ext/bootsnap/bootsnap.c b/ext/bootsnap/bootsnap.c
index e0c5307..d29219a 100644
--- a/ext/bootsnap/bootsnap.c
+++ b/ext/bootsnap/bootsnap.c
@@ -94,6 +94,7 @@ static int cache_key_equal(struct bs_cache_key * k1, struct bs_cache_key * k2);
static VALUE bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler);
static int open_current_file(char * path, struct bs_cache_key * key, char ** errno_provenance);
static int fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE * output_data, int * exception_tag, char ** errno_provenance);
+static uint32_t get_ruby_revision(void);
static uint32_t get_ruby_platform(void);
/*
@@ -134,7 +135,7 @@ Init_bootsnap(void)
rb_mBootsnap_CompileCache_Native = rb_define_module_under(rb_mBootsnap_CompileCache, "Native");
rb_eBootsnap_CompileCache_Uncompilable = rb_define_class_under(rb_mBootsnap_CompileCache, "Uncompilable", rb_eStandardError);
- current_ruby_revision = FIX2INT(rb_const_get(rb_cObject, rb_intern("RUBY_REVISION")));
+ current_ruby_revision = get_ruby_revision();
current_ruby_platform = get_ruby_platform();
uncompilable = rb_intern("__bootsnap_uncompilable__");
@@ -191,6 +192,26 @@ fnv1a_64(const char *str)
return fnv1a_64_iter(h, str);
}
+/*
+ * Ruby's revision may be Integer or String. CRuby 2.7 or later uses
+ * Git commit ID as revision. It's String.
+ */
+static uint32_t
+get_ruby_revision(void)
+{
+ VALUE ruby_revision;
+
+ ruby_revision = rb_const_get(rb_cObject, rb_intern("RUBY_REVISION"));
+ if (RB_TYPE_P(ruby_revision, RUBY_T_FIXNUM)) {
+ return FIX2INT(ruby_revision);
+ } else {
+ uint64_t hash;
+
+ hash = fnv1a_64(StringValueCStr(ruby_revision));
+ return (uint32_t)(hash >> 32);
+ }
+}
+
/*
* When ruby's version doesn't change, but it's recompiled on a different OS
* (or OS version), we need to invalidate the cache.
--
2.23.0