ed-precompiled_json 2.15.1-arm64-darwin

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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/BSDL +22 -0
  3. data/CHANGES.md +693 -0
  4. data/COPYING +56 -0
  5. data/LEGAL +8 -0
  6. data/README.md +283 -0
  7. data/ext/json/ext/fbuffer/fbuffer.h +296 -0
  8. data/ext/json/ext/generator/extconf.rb +16 -0
  9. data/ext/json/ext/generator/generator.c +2169 -0
  10. data/ext/json/ext/parser/extconf.rb +15 -0
  11. data/ext/json/ext/parser/parser.c +1557 -0
  12. data/ext/json/ext/simd/conf.rb +24 -0
  13. data/ext/json/ext/simd/simd.h +188 -0
  14. data/ext/json/ext/vendor/fpconv.c +480 -0
  15. data/ext/json/ext/vendor/jeaiii-ltoa.h +267 -0
  16. data/json.gemspec +62 -0
  17. data/lib/json/add/bigdecimal.rb +58 -0
  18. data/lib/json/add/complex.rb +51 -0
  19. data/lib/json/add/core.rb +13 -0
  20. data/lib/json/add/date.rb +54 -0
  21. data/lib/json/add/date_time.rb +67 -0
  22. data/lib/json/add/exception.rb +49 -0
  23. data/lib/json/add/ostruct.rb +54 -0
  24. data/lib/json/add/range.rb +54 -0
  25. data/lib/json/add/rational.rb +49 -0
  26. data/lib/json/add/regexp.rb +48 -0
  27. data/lib/json/add/set.rb +48 -0
  28. data/lib/json/add/string.rb +35 -0
  29. data/lib/json/add/struct.rb +52 -0
  30. data/lib/json/add/symbol.rb +52 -0
  31. data/lib/json/add/time.rb +52 -0
  32. data/lib/json/common.rb +1130 -0
  33. data/lib/json/ext/3.0/generator.bundle +0 -0
  34. data/lib/json/ext/3.0/parser.bundle +0 -0
  35. data/lib/json/ext/3.1/generator.bundle +0 -0
  36. data/lib/json/ext/3.1/parser.bundle +0 -0
  37. data/lib/json/ext/3.2/generator.bundle +0 -0
  38. data/lib/json/ext/3.2/parser.bundle +0 -0
  39. data/lib/json/ext/3.3/generator.bundle +0 -0
  40. data/lib/json/ext/3.3/parser.bundle +0 -0
  41. data/lib/json/ext/3.4/generator.bundle +0 -0
  42. data/lib/json/ext/3.4/parser.bundle +0 -0
  43. data/lib/json/ext/generator/state.rb +99 -0
  44. data/lib/json/ext.rb +57 -0
  45. data/lib/json/generic_object.rb +67 -0
  46. data/lib/json/truffle_ruby/generator.rb +708 -0
  47. data/lib/json/version.rb +5 -0
  48. data/lib/json.rb +642 -0
  49. metadata +99 -0
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/LEGAL ADDED
@@ -0,0 +1,8 @@
1
+ # -*- rdoc -*-
2
+
3
+ = LEGAL NOTICE INFORMATION
4
+ --------------------------
5
+
6
+ All the files in this distribution are covered under either the Ruby's
7
+ license (see the file COPYING) or public-domain except some files
8
+ mentioned below.
data/README.md ADDED
@@ -0,0 +1,283 @@
1
+ # JSON implementation for Ruby
2
+
3
+ [![CI](https://github.com/ruby/json/actions/workflows/ci.yml/badge.svg)](https://github.com/ruby/json/actions/workflows/ci.yml)
4
+
5
+ ## Description
6
+
7
+ This is an implementation of the JSON specification according to RFC 7159
8
+ http://www.ietf.org/rfc/rfc7159.txt .
9
+
10
+ The JSON generator generate UTF-8 character sequences by default.
11
+ If an :ascii\_only option with a true value is given, they escape all
12
+ non-ASCII and control characters with \uXXXX escape sequences, and support
13
+ UTF-16 surrogate pairs in order to be able to generate the whole range of
14
+ unicode code points.
15
+
16
+ All strings, that are to be encoded as JSON strings, should be UTF-8 byte
17
+ sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
18
+ encoded, please use the to\_json\_raw\_object method of String (which produces
19
+ an object, that contains a byte array) and decode the result on the receiving
20
+ endpoint.
21
+
22
+ ## Installation
23
+
24
+ Install the gem and add to the application's Gemfile by executing:
25
+
26
+ $ bundle add json
27
+
28
+ If bundler is not being used to manage dependencies, install the gem by executing:
29
+
30
+ $ gem install json
31
+
32
+ ## Basic Usage
33
+
34
+ To use JSON you can
35
+
36
+ ```ruby
37
+ require 'json'
38
+ ```
39
+
40
+ Now you can parse a JSON document into a ruby data structure by calling
41
+
42
+ ```ruby
43
+ JSON.parse(document)
44
+ ```
45
+
46
+ If you want to generate a JSON document from a ruby data structure call
47
+ ```ruby
48
+ JSON.generate(data)
49
+ ```
50
+
51
+ You can also use the `pretty_generate` method (which formats the output more
52
+ verbosely and nicely) or `fast_generate` (which doesn't do any of the security
53
+ checks generate performs, e. g. nesting deepness checks).
54
+
55
+ ## Casting non native types
56
+
57
+ JSON documents can only support Hashes, Arrays, Strings, Integers and Floats.
58
+
59
+ By default if you attempt to serialize something else, `JSON.generate` will
60
+ search for a `#to_json` method on that object:
61
+
62
+ ```ruby
63
+ Position = Struct.new(:latitude, :longitude) do
64
+ def to_json(state = nil, *)
65
+ JSON::State.from_state(state).generate({
66
+ latitude: latitude,
67
+ longitude: longitude,
68
+ })
69
+ end
70
+ end
71
+
72
+ JSON.generate([
73
+ Position.new(12323.234, 435345.233),
74
+ Position.new(23434.676, 159435.324),
75
+ ]) # => [{"latitude":12323.234,"longitude":435345.233},{"latitude":23434.676,"longitude":159435.324}]
76
+ ```
77
+
78
+ If a `#to_json` method isn't defined on the object, `JSON.generate` will fallback to call `#to_s`:
79
+
80
+ ```ruby
81
+ JSON.generate(Object.new) # => "#<Object:0x000000011e768b98>"
82
+ ```
83
+
84
+ Both of these behavior can be disabled using the `strict: true` option:
85
+
86
+ ```ruby
87
+ JSON.generate(Object.new, strict: true) # => Object not allowed in JSON (JSON::GeneratorError)
88
+ JSON.generate(Position.new(1, 2)) # => Position not allowed in JSON (JSON::GeneratorError)
89
+ ```
90
+
91
+ ## JSON::Coder
92
+
93
+ Since `#to_json` methods are global, it can sometimes be problematic if you need a given type to be
94
+ serialized in different ways in different locations.
95
+
96
+ Instead it is recommended to use the newer `JSON::Coder` API:
97
+
98
+ ```ruby
99
+ module MyApp
100
+ API_JSON_CODER = JSON::Coder.new do |object, is_object_key|
101
+ case object
102
+ when Time
103
+ object.iso8601(3)
104
+ else
105
+ object
106
+ end
107
+ end
108
+ end
109
+
110
+ puts MyApp::API_JSON_CODER.dump(Time.now.utc) # => "2025-01-21T08:41:44.286Z"
111
+ ```
112
+
113
+ The provided block is called for all objects that don't have a native JSON equivalent, and
114
+ must return a Ruby object that has a native JSON equivalent.
115
+
116
+ It is also called for objects that do have a JSON equivalent, but are used as Hash keys, for instance `{ 1 => 2}`.
117
+
118
+ ## Combining JSON fragments
119
+
120
+ To combine JSON fragments into a bigger JSON document, you can use `JSON::Fragment`:
121
+
122
+ ```ruby
123
+ posts_json = cache.fetch_multi(post_ids) do |post_id|
124
+ JSON.generate(Post.find(post_id))
125
+ end
126
+ posts_json.map! { |post_json| JSON::Fragment.new(post_json) }
127
+ JSON.generate({ posts: posts_json, count: posts_json.count })
128
+ ```
129
+
130
+ ## Round-tripping arbitrary types
131
+
132
+ > [!CAUTION]
133
+ > You should never use `JSON.unsafe_load` nor `JSON.parse(str, create_additions: true)` to parse untrusted user input,
134
+ > as it can lead to remote code execution vulnerabilities.
135
+
136
+ To create a JSON document from a ruby data structure, you can call
137
+ `JSON.generate` like that:
138
+
139
+ ```ruby
140
+ json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
141
+ # => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
142
+ ```
143
+
144
+ To get back a ruby data structure from a JSON document, you have to call
145
+ JSON.parse on it:
146
+
147
+ ```ruby
148
+ JSON.parse json
149
+ # => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
150
+ ```
151
+
152
+ Note, that the range from the original data structure is a simple
153
+ string now. The reason for this is, that JSON doesn't support ranges
154
+ or arbitrary classes. In this case the json library falls back to call
155
+ `Object#to_json`, which is the same as `#to_s.to_json`.
156
+
157
+ It's possible to add JSON support serialization to arbitrary classes by
158
+ simply implementing a more specialized version of the `#to_json method`, that
159
+ should return a JSON object (a hash converted to JSON with `#to_json`) like
160
+ this (don't forget the `*a` for all the arguments):
161
+
162
+ ```ruby
163
+ class Range
164
+ def to_json(*a)
165
+ {
166
+ 'json_class' => self.class.name, # = 'Range'
167
+ 'data' => [ first, last, exclude_end? ]
168
+ }.to_json(*a)
169
+ end
170
+ end
171
+ ```
172
+
173
+ The hash key `json_class` is the class, that will be asked to deserialise the
174
+ JSON representation later. In this case it's `Range`, but any namespace of
175
+ the form `A::B` or `::A::B` will do. All other keys are arbitrary and can be
176
+ used to store the necessary data to configure the object to be deserialised.
177
+
178
+ If the key `json_class` is found in a JSON object, the JSON parser checks
179
+ if the given class responds to the `json_create` class method. If so, it is
180
+ called with the JSON object converted to a Ruby hash. So a range can
181
+ be deserialised by implementing `Range.json_create` like this:
182
+
183
+ ```ruby
184
+ class Range
185
+ def self.json_create(o)
186
+ new(*o['data'])
187
+ end
188
+ end
189
+ ```
190
+
191
+ Now it possible to serialise/deserialise ranges as well:
192
+
193
+ ```ruby
194
+ json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
195
+ # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
196
+ JSON.parse json
197
+ # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
198
+ json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
199
+ # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
200
+ JSON.unsafe_load json
201
+ # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
202
+ ```
203
+
204
+ `JSON.generate` always creates the shortest possible string representation of a
205
+ ruby data structure in one line. This is good for data storage or network
206
+ protocols, but not so good for humans to read. Fortunately there's also
207
+ `JSON.pretty_generate` (or `JSON.pretty_generate`) that creates a more readable
208
+ output:
209
+
210
+ ```ruby
211
+ puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
212
+ [
213
+ 1,
214
+ 2,
215
+ {
216
+ "a": 3.141
217
+ },
218
+ false,
219
+ true,
220
+ null,
221
+ {
222
+ "json_class": "Range",
223
+ "data": [
224
+ 4,
225
+ 10,
226
+ false
227
+ ]
228
+ }
229
+ ]
230
+ ```
231
+
232
+ There are also the methods `Kernel#j` for generate, and `Kernel#jj` for
233
+ `pretty_generate` output to the console, that work analogous to Core Ruby's `p` and
234
+ the `pp` library's `pp` methods.
235
+
236
+ ## Development
237
+
238
+ ### Prerequisites
239
+
240
+ 1. Clone the repository
241
+ 2. Install dependencies with `bundle install`
242
+
243
+ ### Testing
244
+
245
+ The full test suite can be run with:
246
+
247
+ ```bash
248
+ bundle exec rake test
249
+ ```
250
+
251
+ ### Release
252
+
253
+ Update the `lib/json/version.rb` file.
254
+
255
+ ```
256
+ rbenv shell 2.6.5
257
+ rake build
258
+ gem push pkg/json-2.3.0.gem
259
+
260
+ rbenv shell jruby-9.2.9.0
261
+ rake build
262
+ gem push pkg/json-2.3.0-java.gem
263
+ ```
264
+
265
+ ## Author
266
+
267
+ Florian Frank <mailto:flori@ping.de>
268
+
269
+ ## License
270
+
271
+ Ruby License, see https://www.ruby-lang.org/en/about/license.txt.
272
+
273
+ ## Download
274
+
275
+ The latest version of this library can be downloaded at
276
+
277
+ * https://rubygems.org/gems/json
278
+
279
+ Online Documentation should be located at
280
+
281
+ * https://www.rubydoc.info/gems/json
282
+
283
+ [Ragel]: http://www.colm.net/open-source/ragel/
@@ -0,0 +1,296 @@
1
+ #ifndef _FBUFFER_H_
2
+ #define _FBUFFER_H_
3
+
4
+ #include "ruby.h"
5
+ #include "ruby/encoding.h"
6
+ #include "../vendor/jeaiii-ltoa.h"
7
+
8
+ /* shims */
9
+ /* This is the fallback definition from Ruby 3.4 */
10
+
11
+ #ifndef RBIMPL_STDBOOL_H
12
+ #if defined(__cplusplus)
13
+ # if defined(HAVE_STDBOOL_H) && (__cplusplus >= 201103L)
14
+ # include <cstdbool>
15
+ # endif
16
+ #elif defined(HAVE_STDBOOL_H)
17
+ # include <stdbool.h>
18
+ #elif !defined(HAVE__BOOL)
19
+ typedef unsigned char _Bool;
20
+ # define bool _Bool
21
+ # define true ((_Bool)+1)
22
+ # define false ((_Bool)+0)
23
+ # define __bool_true_false_are_defined
24
+ #endif
25
+ #endif
26
+
27
+ #ifndef NOINLINE
28
+ #if defined(__has_attribute) && __has_attribute(noinline)
29
+ #define NOINLINE() __attribute__((noinline))
30
+ #else
31
+ #define NOINLINE()
32
+ #endif
33
+ #endif
34
+
35
+ #ifndef RB_UNLIKELY
36
+ #define RB_UNLIKELY(expr) expr
37
+ #endif
38
+
39
+ #ifndef RB_LIKELY
40
+ #define RB_LIKELY(expr) expr
41
+ #endif
42
+
43
+ #ifndef MAYBE_UNUSED
44
+ # define MAYBE_UNUSED(x) x
45
+ #endif
46
+
47
+ #ifdef RUBY_DEBUG
48
+ #ifndef JSON_DEBUG
49
+ #define JSON_DEBUG RUBY_DEBUG
50
+ #endif
51
+ #endif
52
+
53
+ enum fbuffer_type {
54
+ FBUFFER_HEAP_ALLOCATED = 0,
55
+ FBUFFER_STACK_ALLOCATED = 1,
56
+ };
57
+
58
+ typedef struct FBufferStruct {
59
+ enum fbuffer_type type;
60
+ unsigned long initial_length;
61
+ unsigned long len;
62
+ unsigned long capa;
63
+ #ifdef JSON_DEBUG
64
+ unsigned long requested;
65
+ #endif
66
+ char *ptr;
67
+ VALUE io;
68
+ } FBuffer;
69
+
70
+ #define FBUFFER_STACK_SIZE 512
71
+ #define FBUFFER_IO_BUFFER_SIZE (16384 - 1)
72
+ #define FBUFFER_INITIAL_LENGTH_DEFAULT 1024
73
+
74
+ #define FBUFFER_PTR(fb) ((fb)->ptr)
75
+ #define FBUFFER_LEN(fb) ((fb)->len)
76
+ #define FBUFFER_CAPA(fb) ((fb)->capa)
77
+ #define FBUFFER_PAIR(fb) FBUFFER_PTR(fb), FBUFFER_LEN(fb)
78
+
79
+ static void fbuffer_free(FBuffer *fb);
80
+ static void fbuffer_clear(FBuffer *fb);
81
+ static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long len);
82
+ static void fbuffer_append_long(FBuffer *fb, long number);
83
+ static inline void fbuffer_append_char(FBuffer *fb, char newchr);
84
+ static VALUE fbuffer_finalize(FBuffer *fb);
85
+
86
+ static void fbuffer_stack_init(FBuffer *fb, unsigned long initial_length, char *stack_buffer, long stack_buffer_size)
87
+ {
88
+ fb->initial_length = (initial_length > 0) ? initial_length : FBUFFER_INITIAL_LENGTH_DEFAULT;
89
+ if (stack_buffer) {
90
+ fb->type = FBUFFER_STACK_ALLOCATED;
91
+ fb->ptr = stack_buffer;
92
+ fb->capa = stack_buffer_size;
93
+ }
94
+ #ifdef JSON_DEBUG
95
+ fb->requested = 0;
96
+ #endif
97
+ }
98
+
99
+ static inline void fbuffer_consumed(FBuffer *fb, unsigned long consumed)
100
+ {
101
+ #ifdef JSON_DEBUG
102
+ if (consumed > fb->requested) {
103
+ rb_bug("fbuffer: Out of bound write");
104
+ }
105
+ fb->requested = 0;
106
+ #endif
107
+ fb->len += consumed;
108
+ }
109
+
110
+ static void fbuffer_free(FBuffer *fb)
111
+ {
112
+ if (fb->ptr && fb->type == FBUFFER_HEAP_ALLOCATED) {
113
+ ruby_xfree(fb->ptr);
114
+ }
115
+ }
116
+
117
+ static void fbuffer_clear(FBuffer *fb)
118
+ {
119
+ fb->len = 0;
120
+ }
121
+
122
+ static void fbuffer_flush(FBuffer *fb)
123
+ {
124
+ rb_io_write(fb->io, rb_utf8_str_new(fb->ptr, fb->len));
125
+ fbuffer_clear(fb);
126
+ }
127
+
128
+ static void fbuffer_realloc(FBuffer *fb, unsigned long required)
129
+ {
130
+ if (required > fb->capa) {
131
+ if (fb->type == FBUFFER_STACK_ALLOCATED) {
132
+ const char *old_buffer = fb->ptr;
133
+ fb->ptr = ALLOC_N(char, required);
134
+ fb->type = FBUFFER_HEAP_ALLOCATED;
135
+ MEMCPY(fb->ptr, old_buffer, char, fb->len);
136
+ } else {
137
+ REALLOC_N(fb->ptr, char, required);
138
+ }
139
+ fb->capa = required;
140
+ }
141
+ }
142
+
143
+ static void fbuffer_do_inc_capa(FBuffer *fb, unsigned long requested)
144
+ {
145
+ if (RB_UNLIKELY(fb->io)) {
146
+ if (fb->capa < FBUFFER_IO_BUFFER_SIZE) {
147
+ fbuffer_realloc(fb, FBUFFER_IO_BUFFER_SIZE);
148
+ } else {
149
+ fbuffer_flush(fb);
150
+ }
151
+
152
+ if (RB_LIKELY(requested < fb->capa)) {
153
+ return;
154
+ }
155
+ }
156
+
157
+ unsigned long required;
158
+
159
+ if (RB_UNLIKELY(!fb->ptr)) {
160
+ fb->ptr = ALLOC_N(char, fb->initial_length);
161
+ fb->capa = fb->initial_length;
162
+ }
163
+
164
+ for (required = fb->capa; requested > required - fb->len; required <<= 1);
165
+
166
+ fbuffer_realloc(fb, required);
167
+ }
168
+
169
+ static inline void fbuffer_inc_capa(FBuffer *fb, unsigned long requested)
170
+ {
171
+ #ifdef JSON_DEBUG
172
+ fb->requested = requested;
173
+ #endif
174
+
175
+ if (RB_UNLIKELY(requested > fb->capa - fb->len)) {
176
+ fbuffer_do_inc_capa(fb, requested);
177
+ }
178
+ }
179
+
180
+ static inline void fbuffer_append_reserved(FBuffer *fb, const char *newstr, unsigned long len)
181
+ {
182
+ MEMCPY(fb->ptr + fb->len, newstr, char, len);
183
+ fbuffer_consumed(fb, len);
184
+ }
185
+
186
+ static inline void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long len)
187
+ {
188
+ if (len > 0) {
189
+ fbuffer_inc_capa(fb, len);
190
+ fbuffer_append_reserved(fb, newstr, len);
191
+ }
192
+ }
193
+
194
+ /* Appends a character into a buffer. The buffer needs to have sufficient capacity, via fbuffer_inc_capa(...). */
195
+ static inline void fbuffer_append_reserved_char(FBuffer *fb, char chr)
196
+ {
197
+ #ifdef JSON_DEBUG
198
+ if (fb->requested < 1) {
199
+ rb_bug("fbuffer: unreserved write");
200
+ }
201
+ fb->requested--;
202
+ #endif
203
+
204
+ fb->ptr[fb->len] = chr;
205
+ fb->len++;
206
+ }
207
+
208
+ static void fbuffer_append_str(FBuffer *fb, VALUE str)
209
+ {
210
+ const char *newstr = StringValuePtr(str);
211
+ unsigned long len = RSTRING_LEN(str);
212
+
213
+ fbuffer_append(fb, newstr, len);
214
+ }
215
+
216
+ static void fbuffer_append_str_repeat(FBuffer *fb, VALUE str, size_t repeat)
217
+ {
218
+ const char *newstr = StringValuePtr(str);
219
+ unsigned long len = RSTRING_LEN(str);
220
+
221
+ fbuffer_inc_capa(fb, repeat * len);
222
+ while (repeat) {
223
+ #ifdef JSON_DEBUG
224
+ fb->requested = len;
225
+ #endif
226
+ fbuffer_append_reserved(fb, newstr, len);
227
+ repeat--;
228
+ }
229
+ }
230
+
231
+ static inline void fbuffer_append_char(FBuffer *fb, char newchr)
232
+ {
233
+ fbuffer_inc_capa(fb, 1);
234
+ *(fb->ptr + fb->len) = newchr;
235
+ fbuffer_consumed(fb, 1);
236
+ }
237
+
238
+ static inline char *fbuffer_cursor(FBuffer *fb)
239
+ {
240
+ return fb->ptr + fb->len;
241
+ }
242
+
243
+ static inline void fbuffer_advance_to(FBuffer *fb, char *end)
244
+ {
245
+ fbuffer_consumed(fb, (end - fb->ptr) - fb->len);
246
+ }
247
+
248
+ /*
249
+ * Appends the decimal string representation of \a number into the buffer.
250
+ */
251
+ static void fbuffer_append_long(FBuffer *fb, long number)
252
+ {
253
+ /*
254
+ * The jeaiii_ultoa() function produces digits left-to-right,
255
+ * allowing us to write directly into the buffer, but we don't know
256
+ * the number of resulting characters.
257
+ *
258
+ * We do know, however, that the `number` argument is always in the
259
+ * range 0xc000000000000000 to 0x3fffffffffffffff, or, in decimal,
260
+ * -4611686018427387904 to 4611686018427387903. The max number of chars
261
+ * generated is therefore 20 (including a potential sign character).
262
+ */
263
+
264
+ static const int MAX_CHARS_FOR_LONG = 20;
265
+
266
+ fbuffer_inc_capa(fb, MAX_CHARS_FOR_LONG);
267
+
268
+ if (number < 0) {
269
+ fbuffer_append_reserved_char(fb, '-');
270
+
271
+ /*
272
+ * Since number is always > LONG_MIN, `-number` will not overflow
273
+ * and is always the positive abs() value.
274
+ */
275
+ number = -number;
276
+ }
277
+
278
+ char *end = jeaiii_ultoa(fbuffer_cursor(fb), number);
279
+ fbuffer_advance_to(fb, end);
280
+ }
281
+
282
+ static VALUE fbuffer_finalize(FBuffer *fb)
283
+ {
284
+ if (fb->io) {
285
+ fbuffer_flush(fb);
286
+ fbuffer_free(fb);
287
+ rb_io_flush(fb->io);
288
+ return fb->io;
289
+ } else {
290
+ VALUE result = rb_utf8_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
291
+ fbuffer_free(fb);
292
+ return result;
293
+ }
294
+ }
295
+
296
+ #endif
@@ -0,0 +1,16 @@
1
+ require 'mkmf'
2
+
3
+ if RUBY_ENGINE == 'truffleruby'
4
+ # The pure-Ruby generator is faster on TruffleRuby, so skip compiling the generator extension
5
+ File.write('Makefile', dummy_makefile("").join)
6
+ else
7
+ append_cflags("-std=c99")
8
+ $defs << "-DJSON_GENERATOR"
9
+ $defs << "-DJSON_DEBUG" if ENV["JSON_DEBUG"]
10
+
11
+ if enable_config('generator-use-simd', default=!ENV["JSON_DISABLE_SIMD"])
12
+ load __dir__ + "/../simd/conf.rb"
13
+ end
14
+
15
+ create_makefile 'json/ext/generator'
16
+ end