bootsnap 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac5be912b9602b8b20f12255208a6a6d0373d64167092e3267b2494376f079f0
4
- data.tar.gz: 5f18b74f0c0670b86d40d4f41df87869ce5f145cbc3d71b64eddcee59b63fe12
3
+ metadata.gz: b8814f0b4b0ea307767f1a2c10ba813cdf2c28748b2175015d73c52f7754574c
4
+ data.tar.gz: 32958adc9d09fc2cff2764efd545e6c3c670a7ca453894f34c2dfae48f7b4467
5
5
  SHA512:
6
- metadata.gz: e7abd18f5a495b63083d5b4ae9b105acc7f80c2813fa2c40594d2d34998037e6f433b91bf9ab24e021ca3d727368e5580972fc48b9382a86d30a45e03c8274f6
7
- data.tar.gz: 87aaef6229c936321f8940a28f453446a75fd2b6935e13872c1aa7455990c579c1f3f1ebea3ec6416e9f1b3af18c0468d2a1cae2bc4fafb44f4a2c972e4f4688
6
+ metadata.gz: 0b8dc0aba09934dc35d6011142b8edcb63043219770993ee9db6117124157001d3f62bc5dd72bad8a9cd9538e90e36f85884262378deea054a38e461b670e211
7
+ data.tar.gz: 1e5f2337755ac7f7f52dc155612d2c76c3b17828f2c775e4dedc606cae3d280a16232a9ae1dbee00987cb5846d64277e37079589c96e3d264aca615318d5ce1e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Unreleased
2
2
 
3
+ * Warn Ruby 2.5 users if they turn ISeq caching on. (#327, #244)
4
+ * Disable ISeq caching for the whole 2.5.x series again.
5
+ * Better handle hashing of Ruby strings. (#318)
6
+
3
7
  # 1.7.0
4
8
 
5
9
  * Fix detection of YAML files in gems.
@@ -105,8 +105,7 @@ static VALUE bs_rb_fetch(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handl
105
105
  static VALUE bs_rb_precompile(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler);
106
106
 
107
107
  /* Helpers */
108
- static uint64_t fnv1a_64(const char *str);
109
- static void bs_cache_path(const char * cachedir, const char * path, char (* cache_path)[MAX_CACHEPATH_SIZE]);
108
+ static void bs_cache_path(const char * cachedir, const VALUE path, char (* cache_path)[MAX_CACHEPATH_SIZE]);
110
109
  static int bs_read_key(int fd, struct bs_cache_key * key);
111
110
  static int cache_key_equal(struct bs_cache_key * k1, struct bs_cache_key * k2);
112
111
  static VALUE bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler, VALUE args);
@@ -211,7 +210,7 @@ bs_compile_option_crc32_set(VALUE self, VALUE crc32_v)
211
210
  * - 32 bits doesn't feel collision-resistant enough; 64 is nice.
212
211
  */
213
212
  static uint64_t
214
- fnv1a_64_iter(uint64_t h, const char *str)
213
+ fnv1a_64_iter_cstr(uint64_t h, const char *str)
215
214
  {
216
215
  unsigned char *s = (unsigned char *)str;
217
216
 
@@ -224,7 +223,21 @@ fnv1a_64_iter(uint64_t h, const char *str)
224
223
  }
225
224
 
226
225
  static uint64_t
227
- fnv1a_64(const char *str)
226
+ fnv1a_64_iter(uint64_t h, const VALUE str)
227
+ {
228
+ unsigned char *s = (unsigned char *)RSTRING_PTR(str);
229
+ unsigned char *str_end = (unsigned char *)RSTRING_PTR(str) + RSTRING_LEN(str);
230
+
231
+ while (s < str_end) {
232
+ h ^= (uint64_t)*s++;
233
+ h += (h << 1) + (h << 4) + (h << 5) + (h << 7) + (h << 8) + (h << 40);
234
+ }
235
+
236
+ return h;
237
+ }
238
+
239
+ static uint64_t
240
+ fnv1a_64(const VALUE str)
228
241
  {
229
242
  uint64_t h = (uint64_t)0xcbf29ce484222325ULL;
230
243
  return fnv1a_64_iter(h, str);
@@ -245,7 +258,7 @@ get_ruby_revision(void)
245
258
  } else {
246
259
  uint64_t hash;
247
260
 
248
- hash = fnv1a_64(StringValueCStr(ruby_revision));
261
+ hash = fnv1a_64(ruby_revision);
249
262
  return (uint32_t)(hash >> 32);
250
263
  }
251
264
  }
@@ -265,19 +278,19 @@ get_ruby_platform(void)
265
278
  VALUE ruby_platform;
266
279
 
267
280
  ruby_platform = rb_const_get(rb_cObject, rb_intern("RUBY_PLATFORM"));
268
- hash = fnv1a_64(RSTRING_PTR(ruby_platform));
281
+ hash = fnv1a_64(ruby_platform);
269
282
 
270
283
  #ifdef _WIN32
271
284
  return (uint32_t)(hash >> 32) ^ (uint32_t)GetVersion();
272
285
  #elif defined(__GLIBC__)
273
- hash = fnv1a_64_iter(hash, gnu_get_libc_version());
286
+ hash = fnv1a_64_iter_cstr(hash, gnu_get_libc_version());
274
287
  return (uint32_t)(hash >> 32);
275
288
  #else
276
289
  struct utsname utsname;
277
290
 
278
291
  /* Not worth crashing if this fails; lose extra cache invalidation potential */
279
292
  if (uname(&utsname) >= 0) {
280
- hash = fnv1a_64_iter(hash, utsname.version);
293
+ hash = fnv1a_64_iter_cstr(hash, utsname.version);
281
294
  }
282
295
 
283
296
  return (uint32_t)(hash >> 32);
@@ -292,13 +305,13 @@ get_ruby_platform(void)
292
305
  * The path will look something like: <cachedir>/12/34567890abcdef
293
306
  */
294
307
  static void
295
- bs_cache_path(const char * cachedir, const char * path, char (* cache_path)[MAX_CACHEPATH_SIZE])
308
+ bs_cache_path(const char * cachedir, const VALUE path, char (* cache_path)[MAX_CACHEPATH_SIZE])
296
309
  {
297
310
  uint64_t hash = fnv1a_64(path);
298
311
  uint8_t first_byte = (hash >> (64 - 8));
299
312
  uint64_t remainder = hash & 0x00ffffffffffffff;
300
313
 
301
- sprintf(*cache_path, "%s/%02x/%014llx", cachedir, first_byte, remainder);
314
+ sprintf(*cache_path, "%s/%02"PRIx8"/%014"PRIx64, cachedir, first_byte, remainder);
302
315
  }
303
316
 
304
317
  /*
@@ -344,7 +357,7 @@ bs_rb_fetch(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler, VALUE arg
344
357
  char cache_path[MAX_CACHEPATH_SIZE];
345
358
 
346
359
  /* generate cache path to cache_path */
347
- bs_cache_path(cachedir, path, &cache_path);
360
+ bs_cache_path(cachedir, path_v, &cache_path);
348
361
 
349
362
  return bs_fetch(path, path_v, cache_path, handler, args);
350
363
  }
@@ -371,7 +384,7 @@ bs_rb_precompile(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler)
371
384
  char cache_path[MAX_CACHEPATH_SIZE];
372
385
 
373
386
  /* generate cache path to cache_path */
374
- bs_cache_path(cachedir, path, &cache_path);
387
+ bs_cache_path(cachedir, path_v, &cache_path);
375
388
 
376
389
  return bs_precompile(path, path_v, cache_path, handler);
377
390
  }
@@ -1,19 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
  require("mkmf")
3
- $CFLAGS << ' -O3 '
4
- $CFLAGS << ' -std=c99'
5
3
 
6
- # ruby.h has some -Wpedantic fails in some cases
7
- # (e.g. https://github.com/Shopify/bootsnap/issues/15)
8
- unless ['0', '', nil].include?(ENV['BOOTSNAP_PEDANTIC'])
9
- $CFLAGS << ' -Wall'
10
- $CFLAGS << ' -Werror'
11
- $CFLAGS << ' -Wextra'
12
- $CFLAGS << ' -Wpedantic'
4
+ if RUBY_ENGINE == 'ruby'
5
+ $CFLAGS << ' -O3 '
6
+ $CFLAGS << ' -std=c99'
13
7
 
14
- $CFLAGS << ' -Wno-unused-parameter' # VALUE self has to be there but we don't care what it is.
15
- $CFLAGS << ' -Wno-keyword-macro' # hiding return
16
- $CFLAGS << ' -Wno-gcc-compat' # ruby.h 2.6.0 on macos 10.14, dunno
17
- end
8
+ # ruby.h has some -Wpedantic fails in some cases
9
+ # (e.g. https://github.com/Shopify/bootsnap/issues/15)
10
+ unless ['0', '', nil].include?(ENV['BOOTSNAP_PEDANTIC'])
11
+ $CFLAGS << ' -Wall'
12
+ $CFLAGS << ' -Werror'
13
+ $CFLAGS << ' -Wextra'
14
+ $CFLAGS << ' -Wpedantic'
15
+
16
+ $CFLAGS << ' -Wno-unused-parameter' # VALUE self has to be there but we don't care what it is.
17
+ $CFLAGS << ' -Wno-keyword-macro' # hiding return
18
+ $CFLAGS << ' -Wno-gcc-compat' # ruby.h 2.6.0 on macos 10.14, dunno
19
+ end
18
20
 
19
- create_makefile("bootsnap/bootsnap")
21
+ create_makefile("bootsnap/bootsnap")
22
+ else
23
+ File.write("Makefile", dummy_makefile($srcdir).join(""))
24
+ end
data/lib/bootsnap.rb CHANGED
@@ -54,6 +54,11 @@ module Bootsnap
54
54
  "If you use Ruby 2.5 or newer this option is useless, if not upgrading is recommended."
55
55
  end
56
56
 
57
+ if compile_cache_iseq && !iseq_cache_supported?
58
+ warn "Ruby 2.5 has a bug that break code tracing when code is loaded from cache. It is recommened " \
59
+ "to turn `compile_cache_iseq` off on Ruby 2.5"
60
+ end
61
+
57
62
  Bootsnap::LoadPathCache.setup(
58
63
  cache_path: cache_dir + '/bootsnap/load-path-cache',
59
64
  development_mode: development_mode,
@@ -66,6 +71,13 @@ module Bootsnap
66
71
  )
67
72
  end
68
73
 
74
+ def self.iseq_cache_supported?
75
+ return @iseq_cache_supported if defined? @iseq_cache_supported
76
+
77
+ ruby_version = Gem::Version.new(RUBY_VERSION)
78
+ @iseq_cache_supported = ruby_version < Gem::Version.new('2.5.0') || ruby_version >= Gem::Version.new('2.6.0')
79
+ end
80
+
69
81
  def self.default_setup
70
82
  env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['ENV']
71
83
  development_mode = ['', nil, 'development'].include?(env)
@@ -92,14 +104,12 @@ module Bootsnap
92
104
  cache_dir = File.join(app_root, 'tmp', 'cache')
93
105
  end
94
106
 
95
- ruby_version = Gem::Version.new(RUBY_VERSION)
96
- iseq_cache_enabled = ruby_version < Gem::Version.new('2.5.0') || ruby_version >= Gem::Version.new('2.5.4')
97
107
 
98
108
  setup(
99
109
  cache_dir: cache_dir,
100
110
  development_mode: development_mode,
101
111
  load_path_cache: !ENV['DISABLE_BOOTSNAP_LOAD_PATH_CACHE'],
102
- compile_cache_iseq: !ENV['DISABLE_BOOTSNAP_COMPILE_CACHE'] && iseq_cache_enabled,
112
+ compile_cache_iseq: !ENV['DISABLE_BOOTSNAP_COMPILE_CACHE'] && iseq_cache_supported?,
103
113
  compile_cache_yaml: !ENV['DISABLE_BOOTSNAP_COMPILE_CACHE'],
104
114
  )
105
115
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Bootsnap
3
- VERSION = "1.7.0"
3
+ VERSION = "1.7.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootsnap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-01 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler