Skip to content

Commit 43da4fc

Browse files
lordgamezszaszm
authored andcommitted
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]>
1 parent 07b9641 commit 43da4fc

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

extensions/python/PythonScriptEngine.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class PythonScriptEngine {
6868
}
6969
return result;
7070
}
71-
Py_INCREF(Py_None);
7271
return OwnedReference(Py_None);
7372
} catch (const std::exception& e) {
7473
throw PythonScriptException(e.what());
@@ -98,13 +97,11 @@ class PythonScriptEngine {
9897

9998
try {
10099
if (PyObject_HasAttrString(processor_instance_.get(), fn_name.c_str()) == 0) {
101-
Py_INCREF(Py_None);
102100
return OwnedReference(Py_None);
103101
}
104102

105103
auto callable_method = OwnedCallable(PyObject_GetAttrString(processor_instance_.get(), fn_name.c_str()));
106104
if (callable_method.get() == nullptr) {
107-
Py_INCREF(Py_None);
108105
return OwnedReference(Py_None);
109106
}
110107

extensions/python/tests/PythonManifestTests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ class MyPyProc5(FlowFileTransform):
157157
)";
158158

159159
controller.configuration_->set(minifi::Configuration::nifi_python_processor_dir, python_dir.string());
160+
#ifdef __linux__
161+
controller.configuration_->set(minifi::Configuration::nifi_extension_path, "*minifi-python-lib-loader*, *minifi-python-script*");
162+
#else
160163
controller.configuration_->set(minifi::Configuration::nifi_extension_path, "*minifi-python-script*");
164+
#endif
161165

162166
core::extension::ExtensionManager::get().initialize(controller.configuration_);
163167

extensions/python/types/BaseTypes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ struct ObjectReference {
5050

5151
explicit ObjectReference(PyObject* object)
5252
: object_(object) {
53+
if (object_ == Py_None || object_ == Py_True || object_ == Py_False || object_ == Py_Ellipsis || object_ == Py_NotImplemented) {
54+
Py_INCREF(object_);
55+
}
5356
}
5457

5558
~ObjectReference() {

extensions/python/types/Types.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,15 @@ template<>
6060
struct Converter<bool> {
6161
OwnedObject from(bool value) {
6262
if (value) {
63-
Py_INCREF(Py_True);
6463
return OwnedObject(Py_True);
6564
}
66-
Py_INCREF(Py_False);
6765
return OwnedObject(Py_False);
6866
}
6967
};
7068

7169
template<>
7270
struct Converter<std::nullptr_t> {
7371
OwnedObject from(std::nullptr_t) {
74-
Py_INCREF(Py_None);
7572
return OwnedObject(Py_None);
7673
}
7774
};

0 commit comments

Comments
 (0)