From d891ef939cdc12de808c8b37cd49da89078b65bd Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 24 Jun 2020 22:58:40 +0100 Subject: Add lock when compiling jq programs --- jq.pyx | 12 ++++++++---- 1 file 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, error_store) + with _compilation_lock: + jq_set_error_cb(jq, _store_error, 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") -- cgit v1.2.3