bootsnap 1.4.5 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -0
- data/README.md +46 -15
- data/exe/bootsnap +5 -0
- data/ext/bootsnap/bootsnap.c +230 -76
- data/ext/bootsnap/extconf.rb +1 -0
- data/lib/bootsnap.rb +79 -15
- data/lib/bootsnap/bundler.rb +1 -0
- data/lib/bootsnap/cli.rb +246 -0
- data/lib/bootsnap/cli/worker_pool.rb +131 -0
- data/lib/bootsnap/compile_cache.rb +3 -2
- data/lib/bootsnap/compile_cache/iseq.rb +22 -7
- data/lib/bootsnap/compile_cache/yaml.rb +90 -40
- data/lib/bootsnap/explicit_require.rb +1 -0
- data/lib/bootsnap/load_path_cache.rb +3 -16
- data/lib/bootsnap/load_path_cache/cache.rb +8 -8
- data/lib/bootsnap/load_path_cache/change_observer.rb +2 -1
- data/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb +18 -5
- data/lib/bootsnap/load_path_cache/core_ext/loaded_features.rb +1 -0
- data/lib/bootsnap/load_path_cache/loaded_features_index.rb +33 -10
- data/lib/bootsnap/load_path_cache/path.rb +3 -2
- data/lib/bootsnap/load_path_cache/path_scanner.rb +39 -26
- data/lib/bootsnap/load_path_cache/realpath_cache.rb +5 -5
- data/lib/bootsnap/load_path_cache/store.rb +6 -5
- data/lib/bootsnap/setup.rb +2 -36
- data/lib/bootsnap/version.rb +2 -1
- metadata +15 -29
- data/.github/CODEOWNERS +0 -2
- data/.github/probots.yml +0 -2
- data/.gitignore +0 -17
- data/.rubocop.yml +0 -20
- data/.travis.yml +0 -21
- data/CODE_OF_CONDUCT.md +0 -74
- data/CONTRIBUTING.md +0 -21
- data/Gemfile +0 -8
- data/README.jp.md +0 -231
- data/Rakefile +0 -12
- data/bin/ci +0 -10
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/bin/test-minimal-support +0 -7
- data/bin/testunit +0 -8
- data/bootsnap.gemspec +0 -45
- data/dev.yml +0 -10
- data/lib/bootsnap/load_path_cache/core_ext/active_support.rb +0 -106
- data/shipit.rubygems.yml +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac5be912b9602b8b20f12255208a6a6d0373d64167092e3267b2494376f079f0
|
4
|
+
data.tar.gz: 5f18b74f0c0670b86d40d4f41df87869ce5f145cbc3d71b64eddcee59b63fe12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7abd18f5a495b63083d5b4ae9b105acc7f80c2813fa2c40594d2d34998037e6f433b91bf9ab24e021ca3d727368e5580972fc48b9382a86d30a45e03c8274f6
|
7
|
+
data.tar.gz: 87aaef6229c936321f8940a28f453446a75fd2b6935e13872c1aa7455990c579c1f3f1ebea3ec6416e9f1b3af18c0468d2a1cae2bc4fafb44f4a2c972e4f4688
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,57 @@
|
|
1
|
+
# Unreleased
|
2
|
+
|
3
|
+
# 1.7.0
|
4
|
+
|
5
|
+
* Fix detection of YAML files in gems.
|
6
|
+
* Adds an instrumentation API to monitor cache misses.
|
7
|
+
* Allow to control the behavior of `require 'bootsnap/setup'` using environment variables.
|
8
|
+
* Deprecate the `disable_trace` option.
|
9
|
+
* Deprecate the `ActiveSupport::Dependencies` (AKA Classic autoloader) integration. (#344)
|
10
|
+
|
11
|
+
# 1.6.0
|
12
|
+
|
13
|
+
* Fix a Ruby 2.7/3.0 issue with `YAML.load_file` keyword arguments. (#342)
|
14
|
+
* `bootsnap precompile` CLI use multiple processes to complete faster. (#341)
|
15
|
+
* `bootsnap precompile` CLI also precompile YAML files. (#340)
|
16
|
+
* Changed the load path cache directory from `$BOOTSNAP_CACHE_DIR/bootsnap-load-path-cache` to `$BOOTSNAP_CACHE_DIR/bootsnap/load-path-cache` for ease of use. (#334)
|
17
|
+
* Changed the compile cache directory from `$BOOTSNAP_CACHE_DIR/bootsnap-compile-cache` to `$BOOTSNAP_CACHE_DIR/bootsnap/compile-cache` for ease of use. (#334)
|
18
|
+
|
19
|
+
# 1.5.1
|
20
|
+
|
21
|
+
* Workaround a Ruby bug in InstructionSequence.compile_file. (#332)
|
22
|
+
|
23
|
+
# 1.5.0
|
24
|
+
|
25
|
+
* Add a command line to statically precompile the ISeq cache. (#326)
|
26
|
+
|
27
|
+
# 1.4.9
|
28
|
+
|
29
|
+
* [Windows support](https://github.com/Shopify/bootsnap/pull/319)
|
30
|
+
* [Fix potential crash](https://github.com/Shopify/bootsnap/pull/322)
|
31
|
+
|
32
|
+
# 1.4.8
|
33
|
+
|
34
|
+
* [Prevent FallbackScan from polluting exception cause](https://github.com/Shopify/bootsnap/pull/314)
|
35
|
+
|
36
|
+
# 1.4.7
|
37
|
+
|
38
|
+
* Various performance enhancements
|
39
|
+
* Fix race condition in heavy concurrent load scenarios that would cause bootsnap to raise
|
40
|
+
|
41
|
+
# 1.4.6
|
42
|
+
|
43
|
+
* Fix bug that was erroneously considering that files containing `.` in the names were being
|
44
|
+
required if a different file with the same name was already being required
|
45
|
+
|
46
|
+
Example:
|
47
|
+
|
48
|
+
require 'foo'
|
49
|
+
require 'foo.en'
|
50
|
+
|
51
|
+
Before bootsnap was considering `foo.en` to be the same file as `foo`
|
52
|
+
|
53
|
+
* Use glibc as part of the ruby_platform cache key
|
54
|
+
|
1
55
|
# 1.4.5
|
2
56
|
|
3
57
|
* MRI 2.7 support
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Bootsnap [![
|
1
|
+
# Bootsnap [![Actions Status](https://github.com/Shopify/bootsnap/workflows/ci/badge.svg)](https://github.com/Shopify/bootsnap/actions)
|
2
2
|
|
3
|
-
Bootsnap is a library that plugs into Ruby, with optional support for `
|
3
|
+
Bootsnap is a library that plugs into Ruby, with optional support for `YAML`,
|
4
4
|
to optimize and cache expensive computations. See [How Does This Work](#how-does-this-work).
|
5
5
|
|
6
6
|
#### Performance
|
@@ -11,7 +11,7 @@ to optimize and cache expensive computations. See [How Does This Work](#how-does
|
|
11
11
|
- The core Shopify platform -- a rather large monolithic application -- boots about 75% faster,
|
12
12
|
dropping from around 25s to 6.5s.
|
13
13
|
* In Shopify core (a large app), about 25% of this gain can be attributed to `compile_cache_*`
|
14
|
-
features; 75% to path caching
|
14
|
+
features; 75% to path caching. This is fairly representative.
|
15
15
|
|
16
16
|
## Usage
|
17
17
|
|
@@ -29,7 +29,8 @@ If you are using Rails, add this to `config/boot.rb` immediately after `require
|
|
29
29
|
require 'bootsnap/setup'
|
30
30
|
```
|
31
31
|
|
32
|
-
Note that bootsnap writes to `tmp/cache
|
32
|
+
Note that bootsnap writes to `tmp/cache` (or the path specified by `ENV['BOOTSNAP_CACHE_DIR']`),
|
33
|
+
and that directory *must* be writable. Rails will fail to
|
33
34
|
boot if it is not. If this is unacceptable (e.g. you are running in a read-only container and
|
34
35
|
unwilling to mount in a writable tmpdir), you should remove this line or wrap it in a conditional.
|
35
36
|
|
@@ -53,15 +54,11 @@ Bootsnap.setup(
|
|
53
54
|
cache_dir: 'tmp/cache', # Path to your cache
|
54
55
|
development_mode: env == 'development', # Current working environment, e.g. RACK_ENV, RAILS_ENV, etc
|
55
56
|
load_path_cache: true, # Optimize the LOAD_PATH with a cache
|
56
|
-
autoload_paths_cache: true, # Optimize ActiveSupport autoloads with cache
|
57
|
-
disable_trace: true, # Set `RubyVM::InstructionSequence.compile_option = { trace_instruction: false }`
|
58
57
|
compile_cache_iseq: true, # Compile Ruby code into ISeq cache, breaks coverage reporting.
|
59
58
|
compile_cache_yaml: true # Compile YAML into a cache
|
60
59
|
)
|
61
60
|
```
|
62
61
|
|
63
|
-
**Note that `disable_trace` will break debuggers and tracing.**
|
64
|
-
|
65
62
|
**Protip:** You can replace `require 'bootsnap'` with `BootLib::Require.from_gem('bootsnap',
|
66
63
|
'bootsnap')` using [this trick](https://github.com/Shopify/bootsnap/wiki/Bootlib::Require). This
|
67
64
|
will help optimize boot time further if you have an extremely large `$LOAD_PATH`.
|
@@ -71,12 +68,39 @@ speeds up the loading of individual source files, Spring keeps a copy of a pre-b
|
|
71
68
|
on hand to completely skip parts of the boot process the next time it's needed. The two tools work
|
72
69
|
well together, and are both included in a newly-generated Rails applications by default.
|
73
70
|
|
71
|
+
### Environment variables
|
72
|
+
|
73
|
+
`require 'bootsnap/setup'` behavior can be changed using environment variables:
|
74
|
+
|
75
|
+
- `BOOTSNAP_CACHE_DIR` allows to define the cache location.
|
76
|
+
- `DISABLE_BOOTSNAP` allows to entirely disable bootsnap.
|
77
|
+
- `DISABLE_BOOTSNAP_LOAD_PATH_CACHE` allows to disable load path caching.
|
78
|
+
- `DISABLE_BOOTSNAP_COMPILE_CACHE` allows to disable ISeq and YAML caches.
|
79
|
+
- `BOOTSNAP_LOG` configure bootsnap to log all caches misses to STDERR.
|
80
|
+
|
74
81
|
### Environments
|
75
82
|
|
76
83
|
All Bootsnap features are enabled in development, test, production, and all other environments according to the configuration in the setup. At Shopify, we use this gem safely in all environments without issue.
|
77
84
|
|
78
85
|
If you would like to disable any feature for a certain environment, we suggest changing the configuration to take into account the appropriate ENV var or configuration according to your needs.
|
79
86
|
|
87
|
+
### Instrumentation
|
88
|
+
|
89
|
+
Bootsnap cache misses can be monitored though a callback:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
Bootsnap.instrumentation = ->(event, path) { puts "#{event} #{path}" }
|
93
|
+
```
|
94
|
+
|
95
|
+
`event` is either `:miss` or `:stale`. You can also call `Bootsnap.log!` as a shortcut to
|
96
|
+
log all events to STDERR.
|
97
|
+
|
98
|
+
To turn instrumentation back off you can set it to nil:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
Bootsnap.instrumentation = nil
|
102
|
+
```
|
103
|
+
|
80
104
|
## How does this work?
|
81
105
|
|
82
106
|
Bootsnap optimizes methods to cache results of expensive computations, and can be grouped
|
@@ -84,8 +108,6 @@ into two broad categories:
|
|
84
108
|
|
85
109
|
* [Path Pre-Scanning](#path-pre-scanning)
|
86
110
|
* `Kernel#require` and `Kernel#load` are modified to eliminate `$LOAD_PATH` scans.
|
87
|
-
* `ActiveSupport::Dependencies.{autoloadable_module?,load_missing_constant,depend_on}` are
|
88
|
-
overridden to eliminate scans of `ActiveSupport::Dependencies.autoload_paths`.
|
89
111
|
* [Compilation caching](#compilation-caching)
|
90
112
|
* `RubyVM::InstructionSequence.load_iseq` is implemented to cache the result of ruby bytecode
|
91
113
|
compilation.
|
@@ -124,10 +146,6 @@ open y/foo.rb
|
|
124
146
|
...
|
125
147
|
```
|
126
148
|
|
127
|
-
Exactly the same strategy is employed for methods that traverse
|
128
|
-
`ActiveSupport::Dependencies.autoload_paths` if the `autoload_paths_cache` option is given to
|
129
|
-
`Bootsnap.setup`.
|
130
|
-
|
131
149
|
The following diagram flowcharts the overrides that make the `*_path_cache` features work.
|
132
150
|
|
133
151
|
![Flowchart explaining
|
@@ -214,7 +232,7 @@ Bootsnap writes a cache file containing a 64 byte header followed by the cache c
|
|
214
232
|
is a cache key including several fields:
|
215
233
|
|
216
234
|
* `version`, hardcoded in bootsnap. Essentially a schema version;
|
217
|
-
* `
|
235
|
+
* `ruby_platform`, A hash of `RUBY_PLATFORM` (e.g. x86_64-linux-gnu) variable and glibc version (on Linux) or OS version (`uname -v` on BSD, macOS)
|
218
236
|
* `compile_option`, which changes with `RubyVM::InstructionSequence.compile_option` does;
|
219
237
|
* `ruby_revision`, the version of Ruby this was compiled with;
|
220
238
|
* `size`, the size of the source file;
|
@@ -294,6 +312,19 @@ open /c/nope.bundle -> -1
|
|
294
312
|
# (nothing!)
|
295
313
|
```
|
296
314
|
|
315
|
+
## Precompilation
|
316
|
+
|
317
|
+
In development environments the bootsnap compilation cache is generated on the fly when source files are loaded.
|
318
|
+
But in production environments, such as docker images, you might need to precompile the cache.
|
319
|
+
|
320
|
+
To do so you can use the `bootsnap precompile` command.
|
321
|
+
|
322
|
+
Example:
|
323
|
+
|
324
|
+
```bash
|
325
|
+
$ bundle exec bootsnap precompile --gemfile app/ lib/
|
326
|
+
```
|
327
|
+
|
297
328
|
## When not to use Bootsnap
|
298
329
|
|
299
330
|
*Alternative engines*: Bootsnap is pretty reliant on MRI features, and parts are disabled entirely on alternative ruby
|
data/exe/bootsnap
ADDED
data/ext/bootsnap/bootsnap.c
CHANGED
@@ -14,6 +14,7 @@
|
|
14
14
|
#include "bootsnap.h"
|
15
15
|
#include "ruby.h"
|
16
16
|
#include <stdint.h>
|
17
|
+
#include <stdbool.h>
|
17
18
|
#include <sys/types.h>
|
18
19
|
#include <errno.h>
|
19
20
|
#include <fcntl.h>
|
@@ -21,6 +22,9 @@
|
|
21
22
|
#ifndef _WIN32
|
22
23
|
#include <sys/utsname.h>
|
23
24
|
#endif
|
25
|
+
#ifdef __GLIBC__
|
26
|
+
#include <gnu/libc-version.h>
|
27
|
+
#endif
|
24
28
|
|
25
29
|
/* 1000 is an arbitrary limit; FNV64 plus some slashes brings the cap down to
|
26
30
|
* 981 for the cache dir */
|
@@ -29,6 +33,12 @@
|
|
29
33
|
|
30
34
|
#define KEY_SIZE 64
|
31
35
|
|
36
|
+
#define MAX_CREATE_TEMPFILE_ATTEMPT 3
|
37
|
+
|
38
|
+
#ifndef RB_UNLIKELY
|
39
|
+
#define RB_UNLIKELY(x) (x)
|
40
|
+
#endif
|
41
|
+
|
32
42
|
/*
|
33
43
|
* An instance of this key is written as the first 64 bytes of each cache file.
|
34
44
|
* The mtime and size members track whether the file contents have changed, and
|
@@ -65,7 +75,7 @@ struct bs_cache_key {
|
|
65
75
|
STATIC_ASSERT(sizeof(struct bs_cache_key) == KEY_SIZE);
|
66
76
|
|
67
77
|
/* Effectively a schema version. Bumping invalidates all previous caches */
|
68
|
-
static const uint32_t current_version =
|
78
|
+
static const uint32_t current_version = 3;
|
69
79
|
|
70
80
|
/* hash of e.g. "x86_64-darwin17", invalidating when ruby is recompiled on a
|
71
81
|
* new OS ABI, etc. */
|
@@ -83,19 +93,26 @@ static VALUE rb_mBootsnap_CompileCache;
|
|
83
93
|
static VALUE rb_mBootsnap_CompileCache_Native;
|
84
94
|
static VALUE rb_eBootsnap_CompileCache_Uncompilable;
|
85
95
|
static ID uncompilable;
|
96
|
+
static ID instrumentation_method;
|
97
|
+
static VALUE sym_miss;
|
98
|
+
static VALUE sym_stale;
|
99
|
+
static bool instrumentation_enabled = false;
|
86
100
|
|
87
101
|
/* Functions exposed as module functions on Bootsnap::CompileCache::Native */
|
102
|
+
static VALUE bs_instrumentation_enabled_set(VALUE self, VALUE enabled);
|
88
103
|
static VALUE bs_compile_option_crc32_set(VALUE self, VALUE crc32_v);
|
89
|
-
static VALUE bs_rb_fetch(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler);
|
104
|
+
static VALUE bs_rb_fetch(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler, VALUE args);
|
105
|
+
static VALUE bs_rb_precompile(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler);
|
90
106
|
|
91
107
|
/* Helpers */
|
92
108
|
static uint64_t fnv1a_64(const char *str);
|
93
|
-
static void bs_cache_path(const char * cachedir, const char * path, char
|
109
|
+
static void bs_cache_path(const char * cachedir, const char * path, char (* cache_path)[MAX_CACHEPATH_SIZE]);
|
94
110
|
static int bs_read_key(int fd, struct bs_cache_key * key);
|
95
111
|
static int cache_key_equal(struct bs_cache_key * k1, struct bs_cache_key * k2);
|
96
|
-
static VALUE bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler);
|
97
|
-
static
|
98
|
-
static int
|
112
|
+
static VALUE bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler, VALUE args);
|
113
|
+
static VALUE bs_precompile(char * path, VALUE path_v, char * cache_path, VALUE handler);
|
114
|
+
static int open_current_file(char * path, struct bs_cache_key * key, const char ** errno_provenance);
|
115
|
+
static int fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE args, VALUE * output_data, int * exception_tag, const char ** errno_provenance);
|
99
116
|
static uint32_t get_ruby_revision(void);
|
100
117
|
static uint32_t get_ruby_platform(void);
|
101
118
|
|
@@ -103,12 +120,12 @@ static uint32_t get_ruby_platform(void);
|
|
103
120
|
* Helper functions to call ruby methods on handler object without crashing on
|
104
121
|
* exception.
|
105
122
|
*/
|
106
|
-
static int bs_storage_to_output(VALUE handler, VALUE storage_data, VALUE * output_data);
|
123
|
+
static int bs_storage_to_output(VALUE handler, VALUE args, VALUE storage_data, VALUE * output_data);
|
107
124
|
static VALUE prot_storage_to_output(VALUE arg);
|
108
125
|
static VALUE prot_input_to_output(VALUE arg);
|
109
|
-
static void bs_input_to_output(VALUE handler, VALUE input_data, VALUE * output_data, int * exception_tag);
|
126
|
+
static void bs_input_to_output(VALUE handler, VALUE args, VALUE input_data, VALUE * output_data, int * exception_tag);
|
110
127
|
static VALUE prot_input_to_storage(VALUE arg);
|
111
|
-
static int bs_input_to_storage(VALUE handler, VALUE input_data, VALUE pathval, VALUE * storage_data);
|
128
|
+
static int bs_input_to_storage(VALUE handler, VALUE args, VALUE input_data, VALUE pathval, VALUE * storage_data);
|
112
129
|
struct s2o_data;
|
113
130
|
struct i2o_data;
|
114
131
|
struct i2s_data;
|
@@ -141,15 +158,31 @@ Init_bootsnap(void)
|
|
141
158
|
current_ruby_platform = get_ruby_platform();
|
142
159
|
|
143
160
|
uncompilable = rb_intern("__bootsnap_uncompilable__");
|
161
|
+
instrumentation_method = rb_intern("_instrument");
|
144
162
|
|
163
|
+
sym_miss = ID2SYM(rb_intern("miss"));
|
164
|
+
rb_global_variable(&sym_miss);
|
165
|
+
|
166
|
+
sym_stale = ID2SYM(rb_intern("stale"));
|
167
|
+
rb_global_variable(&sym_stale);
|
168
|
+
|
169
|
+
rb_define_module_function(rb_mBootsnap, "instrumentation_enabled=", bs_instrumentation_enabled_set, 1);
|
145
170
|
rb_define_module_function(rb_mBootsnap_CompileCache_Native, "coverage_running?", bs_rb_coverage_running, 0);
|
146
|
-
rb_define_module_function(rb_mBootsnap_CompileCache_Native, "fetch", bs_rb_fetch,
|
171
|
+
rb_define_module_function(rb_mBootsnap_CompileCache_Native, "fetch", bs_rb_fetch, 4);
|
172
|
+
rb_define_module_function(rb_mBootsnap_CompileCache_Native, "precompile", bs_rb_precompile, 3);
|
147
173
|
rb_define_module_function(rb_mBootsnap_CompileCache_Native, "compile_option_crc32=", bs_compile_option_crc32_set, 1);
|
148
174
|
|
149
175
|
current_umask = umask(0777);
|
150
176
|
umask(current_umask);
|
151
177
|
}
|
152
178
|
|
179
|
+
static VALUE
|
180
|
+
bs_instrumentation_enabled_set(VALUE self, VALUE enabled)
|
181
|
+
{
|
182
|
+
instrumentation_enabled = RTEST(enabled);
|
183
|
+
return enabled;
|
184
|
+
}
|
185
|
+
|
153
186
|
/*
|
154
187
|
* Bootsnap's ruby code registers a hook that notifies us via this function
|
155
188
|
* when compile_option changes. These changes invalidate all existing caches.
|
@@ -236,6 +269,9 @@ get_ruby_platform(void)
|
|
236
269
|
|
237
270
|
#ifdef _WIN32
|
238
271
|
return (uint32_t)(hash >> 32) ^ (uint32_t)GetVersion();
|
272
|
+
#elif defined(__GLIBC__)
|
273
|
+
hash = fnv1a_64_iter(hash, gnu_get_libc_version());
|
274
|
+
return (uint32_t)(hash >> 32);
|
239
275
|
#else
|
240
276
|
struct utsname utsname;
|
241
277
|
|
@@ -256,10 +292,9 @@ get_ruby_platform(void)
|
|
256
292
|
* The path will look something like: <cachedir>/12/34567890abcdef
|
257
293
|
*/
|
258
294
|
static void
|
259
|
-
bs_cache_path(const char * cachedir, const char * path, char
|
295
|
+
bs_cache_path(const char * cachedir, const char * path, char (* cache_path)[MAX_CACHEPATH_SIZE])
|
260
296
|
{
|
261
297
|
uint64_t hash = fnv1a_64(path);
|
262
|
-
|
263
298
|
uint8_t first_byte = (hash >> (64 - 8));
|
264
299
|
uint64_t remainder = hash & 0x00ffffffffffffff;
|
265
300
|
|
@@ -293,7 +328,7 @@ cache_key_equal(struct bs_cache_key * k1, struct bs_cache_key * k2)
|
|
293
328
|
* conversions on the ruby VALUE arguments before passing them along.
|
294
329
|
*/
|
295
330
|
static VALUE
|
296
|
-
bs_rb_fetch(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler)
|
331
|
+
bs_rb_fetch(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler, VALUE args)
|
297
332
|
{
|
298
333
|
FilePathValue(path_v);
|
299
334
|
|
@@ -308,27 +343,51 @@ bs_rb_fetch(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler)
|
|
308
343
|
char * path = RSTRING_PTR(path_v);
|
309
344
|
char cache_path[MAX_CACHEPATH_SIZE];
|
310
345
|
|
311
|
-
|
312
|
-
|
313
|
-
bs_cache_path(cachedir, path, &tmp);
|
314
|
-
}
|
346
|
+
/* generate cache path to cache_path */
|
347
|
+
bs_cache_path(cachedir, path, &cache_path);
|
315
348
|
|
316
|
-
return bs_fetch(path, path_v, cache_path, handler);
|
349
|
+
return bs_fetch(path, path_v, cache_path, handler, args);
|
317
350
|
}
|
318
351
|
|
352
|
+
/*
|
353
|
+
* Entrypoint for Bootsnap::CompileCache::Native.precompile.
|
354
|
+
* Similar to fetch, but it only generate the cache if missing
|
355
|
+
* and doesn't return the content.
|
356
|
+
*/
|
357
|
+
static VALUE
|
358
|
+
bs_rb_precompile(VALUE self, VALUE cachedir_v, VALUE path_v, VALUE handler)
|
359
|
+
{
|
360
|
+
FilePathValue(path_v);
|
361
|
+
|
362
|
+
Check_Type(cachedir_v, T_STRING);
|
363
|
+
Check_Type(path_v, T_STRING);
|
364
|
+
|
365
|
+
if (RSTRING_LEN(cachedir_v) > MAX_CACHEDIR_SIZE) {
|
366
|
+
rb_raise(rb_eArgError, "cachedir too long");
|
367
|
+
}
|
368
|
+
|
369
|
+
char * cachedir = RSTRING_PTR(cachedir_v);
|
370
|
+
char * path = RSTRING_PTR(path_v);
|
371
|
+
char cache_path[MAX_CACHEPATH_SIZE];
|
372
|
+
|
373
|
+
/* generate cache path to cache_path */
|
374
|
+
bs_cache_path(cachedir, path, &cache_path);
|
375
|
+
|
376
|
+
return bs_precompile(path, path_v, cache_path, handler);
|
377
|
+
}
|
319
378
|
/*
|
320
379
|
* Open the file we want to load/cache and generate a cache key for it if it
|
321
380
|
* was loaded.
|
322
381
|
*/
|
323
382
|
static int
|
324
|
-
open_current_file(char * path, struct bs_cache_key * key, char ** errno_provenance)
|
383
|
+
open_current_file(char * path, struct bs_cache_key * key, const char ** errno_provenance)
|
325
384
|
{
|
326
385
|
struct stat statbuf;
|
327
386
|
int fd;
|
328
387
|
|
329
388
|
fd = open(path, O_RDONLY);
|
330
389
|
if (fd < 0) {
|
331
|
-
*errno_provenance =
|
390
|
+
*errno_provenance = "bs_fetch:open_current_file:open";
|
332
391
|
return fd;
|
333
392
|
}
|
334
393
|
#ifdef _WIN32
|
@@ -336,7 +395,7 @@ open_current_file(char * path, struct bs_cache_key * key, char ** errno_provenan
|
|
336
395
|
#endif
|
337
396
|
|
338
397
|
if (fstat(fd, &statbuf) < 0) {
|
339
|
-
*errno_provenance =
|
398
|
+
*errno_provenance = "bs_fetch:open_current_file:fstat";
|
340
399
|
close(fd);
|
341
400
|
return -1;
|
342
401
|
}
|
@@ -352,7 +411,8 @@ open_current_file(char * path, struct bs_cache_key * key, char ** errno_provenan
|
|
352
411
|
}
|
353
412
|
|
354
413
|
#define ERROR_WITH_ERRNO -1
|
355
|
-
#define
|
414
|
+
#define CACHE_MISS -2
|
415
|
+
#define CACHE_STALE -3
|
356
416
|
|
357
417
|
/*
|
358
418
|
* Read the cache key from the given fd, which must have position 0 (e.g.
|
@@ -360,15 +420,16 @@ open_current_file(char * path, struct bs_cache_key * key, char ** errno_provenan
|
|
360
420
|
*
|
361
421
|
* Possible return values:
|
362
422
|
* - 0 (OK, key was loaded)
|
363
|
-
* - CACHE_MISSING_OR_INVALID (-2)
|
364
423
|
* - ERROR_WITH_ERRNO (-1, errno is set)
|
424
|
+
* - CACHE_MISS (-2)
|
425
|
+
* - CACHE_STALE (-3)
|
365
426
|
*/
|
366
427
|
static int
|
367
428
|
bs_read_key(int fd, struct bs_cache_key * key)
|
368
429
|
{
|
369
430
|
ssize_t nread = read(fd, key, KEY_SIZE);
|
370
431
|
if (nread < 0) return ERROR_WITH_ERRNO;
|
371
|
-
if (nread < KEY_SIZE) return
|
432
|
+
if (nread < KEY_SIZE) return CACHE_STALE;
|
372
433
|
return 0;
|
373
434
|
}
|
374
435
|
|
@@ -378,18 +439,19 @@ bs_read_key(int fd, struct bs_cache_key * key)
|
|
378
439
|
*
|
379
440
|
* Possible return values:
|
380
441
|
* - 0 (OK, key was loaded)
|
381
|
-
* -
|
442
|
+
* - CACHE_MISS (-2)
|
443
|
+
* - CACHE_STALE (-3)
|
382
444
|
* - ERROR_WITH_ERRNO (-1, errno is set)
|
383
445
|
*/
|
384
446
|
static int
|
385
|
-
open_cache_file(const char * path, struct bs_cache_key * key, char ** errno_provenance)
|
447
|
+
open_cache_file(const char * path, struct bs_cache_key * key, const char ** errno_provenance)
|
386
448
|
{
|
387
449
|
int fd, res;
|
388
450
|
|
389
451
|
fd = open(path, O_RDONLY);
|
390
452
|
if (fd < 0) {
|
391
|
-
*errno_provenance =
|
392
|
-
if (errno == ENOENT) return
|
453
|
+
*errno_provenance = "bs_fetch:open_cache_file:open";
|
454
|
+
if (errno == ENOENT) return CACHE_MISS;
|
393
455
|
return ERROR_WITH_ERRNO;
|
394
456
|
}
|
395
457
|
#ifdef _WIN32
|
@@ -398,7 +460,7 @@ open_cache_file(const char * path, struct bs_cache_key * key, char ** errno_prov
|
|
398
460
|
|
399
461
|
res = bs_read_key(fd, key);
|
400
462
|
if (res < 0) {
|
401
|
-
*errno_provenance =
|
463
|
+
*errno_provenance = "bs_fetch:open_cache_file:read";
|
402
464
|
close(fd);
|
403
465
|
return res;
|
404
466
|
}
|
@@ -422,7 +484,7 @@ open_cache_file(const char * path, struct bs_cache_key * key, char ** errno_prov
|
|
422
484
|
* or exception, will be the final data returnable to the user.
|
423
485
|
*/
|
424
486
|
static int
|
425
|
-
fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE * output_data, int * exception_tag, char ** errno_provenance)
|
487
|
+
fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE args, VALUE * output_data, int * exception_tag, const char ** errno_provenance)
|
426
488
|
{
|
427
489
|
char * data = NULL;
|
428
490
|
ssize_t nread;
|
@@ -431,7 +493,7 @@ fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE * output_data,
|
|
431
493
|
VALUE storage_data;
|
432
494
|
|
433
495
|
if (data_size > 100000000000) {
|
434
|
-
*errno_provenance =
|
496
|
+
*errno_provenance = "bs_fetch:fetch_cached_data:datasize";
|
435
497
|
errno = EINVAL; /* because wtf? */
|
436
498
|
ret = -1;
|
437
499
|
goto done;
|
@@ -439,18 +501,18 @@ fetch_cached_data(int fd, ssize_t data_size, VALUE handler, VALUE * output_data,
|
|
439
501
|
data = ALLOC_N(char, data_size);
|
440
502
|
nread = read(fd, data, data_size);
|
441
503
|
if (nread < 0) {
|
442
|
-
*errno_provenance =
|
504
|
+
*errno_provenance = "bs_fetch:fetch_cached_data:read";
|
443
505
|
ret = -1;
|
444
506
|
goto done;
|
445
507
|
}
|
446
508
|
if (nread != data_size) {
|
447
|
-
ret =
|
509
|
+
ret = CACHE_STALE;
|
448
510
|
goto done;
|
449
511
|
}
|
450
512
|
|
451
|
-
storage_data =
|
513
|
+
storage_data = rb_str_new(data, data_size);
|
452
514
|
|
453
|
-
*exception_tag = bs_storage_to_output(handler, storage_data, output_data);
|
515
|
+
*exception_tag = bs_storage_to_output(handler, args, storage_data, output_data);
|
454
516
|
ret = 0;
|
455
517
|
done:
|
456
518
|
if (data != NULL) xfree(data);
|
@@ -491,29 +553,36 @@ mkpath(char * file_path, mode_t mode)
|
|
491
553
|
* path.
|
492
554
|
*/
|
493
555
|
static int
|
494
|
-
atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data, char ** errno_provenance)
|
556
|
+
atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data, const char ** errno_provenance)
|
495
557
|
{
|
496
558
|
char template[MAX_CACHEPATH_SIZE + 20];
|
497
559
|
char * tmp_path;
|
498
|
-
int fd, ret;
|
560
|
+
int fd, ret, attempt;
|
499
561
|
ssize_t nwrite;
|
500
562
|
|
501
|
-
|
502
|
-
|
563
|
+
for (attempt = 0; attempt < MAX_CREATE_TEMPFILE_ATTEMPT; ++attempt) {
|
564
|
+
tmp_path = strncpy(template, path, MAX_CACHEPATH_SIZE);
|
565
|
+
strcat(tmp_path, ".tmp.XXXXXX");
|
503
566
|
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
}
|
511
|
-
fd = open(tmp_path, O_WRONLY | O_CREAT, 0664);
|
512
|
-
if (fd < 0) {
|
513
|
-
*errno_provenance = (char *)"bs_fetch:atomic_write_cache_file:open";
|
567
|
+
// mkstemp modifies the template to be the actual created path
|
568
|
+
fd = mkstemp(tmp_path);
|
569
|
+
if (fd > 0) break;
|
570
|
+
|
571
|
+
if (attempt == 0 && mkpath(tmp_path, 0775) < 0) {
|
572
|
+
*errno_provenance = "bs_fetch:atomic_write_cache_file:mkpath";
|
514
573
|
return -1;
|
515
574
|
}
|
516
575
|
}
|
576
|
+
if (fd < 0) {
|
577
|
+
*errno_provenance = "bs_fetch:atomic_write_cache_file:mkstemp";
|
578
|
+
return -1;
|
579
|
+
}
|
580
|
+
|
581
|
+
if (chmod(tmp_path, 0644) < 0) {
|
582
|
+
*errno_provenance = "bs_fetch:atomic_write_cache_file:chmod";
|
583
|
+
return -1;
|
584
|
+
}
|
585
|
+
|
517
586
|
#ifdef _WIN32
|
518
587
|
setmode(fd, O_BINARY);
|
519
588
|
#endif
|
@@ -521,11 +590,11 @@ atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data, char
|
|
521
590
|
key->data_size = RSTRING_LEN(data);
|
522
591
|
nwrite = write(fd, key, KEY_SIZE);
|
523
592
|
if (nwrite < 0) {
|
524
|
-
*errno_provenance =
|
593
|
+
*errno_provenance = "bs_fetch:atomic_write_cache_file:write";
|
525
594
|
return -1;
|
526
595
|
}
|
527
596
|
if (nwrite != KEY_SIZE) {
|
528
|
-
*errno_provenance =
|
597
|
+
*errno_provenance = "bs_fetch:atomic_write_cache_file:keysize";
|
529
598
|
errno = EIO; /* Lies but whatever */
|
530
599
|
return -1;
|
531
600
|
}
|
@@ -533,7 +602,7 @@ atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data, char
|
|
533
602
|
nwrite = write(fd, RSTRING_PTR(data), RSTRING_LEN(data));
|
534
603
|
if (nwrite < 0) return -1;
|
535
604
|
if (nwrite != RSTRING_LEN(data)) {
|
536
|
-
*errno_provenance =
|
605
|
+
*errno_provenance = "bs_fetch:atomic_write_cache_file:writelength";
|
537
606
|
errno = EIO; /* Lies but whatever */
|
538
607
|
return -1;
|
539
608
|
}
|
@@ -541,12 +610,12 @@ atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data, char
|
|
541
610
|
close(fd);
|
542
611
|
ret = rename(tmp_path, path);
|
543
612
|
if (ret < 0) {
|
544
|
-
*errno_provenance =
|
613
|
+
*errno_provenance = "bs_fetch:atomic_write_cache_file:rename";
|
545
614
|
return -1;
|
546
615
|
}
|
547
616
|
ret = chmod(path, 0664 & ~current_umask);
|
548
617
|
if (ret < 0) {
|
549
|
-
*errno_provenance =
|
618
|
+
*errno_provenance = "bs_fetch:atomic_write_cache_file:chmod";
|
550
619
|
}
|
551
620
|
return ret;
|
552
621
|
}
|
@@ -555,13 +624,13 @@ atomic_write_cache_file(char * path, struct bs_cache_key * key, VALUE data, char
|
|
555
624
|
/* Read contents from an fd, whose contents are asserted to be +size+ bytes
|
556
625
|
* long, into a buffer */
|
557
626
|
static ssize_t
|
558
|
-
bs_read_contents(int fd, size_t size, char ** contents, char ** errno_provenance)
|
627
|
+
bs_read_contents(int fd, size_t size, char ** contents, const char ** errno_provenance)
|
559
628
|
{
|
560
629
|
ssize_t nread;
|
561
630
|
*contents = ALLOC_N(char, size);
|
562
631
|
nread = read(fd, *contents, size);
|
563
632
|
if (nread < 0) {
|
564
|
-
*errno_provenance =
|
633
|
+
*errno_provenance = "bs_fetch:bs_read_contents:read";
|
565
634
|
}
|
566
635
|
return nread;
|
567
636
|
}
|
@@ -611,13 +680,13 @@ bs_read_contents(int fd, size_t size, char ** contents, char ** errno_provenance
|
|
611
680
|
* - Return storage_to_output(storage_data)
|
612
681
|
*/
|
613
682
|
static VALUE
|
614
|
-
bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler)
|
683
|
+
bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler, VALUE args)
|
615
684
|
{
|
616
685
|
struct bs_cache_key cached_key, current_key;
|
617
686
|
char * contents = NULL;
|
618
687
|
int cache_fd = -1, current_fd = -1;
|
619
688
|
int res, valid_cache = 0, exception_tag = 0;
|
620
|
-
char * errno_provenance = NULL;
|
689
|
+
const char * errno_provenance = NULL;
|
621
690
|
|
622
691
|
VALUE input_data; /* data read from source file, e.g. YAML or ruby source */
|
623
692
|
VALUE storage_data; /* compiled data, e.g. msgpack / binary iseq */
|
@@ -631,26 +700,34 @@ bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler)
|
|
631
700
|
|
632
701
|
/* Open the cache key if it exists, and read its cache key in */
|
633
702
|
cache_fd = open_cache_file(cache_path, &cached_key, &errno_provenance);
|
634
|
-
if (cache_fd ==
|
703
|
+
if (cache_fd == CACHE_MISS || cache_fd == CACHE_STALE) {
|
635
704
|
/* This is ok: valid_cache remains false, we re-populate it. */
|
705
|
+
if (RB_UNLIKELY(instrumentation_enabled)) {
|
706
|
+
rb_funcall(rb_mBootsnap, instrumentation_method, 2, cache_fd == CACHE_MISS ? sym_miss : sym_stale, path_v);
|
707
|
+
}
|
636
708
|
} else if (cache_fd < 0) {
|
637
709
|
goto fail_errno;
|
638
710
|
} else {
|
639
711
|
/* True if the cache existed and no invalidating changes have occurred since
|
640
712
|
* it was generated. */
|
641
713
|
valid_cache = cache_key_equal(¤t_key, &cached_key);
|
714
|
+
if (RB_UNLIKELY(instrumentation_enabled)) {
|
715
|
+
if (!valid_cache) {
|
716
|
+
rb_funcall(rb_mBootsnap, instrumentation_method, 2, sym_stale, path_v);
|
717
|
+
}
|
718
|
+
}
|
642
719
|
}
|
643
720
|
|
644
721
|
if (valid_cache) {
|
645
722
|
/* Fetch the cache data and return it if we're able to load it successfully */
|
646
723
|
res = fetch_cached_data(
|
647
|
-
cache_fd, (ssize_t)cached_key.data_size, handler,
|
724
|
+
cache_fd, (ssize_t)cached_key.data_size, handler, args,
|
648
725
|
&output_data, &exception_tag, &errno_provenance
|
649
726
|
);
|
650
|
-
if (exception_tag != 0)
|
651
|
-
else if (res ==
|
652
|
-
else if (res == ERROR_WITH_ERRNO)
|
653
|
-
else if (!NIL_P(output_data))
|
727
|
+
if (exception_tag != 0) goto raise;
|
728
|
+
else if (res == CACHE_MISS || res == CACHE_STALE) valid_cache = 0;
|
729
|
+
else if (res == ERROR_WITH_ERRNO) goto fail_errno;
|
730
|
+
else if (!NIL_P(output_data)) goto succeed; /* fast-path, goal */
|
654
731
|
}
|
655
732
|
close(cache_fd);
|
656
733
|
cache_fd = -1;
|
@@ -658,15 +735,15 @@ bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler)
|
|
658
735
|
|
659
736
|
/* Read the contents of the source file into a buffer */
|
660
737
|
if (bs_read_contents(current_fd, current_key.size, &contents, &errno_provenance) < 0) goto fail_errno;
|
661
|
-
input_data =
|
738
|
+
input_data = rb_str_new(contents, current_key.size);
|
662
739
|
|
663
740
|
/* Try to compile the input_data using input_to_storage(input_data) */
|
664
|
-
exception_tag = bs_input_to_storage(handler, input_data, path_v, &storage_data);
|
741
|
+
exception_tag = bs_input_to_storage(handler, args, input_data, path_v, &storage_data);
|
665
742
|
if (exception_tag != 0) goto raise;
|
666
743
|
/* If input_to_storage raised Bootsnap::CompileCache::Uncompilable, don't try
|
667
744
|
* to cache anything; just return input_to_output(input_data) */
|
668
745
|
if (storage_data == uncompilable) {
|
669
|
-
bs_input_to_output(handler, input_data, &output_data, &exception_tag);
|
746
|
+
bs_input_to_output(handler, args, input_data, &output_data, &exception_tag);
|
670
747
|
if (exception_tag != 0) goto raise;
|
671
748
|
goto succeed;
|
672
749
|
}
|
@@ -678,17 +755,17 @@ bs_fetch(char * path, VALUE path_v, char * cache_path, VALUE handler)
|
|
678
755
|
if (res < 0) goto fail_errno;
|
679
756
|
|
680
757
|
/* Having written the cache, now convert storage_data to output_data */
|
681
|
-
exception_tag = bs_storage_to_output(handler, storage_data, &output_data);
|
758
|
+
exception_tag = bs_storage_to_output(handler, args, storage_data, &output_data);
|
682
759
|
if (exception_tag != 0) goto raise;
|
683
760
|
|
684
761
|
/* If output_data is nil, delete the cache entry and generate the output
|
685
762
|
* using input_to_output */
|
686
763
|
if (NIL_P(output_data)) {
|
687
764
|
if (unlink(cache_path) < 0) {
|
688
|
-
errno_provenance =
|
765
|
+
errno_provenance = "bs_fetch:unlink";
|
689
766
|
goto fail_errno;
|
690
767
|
}
|
691
|
-
bs_input_to_output(handler, input_data, &output_data, &exception_tag);
|
768
|
+
bs_input_to_output(handler, args, input_data, &output_data, &exception_tag);
|
692
769
|
if (exception_tag != 0) goto raise;
|
693
770
|
}
|
694
771
|
|
@@ -719,6 +796,79 @@ invalid_type_storage_data:
|
|
719
796
|
#undef CLEANUP
|
720
797
|
}
|
721
798
|
|
799
|
+
static VALUE
|
800
|
+
bs_precompile(char * path, VALUE path_v, char * cache_path, VALUE handler)
|
801
|
+
{
|
802
|
+
struct bs_cache_key cached_key, current_key;
|
803
|
+
char * contents = NULL;
|
804
|
+
int cache_fd = -1, current_fd = -1;
|
805
|
+
int res, valid_cache = 0, exception_tag = 0;
|
806
|
+
const char * errno_provenance = NULL;
|
807
|
+
|
808
|
+
VALUE input_data; /* data read from source file, e.g. YAML or ruby source */
|
809
|
+
VALUE storage_data; /* compiled data, e.g. msgpack / binary iseq */
|
810
|
+
|
811
|
+
/* Open the source file and generate a cache key for it */
|
812
|
+
current_fd = open_current_file(path, ¤t_key, &errno_provenance);
|
813
|
+
if (current_fd < 0) goto fail;
|
814
|
+
|
815
|
+
/* Open the cache key if it exists, and read its cache key in */
|
816
|
+
cache_fd = open_cache_file(cache_path, &cached_key, &errno_provenance);
|
817
|
+
if (cache_fd == CACHE_MISS || cache_fd == CACHE_STALE) {
|
818
|
+
/* This is ok: valid_cache remains false, we re-populate it. */
|
819
|
+
} else if (cache_fd < 0) {
|
820
|
+
goto fail;
|
821
|
+
} else {
|
822
|
+
/* True if the cache existed and no invalidating changes have occurred since
|
823
|
+
* it was generated. */
|
824
|
+
valid_cache = cache_key_equal(¤t_key, &cached_key);
|
825
|
+
}
|
826
|
+
|
827
|
+
if (valid_cache) {
|
828
|
+
goto succeed;
|
829
|
+
}
|
830
|
+
|
831
|
+
close(cache_fd);
|
832
|
+
cache_fd = -1;
|
833
|
+
/* Cache is stale, invalid, or missing. Regenerate and write it out. */
|
834
|
+
|
835
|
+
/* Read the contents of the source file into a buffer */
|
836
|
+
if (bs_read_contents(current_fd, current_key.size, &contents, &errno_provenance) < 0) goto fail;
|
837
|
+
input_data = rb_str_new(contents, current_key.size);
|
838
|
+
|
839
|
+
/* Try to compile the input_data using input_to_storage(input_data) */
|
840
|
+
exception_tag = bs_input_to_storage(handler, Qnil, input_data, path_v, &storage_data);
|
841
|
+
if (exception_tag != 0) goto fail;
|
842
|
+
|
843
|
+
/* If input_to_storage raised Bootsnap::CompileCache::Uncompilable, don't try
|
844
|
+
* to cache anything; just return false */
|
845
|
+
if (storage_data == uncompilable) {
|
846
|
+
goto fail;
|
847
|
+
}
|
848
|
+
/* If storage_data isn't a string, we can't cache it */
|
849
|
+
if (!RB_TYPE_P(storage_data, T_STRING)) goto fail;
|
850
|
+
|
851
|
+
/* Write the cache key and storage_data to the cache directory */
|
852
|
+
res = atomic_write_cache_file(cache_path, ¤t_key, storage_data, &errno_provenance);
|
853
|
+
if (res < 0) goto fail;
|
854
|
+
|
855
|
+
goto succeed;
|
856
|
+
|
857
|
+
#define CLEANUP \
|
858
|
+
if (contents != NULL) xfree(contents); \
|
859
|
+
if (current_fd >= 0) close(current_fd); \
|
860
|
+
if (cache_fd >= 0) close(cache_fd);
|
861
|
+
|
862
|
+
succeed:
|
863
|
+
CLEANUP;
|
864
|
+
return Qtrue;
|
865
|
+
fail:
|
866
|
+
CLEANUP;
|
867
|
+
return Qfalse;
|
868
|
+
#undef CLEANUP
|
869
|
+
}
|
870
|
+
|
871
|
+
|
722
872
|
/*****************************************************************************/
|
723
873
|
/********************* Handler Wrappers **************************************/
|
724
874
|
/*****************************************************************************
|
@@ -738,11 +888,13 @@ invalid_type_storage_data:
|
|
738
888
|
|
739
889
|
struct s2o_data {
|
740
890
|
VALUE handler;
|
891
|
+
VALUE args;
|
741
892
|
VALUE storage_data;
|
742
893
|
};
|
743
894
|
|
744
895
|
struct i2o_data {
|
745
896
|
VALUE handler;
|
897
|
+
VALUE args;
|
746
898
|
VALUE input_data;
|
747
899
|
};
|
748
900
|
|
@@ -756,15 +908,16 @@ static VALUE
|
|
756
908
|
prot_storage_to_output(VALUE arg)
|
757
909
|
{
|
758
910
|
struct s2o_data * data = (struct s2o_data *)arg;
|
759
|
-
return rb_funcall(data->handler, rb_intern("storage_to_output"),
|
911
|
+
return rb_funcall(data->handler, rb_intern("storage_to_output"), 2, data->storage_data, data->args);
|
760
912
|
}
|
761
913
|
|
762
914
|
static int
|
763
|
-
bs_storage_to_output(VALUE handler, VALUE storage_data, VALUE * output_data)
|
915
|
+
bs_storage_to_output(VALUE handler, VALUE args, VALUE storage_data, VALUE * output_data)
|
764
916
|
{
|
765
917
|
int state;
|
766
918
|
struct s2o_data s2o_data = {
|
767
919
|
.handler = handler,
|
920
|
+
.args = args,
|
768
921
|
.storage_data = storage_data,
|
769
922
|
};
|
770
923
|
*output_data = rb_protect(prot_storage_to_output, (VALUE)&s2o_data, &state);
|
@@ -772,10 +925,11 @@ bs_storage_to_output(VALUE handler, VALUE storage_data, VALUE * output_data)
|
|
772
925
|
}
|
773
926
|
|
774
927
|
static void
|
775
|
-
bs_input_to_output(VALUE handler, VALUE input_data, VALUE * output_data, int * exception_tag)
|
928
|
+
bs_input_to_output(VALUE handler, VALUE args, VALUE input_data, VALUE * output_data, int * exception_tag)
|
776
929
|
{
|
777
930
|
struct i2o_data i2o_data = {
|
778
931
|
.handler = handler,
|
932
|
+
.args = args,
|
779
933
|
.input_data = input_data,
|
780
934
|
};
|
781
935
|
*output_data = rb_protect(prot_input_to_output, (VALUE)&i2o_data, exception_tag);
|
@@ -785,7 +939,7 @@ static VALUE
|
|
785
939
|
prot_input_to_output(VALUE arg)
|
786
940
|
{
|
787
941
|
struct i2o_data * data = (struct i2o_data *)arg;
|
788
|
-
return rb_funcall(data->handler, rb_intern("input_to_output"),
|
942
|
+
return rb_funcall(data->handler, rb_intern("input_to_output"), 2, data->input_data, data->args);
|
789
943
|
}
|
790
944
|
|
791
945
|
static VALUE
|
@@ -796,7 +950,7 @@ try_input_to_storage(VALUE arg)
|
|
796
950
|
}
|
797
951
|
|
798
952
|
static VALUE
|
799
|
-
rescue_input_to_storage(VALUE arg)
|
953
|
+
rescue_input_to_storage(VALUE arg, VALUE e)
|
800
954
|
{
|
801
955
|
return uncompilable;
|
802
956
|
}
|
@@ -812,7 +966,7 @@ prot_input_to_storage(VALUE arg)
|
|
812
966
|
}
|
813
967
|
|
814
968
|
static int
|
815
|
-
bs_input_to_storage(VALUE handler, VALUE input_data, VALUE pathval, VALUE * storage_data)
|
969
|
+
bs_input_to_storage(VALUE handler, VALUE args, VALUE input_data, VALUE pathval, VALUE * storage_data)
|
816
970
|
{
|
817
971
|
int state;
|
818
972
|
struct i2s_data i2s_data = {
|