jsonnet 0.5.2 → 0.6.0
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 +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/README.md +1 -1
- data/ext/jsonnet/callbacks.c +28 -4
- data/ext/jsonnet/extconf.rb +19 -2
- data/ext/jsonnet/helpers.c +26 -0
- data/ext/jsonnet/ruby_jsonnet.h +1 -0
- data/ext/jsonnet/vm.c +6 -8
- data/lib/jsonnet/version.rb +1 -1
- data/test/test_vm.rb +20 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4340172a08a949087e54c213842fe9a3ee445ec9149bc39f8dc56371d2199f6
|
4
|
+
data.tar.gz: 1e068cb049eda5218e0a49984bd581e22147f3d98f4db11a2d0fb082490e5001
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d532a2079abd6d4612f0f14bed63ed245302478251dedff199f02572a5e7f5400c07c76f9bf649da67607ad1c904cc49089a3c481614a90d36163427dd91e01
|
7
|
+
data.tar.gz: d2d41cca8cab085b6fe38fda48886706bb2f8876ff1f4e557e9310fd955b11f5784001f11c93c3bb509bfb6df542fced240733cd64478e3bf69c5ae21cbf094d
|
data/.github/workflows/ruby.yml
CHANGED
data/README.md
CHANGED
@@ -63,7 +63,7 @@ gem install jsonnet -- --use-system-libraries
|
|
63
63
|
|
64
64
|
Load the library with `require "jsonnet"`
|
65
65
|
|
66
|
-
You can evaluate a string of Jsonnet using `Jsonnet.
|
66
|
+
You can evaluate a string of Jsonnet using `Jsonnet.evaluate`
|
67
67
|
|
68
68
|
```
|
69
69
|
irb(main):002:0> Jsonnet.evaluate('{ foo: "bar" }')
|
data/ext/jsonnet/callbacks.c
CHANGED
@@ -11,6 +11,14 @@
|
|
11
11
|
*/
|
12
12
|
#define RUBYJSONNET_GLOBAL_ESCAPE_MAGIC "\x07\x03\x0c:rubytag:\x07\x03\x0c:"
|
13
13
|
|
14
|
+
/* Copied from vm_core.h in Ruby. State variables in global escapes have
|
15
|
+
* this value when an exception is raised.
|
16
|
+
*
|
17
|
+
* TODO(yugui) Find a better way to distinguish "raise" from "throw".
|
18
|
+
* It is not a very good idea to depend on the implementation details of Ruby.
|
19
|
+
*/
|
20
|
+
#define RUBY_TAG_RAISE 0x6
|
21
|
+
|
14
22
|
/*
|
15
23
|
* callback support in VM
|
16
24
|
*/
|
@@ -44,9 +52,9 @@ invoke_callback(VALUE args)
|
|
44
52
|
static VALUE
|
45
53
|
rescue_callback(int state, const char *fmt, ...)
|
46
54
|
{
|
47
|
-
|
48
|
-
|
49
|
-
VALUE msg = rb_protect(rubyjsonnet_format_exception,
|
55
|
+
if (state == RUBY_TAG_RAISE) {
|
56
|
+
VALUE err = rb_errinfo();
|
57
|
+
VALUE msg = rb_protect(rubyjsonnet_format_exception, err, NULL);
|
50
58
|
if (msg == Qnil) {
|
51
59
|
va_list ap;
|
52
60
|
va_start(ap, fmt);
|
@@ -96,9 +104,15 @@ rubyjsonnet_jump_tag(const char *exc_mesg)
|
|
96
104
|
return 0;
|
97
105
|
}
|
98
106
|
|
107
|
+
#ifdef HAVE_JSONNET_IMPORT_CALLBACK_0_19
|
108
|
+
static int
|
109
|
+
import_callback_entrypoint(void *ctx, const char *base, const char *rel, char **found_here,
|
110
|
+
char **buf, size_t *buflen)
|
111
|
+
#else
|
99
112
|
static char *
|
100
113
|
import_callback_entrypoint(void *ctx, const char *base, const char *rel, char **found_here,
|
101
114
|
int *success)
|
115
|
+
#endif
|
102
116
|
{
|
103
117
|
struct jsonnet_vm_wrap *const vm = (struct jsonnet_vm_wrap *)ctx;
|
104
118
|
int state;
|
@@ -115,14 +129,24 @@ import_callback_entrypoint(void *ctx, const char *base, const char *rel, char **
|
|
115
129
|
|
116
130
|
if (state) {
|
117
131
|
VALUE msg = rescue_callback(state, "cannot import %s from %s", rel, base);
|
132
|
+
#ifdef HAVE_JSONNET_IMPORT_CALLBACK_0_19
|
133
|
+
*buf = rubyjsonnet_str_to_ptr(vm->vm, msg, buflen);
|
134
|
+
return 1;
|
135
|
+
#else
|
118
136
|
*success = 0;
|
119
137
|
return rubyjsonnet_str_to_cstr(vm->vm, msg);
|
138
|
+
#endif
|
120
139
|
}
|
121
140
|
|
122
141
|
result = rb_Array(result);
|
123
|
-
*success = 1;
|
124
142
|
*found_here = rubyjsonnet_str_to_cstr(vm->vm, rb_ary_entry(result, 1));
|
143
|
+
#ifdef HAVE_JSONNET_IMPORT_CALLBACK_0_19
|
144
|
+
*buf = rubyjsonnet_str_to_ptr(vm->vm, rb_ary_entry(result, 0), buflen);
|
145
|
+
return 0;
|
146
|
+
#else
|
147
|
+
*success = 1;
|
125
148
|
return rubyjsonnet_str_to_cstr(vm->vm, rb_ary_entry(result, 0));
|
149
|
+
#endif
|
126
150
|
}
|
127
151
|
|
128
152
|
/*
|
data/ext/jsonnet/extconf.rb
CHANGED
@@ -13,8 +13,8 @@ unless using_system_libraries?
|
|
13
13
|
require 'mini_portile2'
|
14
14
|
message "Using mini_portile version #{MiniPortile::VERSION}\n"
|
15
15
|
|
16
|
-
recipe = MiniPortile.new('jsonnet', 'v0.
|
17
|
-
recipe.files = ['https://github.com/google/jsonnet/archive/v0.
|
16
|
+
recipe = MiniPortile.new('jsonnet', 'v0.20.0')
|
17
|
+
recipe.files = ['https://github.com/google/jsonnet/archive/v0.20.0.tar.gz']
|
18
18
|
class << recipe
|
19
19
|
CORE_OBJS = %w[
|
20
20
|
desugarer.o formatter.o lexer.o libjsonnet.o parser.o pass.o static_analysis.o string_utils.o vm.o
|
@@ -89,4 +89,21 @@ end
|
|
89
89
|
abort 'libjsonnet.h not found' unless have_header('libjsonnet.h')
|
90
90
|
abort 'libjsonnet not found' unless have_library('jsonnet')
|
91
91
|
have_header('libjsonnet_fmt.h')
|
92
|
+
|
93
|
+
import_callback_0_19 = checking_for checking_message('JsonnetImportCallback >= v0.19.0') do
|
94
|
+
try_compile(<<SRC, '-Werror=incompatible-pointer-types')
|
95
|
+
#include <libjsonnet.h>
|
96
|
+
|
97
|
+
int f(void *ctx, const char *base, const char *rel, char **found_here, char **buf, size_t *buflen);
|
98
|
+
|
99
|
+
int main() {
|
100
|
+
jsonnet_import_callback(NULL, f, NULL);
|
101
|
+
return 0;
|
102
|
+
}
|
103
|
+
SRC
|
104
|
+
end
|
105
|
+
if import_callback_0_19
|
106
|
+
$defs.push('-DHAVE_JSONNET_IMPORT_CALLBACK_0_19')
|
107
|
+
end
|
108
|
+
|
92
109
|
create_makefile('jsonnet/jsonnet_wrap')
|
data/ext/jsonnet/helpers.c
CHANGED
@@ -34,6 +34,13 @@ rubyjsonnet_assert_asciicompat(VALUE str)
|
|
34
34
|
|
35
35
|
/**
|
36
36
|
* Allocates a C string whose content is equal to \c str with jsonnet_realloc.
|
37
|
+
*
|
38
|
+
* Note that this function does not allow NUL characters in the string.
|
39
|
+
* You should use rubyjsonnet_str_to_ptr() if you want to handle NUL characters.
|
40
|
+
*
|
41
|
+
* @param[in] vm a Jsonnet VM
|
42
|
+
* @param[in] str a String-like object
|
43
|
+
* @return the allocated C string
|
37
44
|
*/
|
38
45
|
char *
|
39
46
|
rubyjsonnet_str_to_cstr(struct JsonnetVm *vm, VALUE str)
|
@@ -44,6 +51,25 @@ rubyjsonnet_str_to_cstr(struct JsonnetVm *vm, VALUE str)
|
|
44
51
|
return buf;
|
45
52
|
}
|
46
53
|
|
54
|
+
/**
|
55
|
+
* Allocates a byte sequence whose content is equal to \c str with jsonnet_realloc.
|
56
|
+
*
|
57
|
+
* @param[in] vm a Jsonnet VM
|
58
|
+
* @param[in] str a String-like object
|
59
|
+
* @param[out] buflen the length of the allocated buffer
|
60
|
+
* @return the allocated buffer
|
61
|
+
*/
|
62
|
+
char *
|
63
|
+
rubyjsonnet_str_to_ptr(struct JsonnetVm *vm, VALUE str, size_t *buflen)
|
64
|
+
{
|
65
|
+
StringValue(str);
|
66
|
+
size_t len = RSTRING_LEN(str);
|
67
|
+
char *buf = jsonnet_realloc(vm, NULL, len);
|
68
|
+
memcpy(buf, RSTRING_PTR(str), len);
|
69
|
+
*buflen = len;
|
70
|
+
return buf;
|
71
|
+
}
|
72
|
+
|
47
73
|
/**
|
48
74
|
* @return a human readable string which contains the class name of the
|
49
75
|
* exception and its message. It might be nil on failure
|
data/ext/jsonnet/ruby_jsonnet.h
CHANGED
@@ -33,6 +33,7 @@ struct JsonnetJsonValue *rubyjsonnet_obj_to_json(struct JsonnetVm *vm, VALUE obj
|
|
33
33
|
|
34
34
|
rb_encoding *rubyjsonnet_assert_asciicompat(VALUE str);
|
35
35
|
char *rubyjsonnet_str_to_cstr(struct JsonnetVm *vm, VALUE str);
|
36
|
+
char *rubyjsonnet_str_to_ptr(struct JsonnetVm *vm, VALUE str, size_t *buflen);
|
36
37
|
VALUE rubyjsonnet_format_exception(VALUE exc);
|
37
38
|
int rubyjsonnet_jump_tag(const char *exc_mesg);
|
38
39
|
|
data/ext/jsonnet/vm.c
CHANGED
@@ -59,16 +59,15 @@ rubyjsonnet_obj_to_vm(VALUE wrap)
|
|
59
59
|
}
|
60
60
|
|
61
61
|
static VALUE
|
62
|
-
|
62
|
+
vm_s_allocate(VALUE klass)
|
63
63
|
{
|
64
64
|
struct jsonnet_vm_wrap *vm;
|
65
|
-
VALUE self = TypedData_Make_Struct(
|
65
|
+
VALUE self = TypedData_Make_Struct(klass, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm);
|
66
66
|
vm->vm = jsonnet_make();
|
67
67
|
vm->import_callback = Qnil;
|
68
68
|
vm->native_callbacks.len = 0;
|
69
69
|
vm->native_callbacks.contexts = NULL;
|
70
70
|
|
71
|
-
rb_obj_call_init(self, argc, argv);
|
72
71
|
return self;
|
73
72
|
}
|
74
73
|
|
@@ -81,11 +80,10 @@ vm_free(void *ptr)
|
|
81
80
|
|
82
81
|
for (i = 0; i < vm->native_callbacks.len; ++i) {
|
83
82
|
struct native_callback_ctx *ctx = vm->native_callbacks.contexts[i];
|
84
|
-
|
83
|
+
xfree(ctx);
|
85
84
|
}
|
86
|
-
|
87
|
-
|
88
|
-
RB_REALLOC_N(vm, struct jsonnet_vm_wrap, 0);
|
85
|
+
xfree(vm->native_callbacks.contexts);
|
86
|
+
xfree(vm);
|
89
87
|
}
|
90
88
|
|
91
89
|
static void
|
@@ -390,7 +388,7 @@ void
|
|
390
388
|
rubyjsonnet_init_vm(VALUE mJsonnet)
|
391
389
|
{
|
392
390
|
cVM = rb_define_class_under(mJsonnet, "VM", rb_cObject);
|
393
|
-
|
391
|
+
rb_define_alloc_func(cVM, vm_s_allocate);
|
394
392
|
rb_define_private_method(cVM, "eval_file", vm_evaluate_file, 3);
|
395
393
|
rb_define_private_method(cVM, "eval_snippet", vm_evaluate, 3);
|
396
394
|
rb_define_private_method(cVM, "fmt_file", vm_fmt_file, 2);
|
data/lib/jsonnet/version.rb
CHANGED
data/test/test_vm.rb
CHANGED
@@ -54,7 +54,6 @@ class TestVM < Test::Unit::TestCase
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
57
|
test 'Jsonnet::VM#evaluate evaluates snippet' do
|
59
58
|
vm = Jsonnet::VM.new
|
60
59
|
result = vm.evaluate(<<-EOS, filename: 'example.snippet')
|
@@ -288,6 +287,26 @@ class TestVM < Test::Unit::TestCase
|
|
288
287
|
assert_equal expected, JSON.parse(result)
|
289
288
|
end
|
290
289
|
|
290
|
+
test "Jsonnet::VM#import_callback allows NUL char in Jsonnet v0.19 or later" do
|
291
|
+
return unless Jsonnet.libversion >= "v0.19"
|
292
|
+
|
293
|
+
example_str = "\x0\x1".force_encoding(Encoding::BINARY)
|
294
|
+
|
295
|
+
vm = Jsonnet::VM.new
|
296
|
+
vm.import_callback = ->(base, rel) {
|
297
|
+
case [base, rel]
|
298
|
+
when ['/path/to/base/', 'foo.bin']
|
299
|
+
return "\x0\x1".force_encoding(Encoding::BINARY), '/path/to/base/foo.bin'
|
300
|
+
else
|
301
|
+
raise Errno::ENOENT, "#{rel} at #{base}"
|
302
|
+
end
|
303
|
+
}
|
304
|
+
result = vm.evaluate(<<-EOS, filename: "/path/to/base/example.jsonnet")
|
305
|
+
importbin "foo.bin"
|
306
|
+
EOS
|
307
|
+
assert_equal [0, 1], JSON.parse(result)
|
308
|
+
end
|
309
|
+
|
291
310
|
test "Jsonnet::VM#evaluate returns an error if customized import callback raises an exception" do
|
292
311
|
vm = Jsonnet::VM.new
|
293
312
|
called = false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuki Yugui Sonoda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mini_portile2
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.4.1
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: Jsonnet library
|