diff options
| author | Michael Williamson <mike@zwobble.org> | 2020-06-24 22:58:40 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2020-06-24 22:58:40 +0100 |
| commit | d891ef939cdc12de808c8b37cd49da89078b65bd (patch) | |
| tree | 8adb2fe7a4e0304fa6348e4014a9008610ea5359 | |
| parent | 5f7f1e8866d13f3ecb662cf814f0b599b82de09c (diff) | |
Add lock when compiling jq programs
| -rw-r--r-- | jq.pyx | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -56,6 +56,9 @@ def compile(object program): return _Program(program_bytes) +_compilation_lock = threading.Lock() + + cdef jq_state* _compile(object program_bytes) except NULL: cdef jq_state *jq = jq_init() cdef _ErrorStore error_store @@ -66,12 +69,13 @@ cdef jq_state* _compile(object program_bytes) except NULL: error_store = _ErrorStore() - jq_set_error_cb(jq, _store_error, <void*>error_store) + with _compilation_lock: + jq_set_error_cb(jq, _store_error, <void*>error_store) - compiled = jq_compile(jq, program_bytes) + compiled = jq_compile(jq, program_bytes) - if error_store.has_errors(): - raise ValueError(error_store.error_string()) + if error_store.has_errors(): + raise ValueError(error_store.error_string()) if not compiled: raise ValueError("program was not valid") |
