Skip to content

Commit c6140bc

Browse files
committed
style: fix some clang-tidy
1 parent 7499826 commit c6140bc

File tree

1 file changed

+7
-67
lines changed

1 file changed

+7
-67
lines changed

src/module.cpp

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,8 +1934,7 @@ namespace py3lm {
19341934
const bool funcIsMethod = !className.empty();
19351935

19361936
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())) {
19391938
func = PyObject_GetAttrString(classType, methodName.c_str());
19401939
Py_DECREF(classType);
19411940
}
@@ -3029,19 +3028,17 @@ namespace py3lm {
30293028
void GenerateEnum(MethodHandle method, PyObject* moduleDict);
30303029

30313030
void GenerateEnum(PropertyHandle paramType, PyObject* moduleDict) {
3032-
const auto prototype = paramType.GetPrototype();
3033-
if (prototype) {
3031+
if (const auto prototype = paramType.GetPrototype()) {
30343032
GenerateEnum(prototype, moduleDict);
30353033
}
3036-
const auto enumerator = paramType.GetEnum();
3037-
if (enumerator) {
3034+
if (const auto enumerator = paramType.GetEnum()) {
30383035
g_py3lm.CreateEnumObject(enumerator, moduleDict);
30393036
}
30403037
}
30413038

30423039
void GenerateEnum(MethodHandle method, PyObject* moduleDict) {
30433040
GenerateEnum(method.GetReturnType(), moduleDict);
3044-
for (auto paramType : method.GetParamTypes()) {
3041+
for (const auto& paramType : method.GetParamTypes()) {
30453042
GenerateEnum(paramType, moduleDict);
30463043
}
30473044
}
@@ -3050,7 +3047,7 @@ namespace py3lm {
30503047
PyObject* sep = PyUnicode_FromString(" ");
30513048
PyObject* end = PyUnicode_FromString("\n");
30523049

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) };
30543051
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist.data(), &sep, &end)) {
30553052
return nullptr;
30563053
}
@@ -3065,71 +3062,14 @@ namespace py3lm {
30653062
Py_DECREF(message);
30663063
Py_RETURN_NONE;
30673064
}
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-
}*/
31253065
}
31263066

31273067
Python3LanguageModule::Python3LanguageModule() = default;
31283068

31293069
Python3LanguageModule::~Python3LanguageModule() = default;
31303070

31313071
InitResult Python3LanguageModule::Initialize(std::weak_ptr<IPlugifyProvider> provider, ModuleHandle module) {
3132-
if (!(_provider = provider.lock())) {
3072+
if (!((_provider = provider.lock()))) {
31333073
return ErrorData{ "Provider not exposed" };
31343074
}
31353075

@@ -3853,7 +3793,7 @@ namespace py3lm {
38533793
}
38543794

38553795
auto defPtr = std::make_unique<PyMethodDef>();
3856-
PyMethodDef& def = *(defPtr.get());
3796+
PyMethodDef& def = *(defPtr);
38573797
def.ml_name = "PlugifyExternal";
38583798
def.ml_meth = methodAddr.RCast<PyCFunction>();
38593799
def.ml_flags = noArgs ? METH_NOARGS : METH_VARARGS;

0 commit comments

Comments
 (0)