Skip to content
Myr

Bind data imports properly when already resolved

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Muh Muhten · committed by Nico Williams · parent e843a4f · Browse files · 2 files+31 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+31 added−15 removed

  • tests:+4 added−0 removed
  • other:+27 added−15 removed

2 files+31 added−15 removed

modified:src/linker.c+27 added-15 removed
273 unmodified lines
274 jv_free(jq_origin);275 jv_free(lib_origin);276 return 1;277 }278 uint64_t state_idx = 0;279 for (; state_idx < lib_state->ct; ++state_idx) {280 if (strcmp(lib_state->names[state_idx],jv_string_value(resolved)) == 0)281 break;282 }283 if (state_idx < lib_state->ct) { // Found284 jv_free(resolved);285 // Bind the library to the program286 bk = block_bind_library(lib_state->defs[state_idx], bk, OP_IS_CALL_PSEUDO, as_str);287 } else { // Not found. Add it to the table before binding.288 block dep_def_block = gen_noop();278279 if (is_data) {280 // Can't reuse data libs because the wrong name is bound281 block dep_def_block;282 nerrors += load_library(jq, resolved, is_data, raw, as_str, &dep_def_block, lib_state);290 // resolved has been freed283 if (nerrors == 0) {292 // Bind the library to the program284 // Bind as both $data::data and $data for backward compatibility vs common sense285 bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, as_str);294 if (is_data)295 bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, NULL);286 bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, NULL);287 }288 } else {289 uint64_t state_idx = 0;290 for (; state_idx < lib_state->ct; ++state_idx) {291 if (strcmp(lib_state->names[state_idx],jv_string_value(resolved)) == 0)292 break;293 }294295 if (state_idx < lib_state->ct) { // Found296 jv_free(resolved);297 // Bind the library to the program298 bk = block_bind_library(lib_state->defs[state_idx], bk, OP_IS_CALL_PSEUDO, as_str);299 } else { // Not found. Add it to the table before binding.300 block dep_def_block = gen_noop();301 nerrors += load_library(jq, resolved, is_data, raw, as_str, &dep_def_block, lib_state);302 // resolved has been freed303 if (nerrors == 0) {304 // Bind the library to the program305 bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, as_str);306 }307 }308 }309310 jv_free(as);311 }312 jv_free(lib_origin);313 jv_free(jq_origin);
117 unmodified lines
modified:tests/jq.test+4 added
1390 unmodified lines
1391include "c"; [a, c]1392null1393[0,"acmehbah"]13941395import "data" as $e; import "data" as $d; [$d[].this,$e[].that,$d::d[].this,$e::e[].that]|join(";")1396null1397"is a test;is too;is a test;is too"13981399%%FAIL1400module (.+1); 01401jq: error: Module metadata must be constant at <top-level>, line 1:1402
148 unmodified lines