Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1fbfc59

Browse files
committedDec 22, 2022
don't forget to call Py_FinalizeEx after Py_InitializeEx
1 parent 22ee1b8 commit 1fbfc59

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed
 

‎sakura_core/macro/CPythonMacroManager.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -1010,12 +1010,13 @@ bool CPythonMacroManager::ExecKeyMacro(CEditView *EditView, int flags) const
10101010
return false;
10111011
}
10121012

1013-
{
1013+
bool bSuccess = false;
1014+
do {
10141015
//const char* version = Py_GetVersion();
10151016
//const char* compiler = Py_GetCompiler();
10161017
PyObjectPtr module = PyImport_ImportModule("SakuraEditor");
10171018
if (!module) {
1018-
return false;
1019+
break;
10191020
}
10201021

10211022
for (auto& desc : g_commandDescs) {
@@ -1038,36 +1039,36 @@ bool CPythonMacroManager::ExecKeyMacro(CEditView *EditView, int flags) const
10381039
PyObjectPtr pCode = Py_CompileString(m_strMacro.c_str(), m_strPath.c_str(), Py_file_input);
10391040
if (!pCode) {
10401041
ShowError(EditView, m_wstrPath.c_str());
1041-
return false;
1042+
break;
10421043
}
10431044

10441045
PyObjectPtr pMain = PyImport_AddModule("__main__");
10451046
if (!pMain) {
1046-
return false;
1047+
break;
10471048
}
10481049

10491050
PyObject* pGlobals = PyModule_GetDict(pMain); // borrowed reference
10501051
if (!pGlobals) {
1051-
return false;
1052+
break;
10521053
}
10531054

10541055
PyObjectPtr pLocals = PyDict_New();
10551056
if (!pLocals) {
1056-
return false;
1057+
break;
10571058
}
10581059

10591060
PyObjectPtr pObj = PyEval_EvalCode(pCode, pGlobals, pLocals);
10601061
if (!pObj) {
10611062
ShowError(EditView, m_wstrPath.c_str());
1062-
return false;
1063+
break;
10631064
}
1064-
}
1065+
bSuccess = true;
1066+
} while (false);
10651067

10661068
if (Py_FinalizeEx() < 0) {
10671069
return false;
10681070
}
1069-
1070-
return true;
1071+
return bSuccess;
10711072
}
10721073

10731074
inline

0 commit comments

Comments
 (0)
Please sign in to comment.