@@ -1934,8 +1934,7 @@ namespace py3lm {
1934
1934
const bool funcIsMethod = !className.empty ();
1935
1935
1936
1936
if (funcIsMethod) {
1937
- PyObject* const classType = PyDict_GetItemString (pluginDict, className.c_str ());
1938
- if (classType) {
1937
+ if (PyObject* const classType = PyDict_GetItemString (pluginDict, className.c_str ())) {
1939
1938
func = PyObject_GetAttrString (classType, methodName.c_str ());
1940
1939
Py_DECREF (classType);
1941
1940
}
@@ -3029,19 +3028,17 @@ namespace py3lm {
3029
3028
void GenerateEnum (MethodHandle method, PyObject* moduleDict);
3030
3029
3031
3030
void GenerateEnum (PropertyHandle paramType, PyObject* moduleDict) {
3032
- const auto prototype = paramType.GetPrototype ();
3033
- if (prototype) {
3031
+ if (const auto prototype = paramType.GetPrototype ()) {
3034
3032
GenerateEnum (prototype, moduleDict);
3035
3033
}
3036
- const auto enumerator = paramType.GetEnum ();
3037
- if (enumerator) {
3034
+ if (const auto enumerator = paramType.GetEnum ()) {
3038
3035
g_py3lm.CreateEnumObject (enumerator, moduleDict);
3039
3036
}
3040
3037
}
3041
3038
3042
3039
void GenerateEnum (MethodHandle method, PyObject* moduleDict) {
3043
3040
GenerateEnum (method.GetReturnType (), moduleDict);
3044
- for (auto paramType : method.GetParamTypes ()) {
3041
+ for (const auto & paramType : method.GetParamTypes ()) {
3045
3042
GenerateEnum (paramType, moduleDict);
3046
3043
}
3047
3044
}
@@ -3050,7 +3047,7 @@ namespace py3lm {
3050
3047
PyObject* sep = PyUnicode_FromString (" " );
3051
3048
PyObject* end = PyUnicode_FromString (" \n " );
3052
3049
3053
- static std::array kwlist = { const_cast <char *>(" sep" ), const_cast <char *>(" end" ), ( char *) nullptr };
3050
+ static std::array kwlist = { const_cast <char *>(" sep" ), const_cast <char *>(" end" ), static_cast < char *>( nullptr ) };
3054
3051
if (!PyArg_ParseTupleAndKeywords (args, kwargs, " |OO" , kwlist.data (), &sep, &end)) {
3055
3052
return nullptr ;
3056
3053
}
@@ -3065,71 +3062,14 @@ namespace py3lm {
3065
3062
Py_DECREF (message);
3066
3063
Py_RETURN_NONE;
3067
3064
}
3068
-
3069
- /* std::string ExtractModuleName(const std::string& errorMessage) {
3070
- std::regex pattern(R"(cannot import name '([^']+)' from '([^']+)')");
3071
- std::smatch match;
3072
-
3073
- if (std::regex_search(errorMessage, match, pattern)) {
3074
- return match[2].str() + "." + match[1].str();;
3075
- } else {
3076
- return "";
3077
- }
3078
- }
3079
-
3080
- PyObject* TryImportModule(const std::string& moduleName) {
3081
- std::string lastErrorMsg;
3082
-
3083
- while (true) {
3084
- PyObject* const pluginModule = PyImport_ImportModule(moduleName.c_str());
3085
- if (pluginModule) {
3086
- return pluginModule;
3087
- }
3088
-
3089
- if (PyErr_Occurred()) {
3090
- PyObject *ptype, *pvalue, *ptraceback;
3091
- PyErr_Fetch(&ptype, &pvalue, &ptraceback);
3092
- PyErr_NormalizeException(&ptype, &pvalue, &ptraceback);
3093
-
3094
- if (ptype && PyErr_GivenExceptionMatches(ptype, PyExc_ImportError)) {
3095
- Py_ssize_t size{};
3096
- const char* const buffer = PyUnicode_AsUTF8AndSize(PyObject_Str(pvalue), &size);
3097
- std::string_view errorMsg{buffer, static_cast<size_t>(size)};
3098
-
3099
- if (lastErrorMsg == errorMsg) {
3100
- break; // Stop retrying if the same error occurs twice
3101
- }
3102
-
3103
- lastErrorMsg = errorMsg;
3104
-
3105
- std::string missingModuleName = ExtractModuleName(lastErrorMsg);
3106
-
3107
- if (g_py3lm.ResolveMissingModule(missingModuleName)) {
3108
- Py_DECREF(ptype);
3109
- Py_DECREF(pvalue);
3110
- Py_XDECREF(ptraceback);
3111
- continue;
3112
- }
3113
- }
3114
-
3115
- Py_XDECREF(ptype);
3116
- Py_XDECREF(pvalue);
3117
- Py_XDECREF(ptraceback);
3118
- }
3119
-
3120
- break;
3121
- }
3122
-
3123
- return nullptr; // Import failed
3124
- }*/
3125
3065
}
3126
3066
3127
3067
Python3LanguageModule::Python3LanguageModule () = default ;
3128
3068
3129
3069
Python3LanguageModule::~Python3LanguageModule () = default ;
3130
3070
3131
3071
InitResult Python3LanguageModule::Initialize (std::weak_ptr<IPlugifyProvider> provider, ModuleHandle module ) {
3132
- if (!(_provider = provider.lock ())) {
3072
+ if (!(( _provider = provider.lock () ))) {
3133
3073
return ErrorData{ " Provider not exposed" };
3134
3074
}
3135
3075
@@ -3853,7 +3793,7 @@ namespace py3lm {
3853
3793
}
3854
3794
3855
3795
auto defPtr = std::make_unique<PyMethodDef>();
3856
- PyMethodDef& def = *(defPtr. get () );
3796
+ PyMethodDef& def = *(defPtr);
3857
3797
def.ml_name = " PlugifyExternal" ;
3858
3798
def.ml_meth = methodAddr.RCast <PyCFunction>();
3859
3799
def.ml_flags = noArgs ? METH_NOARGS : METH_VARARGS;
0 commit comments