fix no implicit conversion of String into Integer

This commit is contained in:
wu-leilei 2022-01-27 11:35:21 +08:00
parent 9c9602d7cf
commit 068ae4620e
2 changed files with 68 additions and 1 deletions

View File

@ -0,0 +1,60 @@
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

View File

@ -1,12 +1,13 @@
%global gem_name bootsnap
Name: rubygem-%{gem_name}
Version: 1.3.2
Release: 2
Release: 3
Summary: Boot large ruby/rails apps faster
License: MIT
URL: https://github.com/Shopify/bootsnap
Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem
Source1: https://github.com/Shopify/bootsnap/archive/v1.3.2.tar.gz
Patch1: fix-no-implicit-conversion-of-String-into-Integer.patch
BuildRequires: ruby(release) rubygems-devel ruby-devel >= 2.0.0 rubygem(minitest)
BuildRequires: rubygem(mocha) rubygem(msgpack) gcc
ExcludeArch: armv7hl
@ -23,6 +24,7 @@ Documentation for %{name}.
%prep
%setup -q -n %{gem_name}-%{version}
%patch1 -p1
sed -i -e "/^\s*\$CFLAGS / s/^/#/g" \
ext/bootsnap/extconf.rb
@ -43,6 +45,8 @@ rm -rf %{buildroot}%{gem_instdir}/ext/
pushd .%{gem_instdir}
tar xzvf %{SOURCE1}
ln -s %{gem_name}-%{version}/test test
sed -i 'N;38a\ if RUBY_REVISION.is_a?(String)\n exp = [Help.fnv1a_64(RUBY_REVISION) >> 32].pack("L")\n else\n exp = [RUBY_REVISION].pack("L")\n end' bootsnap-1.3.2/test/compile_cache_key_format_test.rb
sed -i '38 d' bootsnap-1.3.2/test/compile_cache_key_format_test.rb
sed -i -e "/require 'bundler/ s/^/#/g" \
-e "/require 'mocha\/minitest/ s/minitest/mini_test/g" \
test/test_helper.rb
@ -78,6 +82,9 @@ popd
%doc %{gem_instdir}/CODE_OF_CONDUCT.md
%changelog
* Wed Jan 27 2022 wulei <wulei@huawei.com> - 1.3.2-3
- fix no implicit conversion of String into Integer
* Tue Sep 8 2020 yanan li <liyanan032@huawei.com> - 1.3.2-2
- fix build fail