This is an automated email from the ASF dual-hosted git repository.

szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new 43da4fc9f MINIFICPP-2511 Fix python processor tests
43da4fc9f is described below

commit 43da4fc9f164516f1734406f2375eeb57945eac8
Author: Gabor Gyimesi <[email protected]>
AuthorDate: Thu Jan 23 13:07:58 2025 +0100

    MINIFICPP-2511 Fix python processor tests
    
    - Properly load libpython in PythonManifestTests
    - Fix refcount handling for Python singleton objects
    
    Closes #1916
    
    Signed-off-by: Marton Szasz <[email protected]>
---
 extensions/python/PythonScriptEngine.h          | 3 ---
 extensions/python/tests/PythonManifestTests.cpp | 4 ++++
 extensions/python/types/BaseTypes.h             | 3 +++
 extensions/python/types/Types.h                 | 3 ---
 4 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/extensions/python/PythonScriptEngine.h 
b/extensions/python/PythonScriptEngine.h
index 4a266ea57..6a0d90e29 100644
--- a/extensions/python/PythonScriptEngine.h
+++ b/extensions/python/PythonScriptEngine.h
@@ -68,7 +68,6 @@ class PythonScriptEngine {
         }
         return result;
       }
-      Py_INCREF(Py_None);
       return OwnedReference(Py_None);
     } catch (const std::exception& e) {
       throw PythonScriptException(e.what());
@@ -98,13 +97,11 @@ class PythonScriptEngine {
 
     try {
       if (PyObject_HasAttrString(processor_instance_.get(), fn_name.c_str()) 
== 0) {
-        Py_INCREF(Py_None);
         return OwnedReference(Py_None);
       }
 
       auto callable_method = 
OwnedCallable(PyObject_GetAttrString(processor_instance_.get(), 
fn_name.c_str()));
       if (callable_method.get() == nullptr) {
-        Py_INCREF(Py_None);
         return OwnedReference(Py_None);
       }
 
diff --git a/extensions/python/tests/PythonManifestTests.cpp 
b/extensions/python/tests/PythonManifestTests.cpp
index c054d36f5..4bb98d6c7 100644
--- a/extensions/python/tests/PythonManifestTests.cpp
+++ b/extensions/python/tests/PythonManifestTests.cpp
@@ -157,7 +157,11 @@ class MyPyProc5(FlowFileTransform):
 )";
 
   
controller.configuration_->set(minifi::Configuration::nifi_python_processor_dir,
 python_dir.string());
+#ifdef __linux__
+  controller.configuration_->set(minifi::Configuration::nifi_extension_path, 
"*minifi-python-lib-loader*, *minifi-python-script*");
+#else
   controller.configuration_->set(minifi::Configuration::nifi_extension_path, 
"*minifi-python-script*");
+#endif
 
   
core::extension::ExtensionManager::get().initialize(controller.configuration_);
 
diff --git a/extensions/python/types/BaseTypes.h 
b/extensions/python/types/BaseTypes.h
index fe436cf46..04013a39d 100644
--- a/extensions/python/types/BaseTypes.h
+++ b/extensions/python/types/BaseTypes.h
@@ -50,6 +50,9 @@ struct ObjectReference {
 
   explicit ObjectReference(PyObject* object)
       : object_(object) {
+    if (object_ == Py_None || object_ == Py_True || object_ == Py_False || 
object_ == Py_Ellipsis || object_ == Py_NotImplemented) {
+      Py_INCREF(object_);
+    }
   }
 
   ~ObjectReference() {
diff --git a/extensions/python/types/Types.h b/extensions/python/types/Types.h
index 54769b44a..4118d03b0 100644
--- a/extensions/python/types/Types.h
+++ b/extensions/python/types/Types.h
@@ -60,10 +60,8 @@ template<>
 struct Converter<bool> {
   OwnedObject from(bool value) {
     if (value) {
-      Py_INCREF(Py_True);
       return OwnedObject(Py_True);
     }
-    Py_INCREF(Py_False);
     return OwnedObject(Py_False);
   }
 };
@@ -71,7 +69,6 @@ struct Converter<bool> {
 template<>
 struct Converter<std::nullptr_t> {
   OwnedObject from(std::nullptr_t) {
-    Py_INCREF(Py_None);
     return OwnedObject(Py_None);
   }
 };

Reply via email to