From a47897ca820bbadbb978230fc7de9d3467829822 Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Fri, 22 Dec 2023 21:23:52 +0100 Subject: [PATCH 1/2] refactor the compiler progress callback --- python/src/addons/CompletionDictionaryCompiler.pyx | 7 +------ python/src/addons/FloatVectorDictionaryCompiler.pyx | 2 +- python/src/addons/IntDictionaryCompiler.pyx | 2 +- python/src/addons/IntDictionaryCompilerSmallData.pyx | 2 +- python/src/addons/JsonDictionaryCompiler.pyx | 2 +- python/src/addons/JsonDictionaryCompilerSmallData.pyx | 2 +- python/src/addons/KeyOnlyDictionaryCompiler.pyx | 2 +- python/src/addons/StringDictionaryCompiler.pyx | 2 +- python/src/addons/autwrap_workarounds.pyx | 5 +++++ python/src/pxds/match.pxd | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/python/src/addons/CompletionDictionaryCompiler.pyx b/python/src/addons/CompletionDictionaryCompiler.pyx index d225ebec3..350d20a56 100644 --- a/python/src/addons/CompletionDictionaryCompiler.pyx +++ b/python/src/addons/CompletionDictionaryCompiler.pyx @@ -20,9 +20,4 @@ cdef void* callback = args[0] with nogil: - self.inst.get().Compile(callback_wrapper, callback) - - -# definition for all compilers -cdef void callback_wrapper(size_t a, size_t b, void* py_callback) with gil: - (py_callback)(a, b) + self.inst.get().Compile(progress_compiler_callback, callback) diff --git a/python/src/addons/FloatVectorDictionaryCompiler.pyx b/python/src/addons/FloatVectorDictionaryCompiler.pyx index 77c6a2969..dce891d8a 100644 --- a/python/src/addons/FloatVectorDictionaryCompiler.pyx +++ b/python/src/addons/FloatVectorDictionaryCompiler.pyx @@ -20,5 +20,5 @@ cdef void* callback = args[0] with nogil: - self.inst.get().Compile(callback_wrapper, callback) + self.inst.get().Compile(progress_compiler_callback, callback) diff --git a/python/src/addons/IntDictionaryCompiler.pyx b/python/src/addons/IntDictionaryCompiler.pyx index 77c6a2969..dce891d8a 100644 --- a/python/src/addons/IntDictionaryCompiler.pyx +++ b/python/src/addons/IntDictionaryCompiler.pyx @@ -20,5 +20,5 @@ cdef void* callback = args[0] with nogil: - self.inst.get().Compile(callback_wrapper, callback) + self.inst.get().Compile(progress_compiler_callback, callback) diff --git a/python/src/addons/IntDictionaryCompilerSmallData.pyx b/python/src/addons/IntDictionaryCompilerSmallData.pyx index 77c6a2969..dce891d8a 100644 --- a/python/src/addons/IntDictionaryCompilerSmallData.pyx +++ b/python/src/addons/IntDictionaryCompilerSmallData.pyx @@ -20,5 +20,5 @@ cdef void* callback = args[0] with nogil: - self.inst.get().Compile(callback_wrapper, callback) + self.inst.get().Compile(progress_compiler_callback, callback) diff --git a/python/src/addons/JsonDictionaryCompiler.pyx b/python/src/addons/JsonDictionaryCompiler.pyx index bc8607fd6..0faa6fa7d 100644 --- a/python/src/addons/JsonDictionaryCompiler.pyx +++ b/python/src/addons/JsonDictionaryCompiler.pyx @@ -20,5 +20,5 @@ cdef void* callback = args[0] with nogil: - self.inst.get().Compile(callback_wrapper, callback) + self.inst.get().Compile(progress_compiler_callback, callback) diff --git a/python/src/addons/JsonDictionaryCompilerSmallData.pyx b/python/src/addons/JsonDictionaryCompilerSmallData.pyx index 96b5d32df..2b89ba5f2 100644 --- a/python/src/addons/JsonDictionaryCompilerSmallData.pyx +++ b/python/src/addons/JsonDictionaryCompilerSmallData.pyx @@ -35,5 +35,5 @@ cdef void* callback = args[0] with nogil: - self.inst.get().Compile(callback_wrapper, callback) + self.inst.get().Compile(progress_compiler_callback, callback) diff --git a/python/src/addons/KeyOnlyDictionaryCompiler.pyx b/python/src/addons/KeyOnlyDictionaryCompiler.pyx index 77c6a2969..dce891d8a 100644 --- a/python/src/addons/KeyOnlyDictionaryCompiler.pyx +++ b/python/src/addons/KeyOnlyDictionaryCompiler.pyx @@ -20,5 +20,5 @@ cdef void* callback = args[0] with nogil: - self.inst.get().Compile(callback_wrapper, callback) + self.inst.get().Compile(progress_compiler_callback, callback) diff --git a/python/src/addons/StringDictionaryCompiler.pyx b/python/src/addons/StringDictionaryCompiler.pyx index 77c6a2969..dce891d8a 100644 --- a/python/src/addons/StringDictionaryCompiler.pyx +++ b/python/src/addons/StringDictionaryCompiler.pyx @@ -20,5 +20,5 @@ cdef void* callback = args[0] with nogil: - self.inst.get().Compile(callback_wrapper, callback) + self.inst.get().Compile(progress_compiler_callback, callback) diff --git a/python/src/addons/autwrap_workarounds.pyx b/python/src/addons/autwrap_workarounds.pyx index 5fddf9896..7d084c3a4 100644 --- a/python/src/addons/autwrap_workarounds.pyx +++ b/python/src/addons/autwrap_workarounds.pyx @@ -33,3 +33,8 @@ def get_interpreter_executable(): executable = executable.encode('utf-8') return executable + + +# definition for all compilers +cdef void progress_compiler_callback(size_t a, size_t b, void* py_callback) noexcept with gil: + (py_callback)(a, b) \ No newline at end of file diff --git a/python/src/pxds/match.pxd b/python/src/pxds/match.pxd index 22f58b513..038eb5d24 100644 --- a/python/src/pxds/match.pxd +++ b/python/src/pxds/match.pxd @@ -17,7 +17,7 @@ cdef extern from "keyvi/dictionary/match.h" namespace "keyvi::dictionary": void SetScore(float score) libcpp_utf8_output_string GetMatchedString() void SetMatchedString (libcpp_utf8_string matched_string) - PyObject* GetAttributePy(libcpp_utf8_string) nogil except + # wrap-ignore + PyObject* GetAttributePy(libcpp_utf8_string) except + nogil # wrap-ignore libcpp_utf8_output_string GetValueAsString() except + libcpp_string GetRawValueAsString() except + libcpp_string GetMsgPackedValueAsString() except + # wrap-ignore From 08cdcf29333d7a6bb36b143ddcdd51184f3daa28 Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Wed, 27 Dec 2023 19:46:50 +0100 Subject: [PATCH 2/2] Update autwrap_workarounds.pyx --- python/src/addons/autwrap_workarounds.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/src/addons/autwrap_workarounds.pyx b/python/src/addons/autwrap_workarounds.pyx index 7d084c3a4..117c72e07 100644 --- a/python/src/addons/autwrap_workarounds.pyx +++ b/python/src/addons/autwrap_workarounds.pyx @@ -37,4 +37,4 @@ def get_interpreter_executable(): # definition for all compilers cdef void progress_compiler_callback(size_t a, size_t b, void* py_callback) noexcept with gil: - (py_callback)(a, b) \ No newline at end of file + (py_callback)(a, b)