mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Fix issue with Python errors not being retrieved correctly in C++.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <boost/python.hpp>
|
||||
|
||||
#include <log.h>
|
||||
#include <utility.h>
|
||||
|
||||
#include "error.h"
|
||||
@@ -17,20 +18,17 @@
|
||||
template <class WrapperType, class ReturnType, class... Args>
|
||||
ReturnType basicWrapperFunctionImplementation(const WrapperType *wrapper, const char *methodName, Args... args)
|
||||
{
|
||||
GILock lock;
|
||||
boost::python::override implementation = wrapper->get_override(methodName);
|
||||
if (!implementation) {
|
||||
throw pyexcept::MissingImplementation(wrapper->className, methodName);
|
||||
}
|
||||
try {
|
||||
GILock lock;
|
||||
boost::python::override implementation = wrapper->get_override(methodName);
|
||||
if (!implementation) {
|
||||
throw pyexcept::MissingImplementation(wrapper->className, methodName);
|
||||
}
|
||||
return implementation(args...).as<ReturnType>();
|
||||
}
|
||||
catch (const boost::python::error_already_set&) {
|
||||
throw pyexcept::PythonError();
|
||||
}
|
||||
catch (pyexcept::MissingImplementation const& missingImplementation) {
|
||||
throw missingImplementation;
|
||||
}
|
||||
catch (...) {
|
||||
throw pyexcept::UnknownException();
|
||||
}
|
||||
@@ -42,12 +40,12 @@ ReturnType basicWrapperFunctionImplementation(const WrapperType *wrapper, const
|
||||
template <class WrapperType, class ReturnType, class... Args>
|
||||
ReturnType basicWrapperFunctionImplementation(const WrapperType* wrapper, boost::python::object &ref, const char* methodName, Args... args)
|
||||
{
|
||||
GILock lock;
|
||||
boost::python::override implementation = wrapper->get_override(methodName);
|
||||
if (!implementation) {
|
||||
throw pyexcept::MissingImplementation(wrapper->className, methodName);
|
||||
}
|
||||
try {
|
||||
GILock lock;
|
||||
boost::python::override implementation = wrapper->get_override(methodName);
|
||||
if (!implementation) {
|
||||
throw pyexcept::MissingImplementation(wrapper->className, methodName);
|
||||
}
|
||||
ref = implementation(args...);
|
||||
return boost::python::extract<ReturnType>(ref)();
|
||||
}
|
||||
@@ -65,12 +63,15 @@ ReturnType basicWrapperFunctionImplementation(const WrapperType* wrapper, boost:
|
||||
template <class WrapperType, class ReturnType, class Fn, class... Args>
|
||||
ReturnType basicWrapperFunctionImplementationWithDefault(WrapperType* wrapper, Fn fn, const char* methodName, Args... args)
|
||||
{
|
||||
GILock lock;
|
||||
boost::python::override implementation = wrapper->get_override(methodName);
|
||||
|
||||
if (!implementation) {
|
||||
return std::invoke(fn, wrapper, args...);
|
||||
}
|
||||
|
||||
try {
|
||||
GILock lock;
|
||||
boost::python::override implementation = wrapper->get_override(methodName);
|
||||
if (implementation) {
|
||||
return implementation(args...).as<ReturnType>();
|
||||
}
|
||||
return implementation(args...).as<ReturnType>();
|
||||
}
|
||||
catch (const boost::python::error_already_set&) {
|
||||
throw pyexcept::PythonError();
|
||||
@@ -78,19 +79,20 @@ ReturnType basicWrapperFunctionImplementationWithDefault(WrapperType* wrapper, F
|
||||
catch (...) {
|
||||
throw pyexcept::UnknownException();
|
||||
}
|
||||
|
||||
return std::invoke(fn, wrapper, args...);
|
||||
}
|
||||
|
||||
template <class WrapperType, class ReturnType, class Fn, class... Args>
|
||||
ReturnType basicWrapperFunctionImplementationWithDefault(const WrapperType* wrapper, Fn fn, const char* methodName, Args... args)
|
||||
{
|
||||
GILock lock;
|
||||
boost::python::override implementation = wrapper->get_override(methodName);
|
||||
|
||||
if (!implementation) {
|
||||
return std::invoke(fn, wrapper, args...);
|
||||
}
|
||||
|
||||
try {
|
||||
GILock lock;
|
||||
boost::python::override implementation = wrapper->get_override(methodName);
|
||||
if (implementation) {
|
||||
return implementation(args...).as<ReturnType>();
|
||||
}
|
||||
return implementation(args...).as<ReturnType>();
|
||||
}
|
||||
catch (const boost::python::error_already_set&) {
|
||||
throw pyexcept::PythonError();
|
||||
@@ -98,8 +100,6 @@ ReturnType basicWrapperFunctionImplementationWithDefault(const WrapperType* wrap
|
||||
catch (...) {
|
||||
throw pyexcept::UnknownException();
|
||||
}
|
||||
|
||||
return std::invoke(fn, wrapper, args...);
|
||||
}
|
||||
|
||||
#endif // PYTHONWRAPPERUTILITIES_H
|
||||
|
||||
Reference in New Issue
Block a user