@port-labs/jq-node-bindings 1.0.1 → 1.0.2-rc.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.
- package/deps/jq/COPYING +1 -9
- package/deps/jq/Makefile.am +13 -18
- package/deps/jq/NEWS.md +2 -2
- package/deps/jq/README.md +3 -18
- package/deps/jq/configure.ac +1 -0
- package/deps/jq/docs/Pipfile.lock +59 -72
- package/deps/jq/docs/README.md +1 -1
- package/deps/jq/docs/build_manpage.py +1 -1
- package/deps/jq/docs/build_mantests.py +1 -1
- package/deps/jq/docs/content/download/default.yml +1 -23
- package/deps/jq/docs/content/index.yml +0 -5
- package/deps/jq/docs/content/manual/{dev/manual.yml → manual.yml} +36 -162
- package/deps/jq/docs/content/manual/v1.3/manual.yml +5 -0
- package/deps/jq/docs/content/manual/v1.4/manual.yml +5 -0
- package/deps/jq/docs/content/manual/v1.5/manual.yml +8 -3
- package/deps/jq/docs/content/manual/v1.6/manual.yml +8 -3
- package/deps/jq/docs/content/manual/v1.7/manual.yml +11 -6
- package/deps/jq/docs/content/tutorial/default.yml +3 -3
- package/deps/jq/docs/manual_schema.yml +3 -0
- package/deps/jq/docs/templates/index.html.j2 +6 -6
- package/deps/jq/docs/templates/manual.html.j2 +1 -11
- package/deps/jq/jq.1.prebuilt +26 -162
- package/deps/jq/jq.spec +1 -1
- package/deps/jq/src/builtin.c +211 -298
- package/deps/jq/src/builtin.jq +7 -13
- package/deps/jq/src/bytecode.h +3 -8
- package/deps/jq/src/compile.c +2 -2
- package/deps/jq/src/decNumber/decBasic.c +1 -1
- package/deps/jq/src/decNumber/decCommon.c +1 -1
- package/deps/jq/src/decNumber/decNumber.c +4 -4
- package/deps/jq/src/execute.c +42 -22
- package/deps/jq/src/jq.h +1 -1
- package/deps/jq/src/jq_test.c +7 -69
- package/deps/jq/src/jv.c +12 -17
- package/deps/jq/src/jv.h +0 -3
- package/deps/jq/src/jv_aux.c +4 -3
- package/deps/jq/src/jv_dtoa.c +1 -1
- package/deps/jq/src/jv_parse.c +0 -2
- package/deps/jq/src/jv_print.c +27 -21
- package/deps/jq/src/jv_unicode.c +0 -18
- package/deps/jq/src/jv_unicode.h +0 -2
- package/deps/jq/src/lexer.c +262 -283
- package/deps/jq/src/lexer.h +2 -3
- package/deps/jq/src/lexer.l +1 -7
- package/deps/jq/src/libm.h +5 -15
- package/deps/jq/src/linker.c +4 -6
- package/deps/jq/src/main.c +252 -179
- package/deps/jq/src/util.c +35 -41
- package/deps/jq/src/util.h +1 -1
- package/deps/jq/tests/jq.test +10 -148
- package/deps/jq/tests/jq_fuzz_load_file.c +0 -1
- package/deps/jq/tests/man.test +8 -26
- package/deps/jq/tests/setup +0 -4
- package/deps/jq/tests/shtest +39 -150
- package/index.d.ts +3 -2
- package/lib/jq.js +2 -2
- package/lib/templateAsync.js +8 -15
- package/package.json +2 -2
- package/src/binding.cc +46 -27
- package/test/santiy-async.test.js +4 -0
- package/deps/jq/sig/v1.7.1/jq-1.7.1.tar.gz.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-1.7.1.zip.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-amd64.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-arm64.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-armel.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-armhf.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-i386.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-mips.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-mips64.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-mips64el.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-mips64r6.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-mips64r6el.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-mipsel.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-mipsr6.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-mipsr6el.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-powerpc.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-ppc64el.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-riscv64.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux-s390x.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-linux64.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-macos-amd64.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-macos-arm64.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-osx-amd64.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-win64.exe.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-windows-amd64.exe.asc +0 -16
- package/deps/jq/sig/v1.7.1/jq-windows-i386.exe.asc +0 -16
- package/deps/jq/sig/v1.7.1/sha256sum.txt +0 -26
- package/deps/jq/tests/uri.test +0 -38
- package/deps/jq/tests/uritest +0 -5
package/deps/jq/src/builtin.jq
CHANGED
|
@@ -8,8 +8,7 @@ def unique: group_by(.) | map(.[0]);
|
|
|
8
8
|
def unique_by(f): group_by(f) | map(.[0]);
|
|
9
9
|
def max_by(f): _max_by_impl(map([f]));
|
|
10
10
|
def min_by(f): _min_by_impl(map([f]));
|
|
11
|
-
def add
|
|
12
|
-
def add: add(.[]);
|
|
11
|
+
def add: reduce .[] as $x (null; . + $x);
|
|
13
12
|
def del(f): delpaths([path(f)]);
|
|
14
13
|
def abs: if . < 0 then - . else . end;
|
|
15
14
|
def _assign(paths; $value): reduce path(paths) as $p (.; setpath($p; $value));
|
|
@@ -75,8 +74,6 @@ def fromdateiso8601: strptime("%Y-%m-%dT%H:%M:%SZ")|mktime;
|
|
|
75
74
|
def todateiso8601: strftime("%Y-%m-%dT%H:%M:%SZ");
|
|
76
75
|
def fromdate: fromdateiso8601;
|
|
77
76
|
def todate: todateiso8601;
|
|
78
|
-
def ltrimstr($left): if startswith($left) then .[$left | length:] end;
|
|
79
|
-
def rtrimstr($right): if endswith($right) then .[:$right | -length] end;
|
|
80
77
|
def match(re; mode): _match_impl(re; mode; false)|.[];
|
|
81
78
|
def match($val): ($val|type) as $vt | if $vt == "string" then match($val; null)
|
|
82
79
|
elif $vt == "array" and ($val | length) > 1 then match($val[0]; $val[1])
|
|
@@ -149,14 +146,10 @@ def until(cond; next):
|
|
|
149
146
|
def _until:
|
|
150
147
|
if cond then . else (next|_until) end;
|
|
151
148
|
_until;
|
|
152
|
-
def limit($n;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
def skip($n; expr):
|
|
157
|
-
if $n > 0 then foreach expr as $item ($n; . - 1; if . < 0 then $item else empty end)
|
|
158
|
-
elif $n == 0 then expr
|
|
159
|
-
else error("skip doesn't support negative count") end;
|
|
149
|
+
def limit($n; exp):
|
|
150
|
+
if $n > 0 then label $out | foreach exp as $item ($n; .-1; $item, if . <= 0 then break $out else empty end)
|
|
151
|
+
elif $n == 0 then empty
|
|
152
|
+
else exp end;
|
|
160
153
|
# range/3, with a `by` expression argument
|
|
161
154
|
def range($init; $upto; $by):
|
|
162
155
|
if $by > 0 then $init|while(. < $upto; . + $by)
|
|
@@ -170,9 +163,10 @@ def all(condition): all(.[]; condition);
|
|
|
170
163
|
def any(condition): any(.[]; condition);
|
|
171
164
|
def all: all(.[]; .);
|
|
172
165
|
def any: any(.[]; .);
|
|
166
|
+
def last(g): reduce g as $item (null; $item);
|
|
173
167
|
def nth($n; g):
|
|
174
168
|
if $n < 0 then error("nth doesn't support negative indices")
|
|
175
|
-
else
|
|
169
|
+
else label $out | foreach g as $item ($n + 1; . - 1; if . <= 0 then $item, break $out else empty end) end;
|
|
176
170
|
def first: .[0];
|
|
177
171
|
def last: .[-1];
|
|
178
172
|
def nth($n): .[$n];
|
package/deps/jq/src/bytecode.h
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#define BYTECODE_H
|
|
3
3
|
#include <stdint.h>
|
|
4
4
|
|
|
5
|
-
#include "
|
|
5
|
+
#include "jv.h"
|
|
6
6
|
|
|
7
7
|
typedef enum {
|
|
8
8
|
#define OP(name, imm, in, out) name,
|
|
@@ -44,14 +44,9 @@ struct opcode_description {
|
|
|
44
44
|
const struct opcode_description* opcode_describe(opcode op);
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
#define MAX_CFUNCTION_ARGS
|
|
47
|
+
#define MAX_CFUNCTION_ARGS 10
|
|
48
48
|
struct cfunction {
|
|
49
|
-
|
|
50
|
-
jv (*a1)(jq_state *, jv);
|
|
51
|
-
jv (*a2)(jq_state *, jv, jv);
|
|
52
|
-
jv (*a3)(jq_state *, jv, jv, jv);
|
|
53
|
-
jv (*a4)(jq_state *, jv, jv, jv, jv);
|
|
54
|
-
} fptr;
|
|
49
|
+
jv (*fptr)();
|
|
55
50
|
const char* name;
|
|
56
51
|
int nargs;
|
|
57
52
|
};
|
package/deps/jq/src/compile.c
CHANGED
|
@@ -832,7 +832,7 @@ block gen_reduce(block source, block matcher, block init, block body) {
|
|
|
832
832
|
block loop = BLOCK(gen_op_simple(DUPN),
|
|
833
833
|
source,
|
|
834
834
|
bind_alternation_matchers(matcher,
|
|
835
|
-
BLOCK(gen_op_bound(
|
|
835
|
+
BLOCK(gen_op_bound(LOADVN, res_var),
|
|
836
836
|
body,
|
|
837
837
|
gen_op_bound(STOREV, res_var))),
|
|
838
838
|
gen_op_simple(BACKTRACK));
|
|
@@ -854,7 +854,7 @@ block gen_foreach(block source, block matcher, block init, block update, block e
|
|
|
854
854
|
// in the body to see
|
|
855
855
|
bind_alternation_matchers(matcher,
|
|
856
856
|
// load the loop state variable
|
|
857
|
-
BLOCK(gen_op_bound(
|
|
857
|
+
BLOCK(gen_op_bound(LOADVN, state_var),
|
|
858
858
|
// generate updated state
|
|
859
859
|
update,
|
|
860
860
|
// save the updated state for value extraction
|
|
@@ -756,7 +756,7 @@ static void decFiniteMultiply(bcdnum *num, uByte *bcdacc,
|
|
|
756
756
|
#endif
|
|
757
757
|
|
|
758
758
|
/* Effect the multiplication */
|
|
759
|
-
// The
|
|
759
|
+
// The multiplcation proceeds using MFC's lazy-carry resolution
|
|
760
760
|
// algorithm from decNumber. First, the multiplication is
|
|
761
761
|
// effected, allowing accumulation of the partial products (which
|
|
762
762
|
// are in base-billion at each column position) into 64 bits
|
|
@@ -376,7 +376,7 @@ static decFloat * decFinalize(decFloat *df, bcdnum *num,
|
|
|
376
376
|
UBFROMUI(ub-3, 0); // to 00000000
|
|
377
377
|
}
|
|
378
378
|
// [note ub could now be to left of msd, and it is not safe
|
|
379
|
-
// to write to the left of the msd]
|
|
379
|
+
// to write to the the left of the msd]
|
|
380
380
|
// now at most 3 digits left to non-9 (usually just the one)
|
|
381
381
|
for (; ub>=umsd; *ub=0, ub--) {
|
|
382
382
|
if (*ub==9) continue; // carry
|
|
@@ -2168,7 +2168,7 @@ decNumber * decNumberPower(decNumber *res, const decNumber *lhs,
|
|
|
2168
2168
|
// if a negative power the constant 1 is needed, and if not subset
|
|
2169
2169
|
// invert the lhs now rather than inverting the result later
|
|
2170
2170
|
if (decNumberIsNegative(rhs)) { // was a **-n [hence digits>0]
|
|
2171
|
-
decNumber *inv=invbuff; //
|
|
2171
|
+
decNumber *inv=invbuff; // asssume use fixed buffer
|
|
2172
2172
|
decNumberCopy(&dnOne, dac); // dnOne=1; [needed now or later]
|
|
2173
2173
|
#if DECSUBSET
|
|
2174
2174
|
if (set->extended) { // need to calculate 1/lhs
|
|
@@ -3798,7 +3798,7 @@ static void decToString(const decNumber *dn, char *string, Flag eng) {
|
|
|
3798
3798
|
/* */
|
|
3799
3799
|
/* Addition, especially x=x+1, is speed-critical. */
|
|
3800
3800
|
/* The static buffer is larger than might be expected to allow for */
|
|
3801
|
-
/* calls from higher-level
|
|
3801
|
+
/* calls from higher-level funtions (notable exp). */
|
|
3802
3802
|
/* ------------------------------------------------------------------ */
|
|
3803
3803
|
static decNumber * decAddOp(decNumber *res, const decNumber *lhs,
|
|
3804
3804
|
const decNumber *rhs, decContext *set,
|
|
@@ -4212,7 +4212,7 @@ static decNumber * decAddOp(decNumber *res, const decNumber *lhs,
|
|
|
4212
4212
|
/* long subtractions. These are acc and var1 respectively. */
|
|
4213
4213
|
/* var1 is a copy of the lhs coefficient, var2 is the rhs coefficient.*/
|
|
4214
4214
|
/* The static buffers may be larger than might be expected to allow */
|
|
4215
|
-
/* for calls from higher-level
|
|
4215
|
+
/* for calls from higher-level funtions (notable exp). */
|
|
4216
4216
|
/* ------------------------------------------------------------------ */
|
|
4217
4217
|
static decNumber * decDivideOp(decNumber *res,
|
|
4218
4218
|
const decNumber *lhs, const decNumber *rhs,
|
|
@@ -5203,7 +5203,7 @@ static decNumber * decMultiplyOp(decNumber *res, const decNumber *lhs,
|
|
|
5203
5203
|
/* exp(-x) where x can be the tiniest number (Ntiny). */
|
|
5204
5204
|
/* */
|
|
5205
5205
|
/* 2. Normalizing x to be <=0.1 (instead of <=1) reduces loop */
|
|
5206
|
-
/* iterations by
|
|
5206
|
+
/* iterations by appoximately a third with additional (although */
|
|
5207
5207
|
/* diminishing) returns as the range is reduced to even smaller */
|
|
5208
5208
|
/* fractions. However, h (the power of 10 used to correct the */
|
|
5209
5209
|
/* result at the end, see below) must be kept <=8 as otherwise */
|
package/deps/jq/src/execute.c
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
#include "builtin.h"
|
|
19
19
|
#include "util.h"
|
|
20
20
|
#include "linker.h"
|
|
21
|
+
#include "time.h"
|
|
22
|
+
|
|
23
|
+
#define CHECK_TIMEOUT_FREQ 100
|
|
21
24
|
|
|
22
25
|
struct jq_state {
|
|
23
26
|
void (*nomem_handler)(void *);
|
|
@@ -315,9 +318,7 @@ static void jq_reset(jq_state *jq) {
|
|
|
315
318
|
|
|
316
319
|
jq->halted = 0;
|
|
317
320
|
jv_free(jq->exit_code);
|
|
318
|
-
jq->exit_code = jv_invalid();
|
|
319
321
|
jv_free(jq->error_message);
|
|
320
|
-
jq->error_message = jv_invalid();
|
|
321
322
|
if (jv_get_kind(jq->path) != JV_KIND_INVALID)
|
|
322
323
|
jv_free(jq->path);
|
|
323
324
|
jq->path = jv_null();
|
|
@@ -340,7 +341,9 @@ static void set_error(jq_state *jq, jv value) {
|
|
|
340
341
|
|
|
341
342
|
#define ON_BACKTRACK(op) ((op)+NUM_OPCODES)
|
|
342
343
|
|
|
343
|
-
jv jq_next(jq_state *jq) {
|
|
344
|
+
jv jq_next(jq_state *jq, unsigned int timeout_sec) {
|
|
345
|
+
jv cfunc_input[MAX_CFUNCTION_ARGS];
|
|
346
|
+
|
|
344
347
|
jv_nomem_handler(jq->nomem_handler, jq->nomem_handler_data);
|
|
345
348
|
|
|
346
349
|
uint16_t* pc = stack_restore(jq);
|
|
@@ -349,6 +352,9 @@ jv jq_next(jq_state *jq) {
|
|
|
349
352
|
int raising;
|
|
350
353
|
int backtracking = !jq->initial_execution;
|
|
351
354
|
|
|
355
|
+
char check_timeout_freq = CHECK_TIMEOUT_FREQ;
|
|
356
|
+
clock_t deadline = clock() + timeout_sec * CLOCKS_PER_SEC;
|
|
357
|
+
|
|
352
358
|
jq->initial_execution = 0;
|
|
353
359
|
assert(jv_get_kind(jq->error) == JV_KIND_NULL);
|
|
354
360
|
while (1) {
|
|
@@ -357,6 +363,15 @@ jv jq_next(jq_state *jq) {
|
|
|
357
363
|
printf("\t<halted>\n");
|
|
358
364
|
return jv_invalid();
|
|
359
365
|
}
|
|
366
|
+
|
|
367
|
+
if(check_timeout_freq != 0) {
|
|
368
|
+
check_timeout_freq--;
|
|
369
|
+
} else if (clock() > deadline) {
|
|
370
|
+
return jv_invalid_with_msg(jv_string("timeout"));
|
|
371
|
+
} else {
|
|
372
|
+
check_timeout_freq = CHECK_TIMEOUT_FREQ;
|
|
373
|
+
}
|
|
374
|
+
|
|
360
375
|
uint16_t opcode = *pc;
|
|
361
376
|
raising = 0;
|
|
362
377
|
|
|
@@ -521,7 +536,7 @@ jv jq_next(jq_state *jq) {
|
|
|
521
536
|
if (raising) {
|
|
522
537
|
jv_free(max);
|
|
523
538
|
goto do_backtrack;
|
|
524
|
-
}
|
|
539
|
+
}
|
|
525
540
|
if (jv_get_kind(*var) != JV_KIND_NUMBER ||
|
|
526
541
|
jv_get_kind(max) != JV_KIND_NUMBER) {
|
|
527
542
|
set_error(jq, jv_invalid_with_msg(jv_string_fmt("Range bounds must be numeric")));
|
|
@@ -781,10 +796,8 @@ jv jq_next(jq_state *jq) {
|
|
|
781
796
|
}
|
|
782
797
|
|
|
783
798
|
if (!keep_going || raising) {
|
|
784
|
-
if (keep_going)
|
|
785
|
-
jv_free(key);
|
|
799
|
+
if (keep_going)
|
|
786
800
|
jv_free(value);
|
|
787
|
-
}
|
|
788
801
|
jv_free(container);
|
|
789
802
|
goto do_backtrack;
|
|
790
803
|
} else if (is_last) {
|
|
@@ -907,27 +920,34 @@ jv jq_next(jq_state *jq) {
|
|
|
907
920
|
|
|
908
921
|
case CALL_BUILTIN: {
|
|
909
922
|
int nargs = *pc++;
|
|
910
|
-
|
|
911
|
-
jv in
|
|
912
|
-
|
|
923
|
+
jv top = stack_pop(jq);
|
|
924
|
+
jv* in = cfunc_input;
|
|
925
|
+
in[0] = top;
|
|
926
|
+
for (int i = 1; i < nargs; i++) {
|
|
913
927
|
in[i] = stack_pop(jq);
|
|
914
|
-
|
|
915
|
-
|
|
928
|
+
}
|
|
929
|
+
struct cfunction* function = &frame_current(jq)->bc->globals->cfunctions[*pc++];
|
|
916
930
|
switch (function->nargs) {
|
|
917
|
-
case 1: top = function->fptr
|
|
918
|
-
case 2: top = function->fptr
|
|
919
|
-
case 3: top = function->fptr
|
|
920
|
-
case 4: top = function->fptr
|
|
921
|
-
|
|
931
|
+
case 1: top = ((jv (*)(jq_state *, jv))function->fptr)(jq, in[0]); break;
|
|
932
|
+
case 2: top = ((jv (*)(jq_state *, jv, jv))function->fptr)(jq, in[0], in[1]); break;
|
|
933
|
+
case 3: top = ((jv (*)(jq_state *, jv, jv, jv))function->fptr)(jq, in[0], in[1], in[2]); break;
|
|
934
|
+
case 4: top = ((jv (*)(jq_state *, jv, jv, jv, jv))function->fptr)(jq, in[0], in[1], in[2], in[3]); break;
|
|
935
|
+
case 5: top = ((jv (*)(jq_state *, jv, jv, jv, jv, jv))function->fptr)(jq, in[0], in[1], in[2], in[3], in[4]); break;
|
|
936
|
+
// FIXME: a) up to 7 arguments (input + 6), b) should assert
|
|
937
|
+
// because the compiler should not generate this error.
|
|
938
|
+
default: return jv_invalid_with_msg(jv_string("Function takes too many arguments"));
|
|
922
939
|
}
|
|
923
940
|
|
|
924
|
-
if (
|
|
925
|
-
|
|
926
|
-
|
|
941
|
+
if (jv_is_valid(top)) {
|
|
942
|
+
stack_push(jq, top);
|
|
943
|
+
} else if (jv_invalid_has_msg(jv_copy(top))) {
|
|
944
|
+
set_error(jq, top);
|
|
945
|
+
goto do_backtrack;
|
|
946
|
+
} else {
|
|
947
|
+
// C-coded function returns invalid w/o msg? -> backtrack, as if
|
|
948
|
+
// it had returned `empty`
|
|
927
949
|
goto do_backtrack;
|
|
928
950
|
}
|
|
929
|
-
|
|
930
|
-
stack_push(jq, top);
|
|
931
951
|
break;
|
|
932
952
|
}
|
|
933
953
|
|
package/deps/jq/src/jq.h
CHANGED
|
@@ -27,7 +27,7 @@ int jq_compile(jq_state *, const char*);
|
|
|
27
27
|
int jq_compile_args(jq_state *, const char*, jv);
|
|
28
28
|
void jq_dump_disassembly(jq_state *, int);
|
|
29
29
|
void jq_start(jq_state *, jv value, int);
|
|
30
|
-
jv jq_next(jq_state
|
|
30
|
+
jv jq_next(jq_state *, unsigned int);
|
|
31
31
|
void jq_teardown(jq_state **);
|
|
32
32
|
|
|
33
33
|
void jq_halt(jq_state *, jv, jv);
|
package/deps/jq/src/jq_test.c
CHANGED
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
static void jv_test();
|
|
12
12
|
static void run_jq_tests(jv, int, FILE *, int, int);
|
|
13
|
-
static void run_jq_start_state_tests();
|
|
14
13
|
#ifdef HAVE_PTHREAD
|
|
15
14
|
static void run_jq_pthread_tests();
|
|
16
15
|
#endif
|
|
17
16
|
|
|
17
|
+
#define TIMEOUT_SEC 5
|
|
18
|
+
|
|
18
19
|
int jq_testsuite(jv libdirs, int verbose, int argc, char* argv[]) {
|
|
19
20
|
FILE *testdata = stdin;
|
|
20
21
|
int skip = -1;
|
|
@@ -38,7 +39,6 @@ int jq_testsuite(jv libdirs, int verbose, int argc, char* argv[]) {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
run_jq_tests(libdirs, verbose, testdata, skip, take);
|
|
41
|
-
run_jq_start_state_tests();
|
|
42
42
|
#ifdef HAVE_PTHREAD
|
|
43
43
|
run_jq_pthread_tests();
|
|
44
44
|
#endif
|
|
@@ -76,7 +76,7 @@ static void test_err_cb(void *data, jv e) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int take) {
|
|
79
|
-
char prog[4096]
|
|
79
|
+
char prog[4096];
|
|
80
80
|
char buf[4096];
|
|
81
81
|
struct err_data err_msg;
|
|
82
82
|
int tests = 0, passed = 0, invalid = 0;
|
|
@@ -195,7 +195,7 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
|
|
|
195
195
|
invalid++;
|
|
196
196
|
continue;
|
|
197
197
|
}
|
|
198
|
-
jv actual = jq_next(jq);
|
|
198
|
+
jv actual = jq_next(jq, TIMEOUT_SEC);
|
|
199
199
|
if (!jv_is_valid(actual)) {
|
|
200
200
|
jv_free(expected);
|
|
201
201
|
jv_free(actual);
|
|
@@ -210,18 +210,16 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
|
|
|
210
210
|
printf(" for test at line number %u: %s\n", lineno, prog);
|
|
211
211
|
pass = 0;
|
|
212
212
|
}
|
|
213
|
-
#ifdef USE_DECNUM
|
|
214
213
|
jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOR|JV_PRINT_REFCOUNT));
|
|
215
214
|
jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length_bytes(jv_copy(as_string)));
|
|
216
215
|
assert(jv_equal(jv_copy(expected), jv_copy(reparsed)));
|
|
217
216
|
jv_free(as_string);
|
|
218
217
|
jv_free(reparsed);
|
|
219
|
-
#endif
|
|
220
218
|
jv_free(expected);
|
|
221
219
|
jv_free(actual);
|
|
222
220
|
}
|
|
223
221
|
if (pass) {
|
|
224
|
-
jv extra = jq_next(jq);
|
|
222
|
+
jv extra = jq_next(jq, TIMEOUT_SEC);
|
|
225
223
|
if (jv_is_valid(extra)) {
|
|
226
224
|
printf("*** Superfluous result: ");
|
|
227
225
|
jv_dump(extra, 0);
|
|
@@ -253,66 +251,6 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
|
|
|
253
251
|
}
|
|
254
252
|
|
|
255
253
|
|
|
256
|
-
static int test_start_state(jq_state *jq, char *prog) {
|
|
257
|
-
int pass = 1;
|
|
258
|
-
jv message = jq_get_error_message(jq);
|
|
259
|
-
if (jv_is_valid(message)) {
|
|
260
|
-
printf("*** Expected error_message to be invalid after jq_start: %s\n", prog);
|
|
261
|
-
pass = 0;
|
|
262
|
-
}
|
|
263
|
-
jv_free(message);
|
|
264
|
-
|
|
265
|
-
jv exit_code = jq_get_exit_code(jq);
|
|
266
|
-
if (jv_is_valid(exit_code)) {
|
|
267
|
-
printf("*** Expected exit_code to be invalid after jq_start: %s\n", prog);
|
|
268
|
-
pass = 0;
|
|
269
|
-
}
|
|
270
|
-
jv_free(exit_code);
|
|
271
|
-
|
|
272
|
-
if (jq_halted(jq)) {
|
|
273
|
-
printf("*** Expected jq to not be halted after jq_start: %s\n", prog);
|
|
274
|
-
pass = 0;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return pass;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// Test jq_state is reset after subsequent calls to jq_start.
|
|
281
|
-
static void test_jq_start_resets_state(char *prog, const char *input) {
|
|
282
|
-
printf("Test jq_state: %s\n", prog);
|
|
283
|
-
jq_state *jq = jq_init();
|
|
284
|
-
assert(jq);
|
|
285
|
-
|
|
286
|
-
int compiled = jq_compile(jq, prog);
|
|
287
|
-
assert(compiled);
|
|
288
|
-
|
|
289
|
-
// First call to jq_start. Run until completion.
|
|
290
|
-
jv parsed_input = jv_parse(input);
|
|
291
|
-
assert(jv_is_valid(parsed_input));
|
|
292
|
-
jq_start(jq, parsed_input, 0);
|
|
293
|
-
assert(test_start_state(jq, prog));
|
|
294
|
-
while (1) {
|
|
295
|
-
jv result = jq_next(jq);
|
|
296
|
-
int valid = jv_is_valid(result);
|
|
297
|
-
jv_free(result);
|
|
298
|
-
if (!valid) { break; }
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// Second call to jq_start.
|
|
302
|
-
jv parsed_input2 = jv_parse(input);
|
|
303
|
-
assert(jv_is_valid(parsed_input2));
|
|
304
|
-
jq_start(jq, parsed_input2, 0);
|
|
305
|
-
assert(test_start_state(jq, prog));
|
|
306
|
-
|
|
307
|
-
jq_teardown(&jq);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
static void run_jq_start_state_tests() {
|
|
311
|
-
test_jq_start_resets_state(".[]", "[1,2,3]");
|
|
312
|
-
test_jq_start_resets_state(".[] | if .%2 == 0 then halt_error else . end", "[1,2,3]");
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
254
|
/// pthread regression test
|
|
317
255
|
#ifdef HAVE_PTHREAD
|
|
318
256
|
#define NUMBER_OF_THREADS 3
|
|
@@ -328,11 +266,11 @@ static int test_pthread_jq_parse(jq_state *jq, struct jv_parser *parser)
|
|
|
328
266
|
value = jv_parser_next(parser);
|
|
329
267
|
while (jv_is_valid(value)) {
|
|
330
268
|
jq_start(jq, value, 0);
|
|
331
|
-
jv result = jq_next(jq);
|
|
269
|
+
jv result = jq_next(jq, TIMEOUT_SEC);
|
|
332
270
|
|
|
333
271
|
while (jv_is_valid(result)) {
|
|
334
272
|
jv_free(result);
|
|
335
|
-
result = jq_next(jq);
|
|
273
|
+
result = jq_next(jq, TIMEOUT_SEC);
|
|
336
274
|
}
|
|
337
275
|
jv_free(result);
|
|
338
276
|
value = jv_parser_next(parser);
|
package/deps/jq/src/jv.c
CHANGED
|
@@ -213,9 +213,9 @@ enum {
|
|
|
213
213
|
#define JVP_FLAGS_NUMBER_LITERAL JVP_MAKE_FLAGS(JV_KIND_NUMBER, JVP_MAKE_PFLAGS(JVP_NUMBER_DECIMAL, 1))
|
|
214
214
|
|
|
215
215
|
// the decimal precision of binary double
|
|
216
|
-
#define
|
|
216
|
+
#define DEC_NUBMER_DOUBLE_PRECISION (17)
|
|
217
217
|
#define DEC_NUMBER_STRING_GUARD (14)
|
|
218
|
-
#define
|
|
218
|
+
#define DEC_NUBMER_DOUBLE_EXTRA_UNITS ((DEC_NUBMER_DOUBLE_PRECISION - DECNUMDIGITS + DECDPUN - 1)/DECDPUN)
|
|
219
219
|
|
|
220
220
|
#include "jv_thread.h"
|
|
221
221
|
#ifdef WIN32
|
|
@@ -542,7 +542,7 @@ typedef struct {
|
|
|
542
542
|
|
|
543
543
|
typedef struct {
|
|
544
544
|
decNumber number;
|
|
545
|
-
decNumberUnit units[
|
|
545
|
+
decNumberUnit units[DEC_NUBMER_DOUBLE_EXTRA_UNITS];
|
|
546
546
|
} decNumberDoublePrecision;
|
|
547
547
|
|
|
548
548
|
|
|
@@ -600,11 +600,11 @@ static double jvp_literal_number_to_double(jv j) {
|
|
|
600
600
|
|
|
601
601
|
// init as decimal64 but change digits to allow conversion to binary64 (double)
|
|
602
602
|
decContextDefault(&dblCtx, DEC_INIT_DECIMAL64);
|
|
603
|
-
dblCtx.digits =
|
|
603
|
+
dblCtx.digits = DEC_NUBMER_DOUBLE_PRECISION;
|
|
604
604
|
|
|
605
605
|
decNumber *p_dec_number = jvp_dec_number_ptr(j);
|
|
606
606
|
decNumberDoublePrecision dec_double;
|
|
607
|
-
char literal[
|
|
607
|
+
char literal[DEC_NUBMER_DOUBLE_PRECISION + DEC_NUMBER_STRING_GUARD + 1];
|
|
608
608
|
|
|
609
609
|
// reduce the number to the shortest possible form
|
|
610
610
|
// that fits into the 64 bit floating point representation
|
|
@@ -1025,13 +1025,14 @@ jv jv_array_slice(jv a, int start, int end) {
|
|
|
1025
1025
|
jv jv_array_indexes(jv a, jv b) {
|
|
1026
1026
|
jv res = jv_array();
|
|
1027
1027
|
int idx = -1;
|
|
1028
|
-
|
|
1029
|
-
|
|
1028
|
+
jv_array_foreach(a, ai, aelem) {
|
|
1029
|
+
jv_free(aelem);
|
|
1030
1030
|
jv_array_foreach(b, bi, belem) {
|
|
1031
|
-
if (!jv_equal(jv_array_get(jv_copy(a), ai + bi), belem))
|
|
1031
|
+
if (!jv_equal(jv_array_get(jv_copy(a), ai + bi), jv_copy(belem)))
|
|
1032
1032
|
idx = -1;
|
|
1033
1033
|
else if (bi == 0 && idx == -1)
|
|
1034
1034
|
idx = ai;
|
|
1035
|
+
jv_free(belem);
|
|
1035
1036
|
}
|
|
1036
1037
|
if (idx > -1)
|
|
1037
1038
|
res = jv_array_append(res, jv_number(idx));
|
|
@@ -1273,21 +1274,15 @@ jv jv_string_indexes(jv j, jv k) {
|
|
|
1273
1274
|
assert(JVP_HAS_KIND(k, JV_KIND_STRING));
|
|
1274
1275
|
const char *jstr = jv_string_value(j);
|
|
1275
1276
|
const char *idxstr = jv_string_value(k);
|
|
1276
|
-
const char *p
|
|
1277
|
+
const char *p;
|
|
1277
1278
|
int jlen = jv_string_length_bytes(jv_copy(j));
|
|
1278
1279
|
int idxlen = jv_string_length_bytes(jv_copy(k));
|
|
1279
1280
|
jv a = jv_array();
|
|
1280
1281
|
|
|
1281
1282
|
if (idxlen != 0) {
|
|
1282
|
-
|
|
1283
|
-
p = lp = jstr;
|
|
1283
|
+
p = jstr;
|
|
1284
1284
|
while ((p = _jq_memmem(p, (jstr + jlen) - p, idxstr, idxlen)) != NULL) {
|
|
1285
|
-
|
|
1286
|
-
lp += jvp_utf8_decode_length(*lp);
|
|
1287
|
-
n++;
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
a = jv_array_append(a, jv_number(n));
|
|
1285
|
+
a = jv_array_append(a, jv_number(p - jstr));
|
|
1291
1286
|
p++;
|
|
1292
1287
|
}
|
|
1293
1288
|
}
|
package/deps/jq/src/jv.h
CHANGED
|
@@ -113,9 +113,6 @@ jv jv_array_indexes(jv, jv);
|
|
|
113
113
|
__attribute__ ((__format__( __printf__, fmt_arg_num, args_num)))
|
|
114
114
|
#define JV_VPRINTF_LIKE(fmt_arg_num) \
|
|
115
115
|
__attribute__ ((__format__( __printf__, fmt_arg_num, 0)))
|
|
116
|
-
#else
|
|
117
|
-
#define JV_PRINTF_LIKE(fmt_arg_num, args_num)
|
|
118
|
-
#define JV_VPRINTF_LIKE(fmt_arg_num)
|
|
119
116
|
#endif
|
|
120
117
|
|
|
121
118
|
|
package/deps/jq/src/jv_aux.c
CHANGED
|
@@ -314,7 +314,7 @@ static jv jv_dels(jv t, jv keys) {
|
|
|
314
314
|
int neg_idx = 0;
|
|
315
315
|
int nonneg_idx = 0;
|
|
316
316
|
int len = jv_array_length(jv_copy(t));
|
|
317
|
-
|
|
317
|
+
jv_array_foreach(t, i, elem) {
|
|
318
318
|
int del = 0;
|
|
319
319
|
while (neg_idx < jv_array_length(jv_copy(neg_keys))) {
|
|
320
320
|
int delidx = len + (int)jv_number_get_value_and_consume(jv_array_get(jv_copy(neg_keys), neg_idx));
|
|
@@ -343,7 +343,9 @@ static jv jv_dels(jv t, jv keys) {
|
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
345
|
if (!del)
|
|
346
|
-
new_array = jv_array_append(new_array,
|
|
346
|
+
new_array = jv_array_append(new_array, elem);
|
|
347
|
+
else
|
|
348
|
+
jv_free(elem);
|
|
347
349
|
}
|
|
348
350
|
arr_out:
|
|
349
351
|
jv_free(neg_keys);
|
|
@@ -417,7 +419,6 @@ jv jv_setpath(jv root, jv path, jv value) {
|
|
|
417
419
|
// to null first.
|
|
418
420
|
root = jv_set(root, jv_copy(pathcurr), jv_null());
|
|
419
421
|
if (!jv_is_valid(root)) {
|
|
420
|
-
jv_free(subroot);
|
|
421
422
|
jv_free(pathcurr);
|
|
422
423
|
jv_free(pathrest);
|
|
423
424
|
jv_free(value);
|
package/deps/jq/src/jv_dtoa.c
CHANGED
|
@@ -299,7 +299,7 @@ extern "C" {
|
|
|
299
299
|
#endif
|
|
300
300
|
|
|
301
301
|
#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
|
|
302
|
-
|
|
302
|
+
Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
|
|
303
303
|
#endif
|
|
304
304
|
|
|
305
305
|
typedef union { double d; ULong L[2]; } U;
|
package/deps/jq/src/jv_parse.c
CHANGED
|
@@ -512,8 +512,6 @@ static pfunc check_literal(struct jv_parser* p) {
|
|
|
512
512
|
switch (p->tokenbuf[0]) {
|
|
513
513
|
case 't': pattern = "true"; plen = 4; v = jv_true(); break;
|
|
514
514
|
case 'f': pattern = "false"; plen = 5; v = jv_false(); break;
|
|
515
|
-
case '\'':
|
|
516
|
-
return "Invalid string literal; expected \", but got '";
|
|
517
515
|
case 'n':
|
|
518
516
|
// if it starts with 'n', it could be a literal "nan"
|
|
519
517
|
if (p->tokenbuf[1] == 'u') {
|
package/deps/jq/src/jv_print.c
CHANGED
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
// the last color is used for object keys.
|
|
30
30
|
static char color_bufs[8][16];
|
|
31
31
|
static const char *color_bufps[8];
|
|
32
|
-
static const char
|
|
32
|
+
static const char* def_colors[] =
|
|
33
33
|
{COL("0;90"), COL("0;39"), COL("0;39"), COL("0;39"),
|
|
34
34
|
COL("0;32"), COL("1;39"), COL("1;39"), COL("1;34")};
|
|
35
35
|
#define FIELD_COLOR (colors[7])
|
|
36
36
|
|
|
37
|
-
static const char
|
|
37
|
+
static const char **colors = def_colors;
|
|
38
38
|
|
|
39
39
|
int
|
|
40
40
|
jq_set_colors(const char *c)
|
|
@@ -206,7 +206,7 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
|
|
|
206
206
|
if (jv_get_kind(msg) == JV_KIND_STRING) {
|
|
207
207
|
put_str("<invalid:", F, S, flags & JV_PRINT_ISATTY);
|
|
208
208
|
jvp_dump_string(msg, flags | JV_PRINT_ASCII, F, S, flags & JV_PRINT_ISATTY);
|
|
209
|
-
|
|
209
|
+
put_str(">", F, S, flags & JV_PRINT_ISATTY);
|
|
210
210
|
} else {
|
|
211
211
|
put_str("<invalid>", F, S, flags & JV_PRINT_ISATTY);
|
|
212
212
|
}
|
|
@@ -259,18 +259,22 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
|
|
|
259
259
|
put_str("[]", F, S, flags & JV_PRINT_ISATTY);
|
|
260
260
|
break;
|
|
261
261
|
}
|
|
262
|
-
|
|
262
|
+
put_str("[", F, S, flags & JV_PRINT_ISATTY);
|
|
263
|
+
if (flags & JV_PRINT_PRETTY) {
|
|
264
|
+
put_char('\n', F, S, flags & JV_PRINT_ISATTY);
|
|
265
|
+
put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);
|
|
266
|
+
}
|
|
263
267
|
jv_array_foreach(x, i, elem) {
|
|
264
268
|
if (i!=0) {
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);
|
|
269
|
+
if (flags & JV_PRINT_PRETTY) {
|
|
270
|
+
put_str(",\n", F, S, flags & JV_PRINT_ISATTY);
|
|
271
|
+
put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);
|
|
272
|
+
} else {
|
|
273
|
+
put_str(",", F, S, flags & JV_PRINT_ISATTY);
|
|
274
|
+
}
|
|
272
275
|
}
|
|
273
276
|
jv_dump_term(C, elem, flags, indent + 1, F, S);
|
|
277
|
+
if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);
|
|
274
278
|
}
|
|
275
279
|
if (flags & JV_PRINT_PRETTY) {
|
|
276
280
|
put_char('\n', F, S, flags & JV_PRINT_ISATTY);
|
|
@@ -288,6 +292,10 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
|
|
|
288
292
|
break;
|
|
289
293
|
}
|
|
290
294
|
put_char('{', F, S, flags & JV_PRINT_ISATTY);
|
|
295
|
+
if (flags & JV_PRINT_PRETTY) {
|
|
296
|
+
put_char('\n', F, S, flags & JV_PRINT_ISATTY);
|
|
297
|
+
put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);
|
|
298
|
+
}
|
|
291
299
|
int first = 1;
|
|
292
300
|
int i = 0;
|
|
293
301
|
jv keyset = jv_null();
|
|
@@ -318,14 +326,14 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
|
|
|
318
326
|
}
|
|
319
327
|
|
|
320
328
|
if (!first) {
|
|
321
|
-
if (
|
|
322
|
-
|
|
329
|
+
if (flags & JV_PRINT_PRETTY){
|
|
330
|
+
put_str(",\n", F, S, flags & JV_PRINT_ISATTY);
|
|
331
|
+
put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);
|
|
332
|
+
} else {
|
|
333
|
+
put_str(",", F, S, flags & JV_PRINT_ISATTY);
|
|
334
|
+
}
|
|
323
335
|
}
|
|
324
336
|
if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
|
|
325
|
-
if (flags & JV_PRINT_PRETTY) {
|
|
326
|
-
put_char('\n', F, S, flags & JV_PRINT_ISATTY);
|
|
327
|
-
put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);
|
|
328
|
-
}
|
|
329
337
|
|
|
330
338
|
first = 0;
|
|
331
339
|
if (color) put_str(FIELD_COLOR, F, S, flags & JV_PRINT_ISATTY);
|
|
@@ -334,13 +342,11 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
|
|
|
334
342
|
if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
|
|
335
343
|
|
|
336
344
|
if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);
|
|
337
|
-
|
|
345
|
+
put_str((flags & JV_PRINT_PRETTY) ? ": " : ":", F, S, flags & JV_PRINT_ISATTY);
|
|
338
346
|
if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
|
|
339
|
-
if (flags & JV_PRINT_PRETTY) {
|
|
340
|
-
put_char(' ', F, S, flags & JV_PRINT_ISATTY);
|
|
341
|
-
}
|
|
342
347
|
|
|
343
348
|
jv_dump_term(C, value, flags, indent + 1, F, S);
|
|
349
|
+
if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);
|
|
344
350
|
}
|
|
345
351
|
if (flags & JV_PRINT_PRETTY) {
|
|
346
352
|
put_char('\n', F, S, flags & JV_PRINT_ISATTY);
|