diff options
author | Muh Muhten <muh.muhten@gmail.com> | 2019-02-07 23:05:18 -0500 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2019-02-20 20:02:41 -0600 |
commit | 1ef90acb3814d85d59e5d1502d0ced6287b83408 (patch) | |
tree | c46b265aed470d3d08793598950d29a3bd278355 | |
parent | e843a4fdf9f6f446f5ddebf2c108cb7d4dda867b (diff) |
Bind data imports properly when already resolved
-rw-r--r-- | src/linker.c | 42 | ||||
-rw-r--r-- | tests/jq.test | 4 |
2 files changed, 31 insertions, 15 deletions
diff --git a/src/linker.c b/src/linker.c index aa1ff137..c222bc16 100644 --- a/src/linker.c +++ b/src/linker.c @@ -275,26 +275,38 @@ static int process_dependencies(jq_state *jq, jv jq_origin, jv lib_origin, block jv_free(lib_origin); return 1; } - uint64_t state_idx = 0; - for (; state_idx < lib_state->ct; ++state_idx) { - if (strcmp(lib_state->names[state_idx],jv_string_value(resolved)) == 0) - break; - } - if (state_idx < lib_state->ct) { // Found - jv_free(resolved); - // Bind the library to the program - bk = block_bind_library(lib_state->defs[state_idx], bk, OP_IS_CALL_PSEUDO, as_str); - } else { // Not found. Add it to the table before binding. - block dep_def_block = gen_noop(); + + if (is_data) { + // Can't reuse data libs because the wrong name is bound + block dep_def_block; nerrors += load_library(jq, resolved, is_data, raw, as_str, &dep_def_block, lib_state); - // resolved has been freed if (nerrors == 0) { - // Bind the library to the program + // Bind as both $data::data and $data for backward compatibility vs common sense bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, as_str); - if (is_data) - bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, NULL); + bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, NULL); + } + } else { + uint64_t state_idx = 0; + for (; state_idx < lib_state->ct; ++state_idx) { + if (strcmp(lib_state->names[state_idx],jv_string_value(resolved)) == 0) + break; + } + + if (state_idx < lib_state->ct) { // Found + jv_free(resolved); + // Bind the library to the program + bk = block_bind_library(lib_state->defs[state_idx], bk, OP_IS_CALL_PSEUDO, as_str); + } else { // Not found. Add it to the table before binding. + block dep_def_block = gen_noop(); + nerrors += load_library(jq, resolved, is_data, raw, as_str, &dep_def_block, lib_state); + // resolved has been freed + if (nerrors == 0) { + // Bind the library to the program + bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, as_str); + } } } + jv_free(as); } jv_free(lib_origin); diff --git a/tests/jq.test b/tests/jq.test index 1572043e..cbdc0bf0 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -1392,6 +1392,10 @@ include "c"; [a, c] null [0,"acmehbah"] +import "data" as $e; import "data" as $d; [$d[].this,$e[].that,$d::d[].this,$e::e[].that]|join(";") +null +"is a test;is too;is a test;is too" + %%FAIL module (.+1); 0 jq: error: Module metadata must be constant at <top-level>, line 1: |