summaryrefslogtreecommitdiff
path: root/jq.pyx
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2020-06-24 22:58:40 +0100
committerMichael Williamson <mike@zwobble.org>2020-06-24 22:58:40 +0100
commitd891ef939cdc12de808c8b37cd49da89078b65bd (patch)
tree8adb2fe7a4e0304fa6348e4014a9008610ea5359 /jq.pyx
parent5f7f1e8866d13f3ecb662cf814f0b599b82de09c (diff)
Add lock when compiling jq programs
Diffstat (limited to 'jq.pyx')
-rw-r--r--jq.pyx12
1 files changed, 8 insertions, 4 deletions
diff --git a/jq.pyx b/jq.pyx
index f319c18..bcfb457 100644
--- a/jq.pyx
+++ b/jq.pyx
@@ -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")