jsonnet 0.5.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21fb3547860dbf786a960705f8ec154f2068b07679091020da431fd1b407a4fd
4
- data.tar.gz: 7860579f2f6931a3635ccae64de7c2de558644e6833e302b6511efb00f494a17
3
+ metadata.gz: d4340172a08a949087e54c213842fe9a3ee445ec9149bc39f8dc56371d2199f6
4
+ data.tar.gz: 1e068cb049eda5218e0a49984bd581e22147f3d98f4db11a2d0fb082490e5001
5
5
  SHA512:
6
- metadata.gz: b1abbd8abe2a2670b366bd249ed92106d06c55e43db8c3ffd4c263c7151b985361a653f8d032782e0a5a3900af0e26d3f2a6a761246669463fbc0d22999df498
7
- data.tar.gz: 59e92b2680be878b8dfeb29c876aa877eaa22562ee5e60a4deb98f24b8e7cf27702f1e3b78404f31f21be1e6d0475e606e90398805f1b92d20bcdbcdd1ef7b7d
6
+ metadata.gz: 9d532a2079abd6d4612f0f14bed63ed245302478251dedff199f02572a5e7f5400c07c76f9bf649da67607ad1c904cc49089a3c481614a90d36163427dd91e01
7
+ data.tar.gz: d2d41cca8cab085b6fe38fda48886706bb2f8876ff1f4e557e9310fd955b11f5784001f11c93c3bb509bfb6df542fced240733cd64478e3bf69c5ae21cbf094d
@@ -14,7 +14,7 @@ jobs:
14
14
  name: Test
15
15
  strategy:
16
16
  matrix:
17
- ruby-version: ['2.7', '3.0', '3.1', '3.2']
17
+ ruby-version: ['3.0', '3.1', '3.2', '3.3']
18
18
  os: ['ubuntu-latest', 'macos-latest']
19
19
  runs-on: ${{ matrix.os }}
20
20
 
@@ -104,9 +104,15 @@ rubyjsonnet_jump_tag(const char *exc_mesg)
104
104
  return 0;
105
105
  }
106
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
107
112
  static char *
108
113
  import_callback_entrypoint(void *ctx, const char *base, const char *rel, char **found_here,
109
114
  int *success)
115
+ #endif
110
116
  {
111
117
  struct jsonnet_vm_wrap *const vm = (struct jsonnet_vm_wrap *)ctx;
112
118
  int state;
@@ -123,14 +129,24 @@ import_callback_entrypoint(void *ctx, const char *base, const char *rel, char **
123
129
 
124
130
  if (state) {
125
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
126
136
  *success = 0;
127
137
  return rubyjsonnet_str_to_cstr(vm->vm, msg);
138
+ #endif
128
139
  }
129
140
 
130
141
  result = rb_Array(result);
131
- *success = 1;
132
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;
133
148
  return rubyjsonnet_str_to_cstr(vm->vm, rb_ary_entry(result, 0));
149
+ #endif
134
150
  }
135
151
 
136
152
  /*
@@ -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.18.0')
17
- recipe.files = ['https://github.com/google/jsonnet/archive/v0.18.0.tar.gz']
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')
@@ -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
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Jsonnet
2
- VERSION = "0.5.3"
2
+ VERSION = "0.6.0"
3
3
  end
data/test/test_vm.rb CHANGED
@@ -287,6 +287,26 @@ class TestVM < Test::Unit::TestCase
287
287
  assert_equal expected, JSON.parse(result)
288
288
  end
289
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
+
290
310
  test "Jsonnet::VM#evaluate returns an error if customized import callback raises an exception" do
291
311
  vm = Jsonnet::VM.new
292
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.5.3
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: 2023-03-26 00:00:00.000000000 Z
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.3.7
133
+ rubygems_version: 3.4.1
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Jsonnet library