diff --git a/src/EterPythonLib/PythonGraphicImageModule.cpp b/src/EterPythonLib/PythonGraphicImageModule.cpp index 9cff611..181adb5 100644 --- a/src/EterPythonLib/PythonGraphicImageModule.cpp +++ b/src/EterPythonLib/PythonGraphicImageModule.cpp @@ -82,12 +82,12 @@ PyObject* grpImageGenerateExpanded(PyObject* poSelf, PyObject* poArgs) PyObject* grpImageGenerateFromHandle(PyObject * poSelf, PyObject* poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CGraphicImage* iHandle; + if (!PyTuple_GetPointer(poArgs, 0, &iHandle)) return Py_BadArgument(); CGraphicImageInstance * pImageInstance = CGraphicImageInstance::New(); - pImageInstance->SetImagePointer((CGraphicImage *)iHandle); + pImageInstance->SetImagePointer(iHandle); return Py_BuildValue("K", pImageInstance); } diff --git a/src/EterPythonLib/PythonGraphicModule.cpp b/src/EterPythonLib/PythonGraphicModule.cpp index b54ffd9..b1bc61a 100644 --- a/src/EterPythonLib/PythonGraphicModule.cpp +++ b/src/EterPythonLib/PythonGraphicModule.cpp @@ -48,11 +48,10 @@ PyObject* grpCreateBigTextBar(PyObject* poSelf, PyObject* poArgs) PyObject* grpDestroyTextBar(PyObject* poSelf, PyObject* poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CTextBar* pTextBar; + if (!PyTuple_GetPointer(poArgs, 0, &pTextBar)) return Py_BuildException(); - CTextBar * pTextBar = (CTextBar *)iHandle; delete pTextBar; return Py_BuildNone(); @@ -60,8 +59,8 @@ PyObject* grpDestroyTextBar(PyObject* poSelf, PyObject* poArgs) PyObject* grpRenderTextBar(PyObject* poSelf, PyObject* poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CTextBar* pTextBar; + if (!PyTuple_GetPointer(poArgs, 0, &pTextBar)) return Py_BuildException(); int ix; if (!PyTuple_GetInteger(poArgs, 1, &ix)) @@ -70,7 +69,6 @@ PyObject* grpRenderTextBar(PyObject* poSelf, PyObject* poArgs) if (!PyTuple_GetInteger(poArgs, 2, &iy)) return Py_BuildException(); - CTextBar * pTextBar = (CTextBar *)iHandle; if (pTextBar) pTextBar->Render(ix, iy); @@ -79,8 +77,8 @@ PyObject* grpRenderTextBar(PyObject* poSelf, PyObject* poArgs) PyObject* grpTextBarSetTextColor(PyObject* poSelf, PyObject* poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CTextBar* pTextBar; + if (!PyTuple_GetPointer(poArgs, 0, &pTextBar)) return Py_BuildException(); int r; if (!PyTuple_GetInteger(poArgs, 1, &r)) @@ -92,7 +90,6 @@ PyObject* grpTextBarSetTextColor(PyObject* poSelf, PyObject* poArgs) if (!PyTuple_GetInteger(poArgs, 3, &b)) return Py_BuildException(); - CTextBar * pTextBar = (CTextBar *)iHandle; if (pTextBar) pTextBar->SetTextColor(r, g, b); @@ -101,15 +98,14 @@ PyObject* grpTextBarSetTextColor(PyObject* poSelf, PyObject* poArgs) PyObject* grpTextBarGetTextExtent(PyObject* poSelf, PyObject* poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CTextBar* pTextBar; + if (!PyTuple_GetPointer(poArgs, 0, &pTextBar)) return Py_BuildException(); char * szText; if (!PyTuple_GetString(poArgs, 1, &szText)) return Py_BuildException(); SIZE size = {0, 0}; - CTextBar * pTextBar = (CTextBar *)iHandle; if (pTextBar) pTextBar->GetTextExtent(szText, &size); @@ -118,8 +114,8 @@ PyObject* grpTextBarGetTextExtent(PyObject* poSelf, PyObject* poArgs) PyObject* grpTextBarTextOut(PyObject* poSelf, PyObject* poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CTextBar* pTextBar; + if (!PyTuple_GetPointer(poArgs, 0, &pTextBar)) return Py_BuildException(); int ix; if (!PyTuple_GetInteger(poArgs, 1, &ix)) @@ -131,7 +127,6 @@ PyObject* grpTextBarTextOut(PyObject* poSelf, PyObject* poArgs) if (!PyTuple_GetString(poArgs, 3, &szText)) return Py_BuildException(); - CTextBar * pTextBar = (CTextBar *)iHandle; if (pTextBar) pTextBar->TextOut(ix, iy, szText); @@ -140,11 +135,10 @@ PyObject* grpTextBarTextOut(PyObject* poSelf, PyObject* poArgs) PyObject* grpClearTextBar(PyObject* poSelf, PyObject* poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CTextBar* pTextBar; + if (!PyTuple_GetPointer(poArgs, 0, &pTextBar)) return Py_BuildException(); - CTextBar * pTextBar = (CTextBar *)iHandle; if (pTextBar) pTextBar->ClearBar(); @@ -153,8 +147,8 @@ PyObject* grpClearTextBar(PyObject* poSelf, PyObject* poArgs) PyObject* grpSetTextBarClipRect(PyObject* poSelf, PyObject* poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CTextBar* pTextBar; + if (!PyTuple_GetPointer(poArgs, 0, &pTextBar)) return Py_BuildException(); int isx; if (!PyTuple_GetInteger(poArgs, 1, &isx)) @@ -169,7 +163,6 @@ PyObject* grpSetTextBarClipRect(PyObject* poSelf, PyObject* poArgs) if (!PyTuple_GetInteger(poArgs, 4, &iey)) return Py_BuildException(); - CTextBar * pTextBar = (CTextBar *)iHandle; if (pTextBar) { RECT rect; diff --git a/src/EterPythonLib/PythonWindowManagerModule.cpp b/src/EterPythonLib/PythonWindowManagerModule.cpp index 2df4eb2..d2cc76b 100644 --- a/src/EterPythonLib/PythonWindowManagerModule.cpp +++ b/src/EterPythonLib/PythonWindowManagerModule.cpp @@ -5,14 +5,10 @@ bool PyTuple_GetWindow(PyObject* poArgs, int pos, UI::CWindow ** ppRetWindow) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, pos, &iHandle)) - return false; - if (!iHandle) + if (!PyTuple_GetPointer(poArgs, pos, ppRetWindow)) return false; - *ppRetWindow = (UI::CWindow*)iHandle; - return true; + return *ppRetWindow != nullptr; } PyObject * wndMgrGetAspect(PyObject * poSelf, PyObject * poArgs) diff --git a/src/ScriptLib/PythonUtils.h b/src/ScriptLib/PythonUtils.h index bfdf682..cbd32ca 100644 --- a/src/ScriptLib/PythonUtils.h +++ b/src/ScriptLib/PythonUtils.h @@ -17,6 +17,11 @@ bool PyTuple_GetDouble(PyObject* poArgs, int pos, double* ret); bool PyTuple_GetObject(PyObject* poArgs, int pos, PyObject** ret); bool PyTuple_GetBoolean(PyObject* poArgs, int pos, bool* ret); +template +bool PyTuple_GetPointer(PyObject* poArgs, int pos, T** ret) { + return PyTuple_GetUnsignedLongLong(poArgs, pos, (unsigned long long*)*ret); +} + bool PyCallClassMemberFunc(PyObject* poClass, const char* c_szFunc, PyObject* poArgs); bool PyCallClassMemberFunc(PyObject* poClass, const char* c_szFunc, PyObject* poArgs, bool* pisRet); bool PyCallClassMemberFunc(PyObject* poClass, const char* c_szFunc, PyObject* poArgs, long * plRetValue); diff --git a/src/UserInterface/PythonApplicationModule.cpp b/src/UserInterface/PythonApplicationModule.cpp index 7cb2e98..b62dc20 100644 --- a/src/UserInterface/PythonApplicationModule.cpp +++ b/src/UserInterface/PythonApplicationModule.cpp @@ -1063,11 +1063,10 @@ PyObject * appOpenTextFile(PyObject * poSelf, PyObject * poArgs) PyObject * appCloseTextFile(PyObject * poSelf, PyObject * poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CTextLineLoader* pTextFileLoader; + if (!PyTuple_GetPointer(poArgs, 0, &pTextFileLoader)) return Py_BuildException(); - CTextLineLoader * pTextFileLoader = (CTextLineLoader *)iHandle; delete pTextFileLoader; return Py_BuildNone(); @@ -1075,24 +1074,22 @@ PyObject * appCloseTextFile(PyObject * poSelf, PyObject * poArgs) PyObject * appGetTextFileLineCount(PyObject * poSelf, PyObject * poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CTextLineLoader* pTextFileLoader; + if (!PyTuple_GetPointer(poArgs, 0, &pTextFileLoader)) return Py_BuildException(); - CTextLineLoader * pTextFileLoader = (CTextLineLoader *)iHandle; return Py_BuildValue("i", pTextFileLoader->GetLineCount()); } PyObject * appGetTextFileLine(PyObject * poSelf, PyObject * poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CTextLineLoader* pTextFileLoader; + if (!PyTuple_GetPointer(poArgs, 0, &pTextFileLoader)) return Py_BuildException(); int iLineIndex; if (!PyTuple_GetInteger(poArgs, 1, &iLineIndex)) return Py_BuildException(); - CTextLineLoader * pTextFileLoader = (CTextLineLoader *)iHandle; return Py_BuildValue("s", pTextFileLoader->GetLine(iLineIndex)); } diff --git a/src/UserInterface/PythonItemModule.cpp b/src/UserInterface/PythonItemModule.cpp index 26a7aec..4479be9 100644 --- a/src/UserInterface/PythonItemModule.cpp +++ b/src/UserInterface/PythonItemModule.cpp @@ -287,11 +287,11 @@ PyObject * itemGetIconInstance(PyObject * poSelf, PyObject * poArgs) PyObject * itemDeleteIconInstance(PyObject * poSelf, PyObject * poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CGraphicImageInstance* pImgInstance; + if (!PyTuple_GetPointer(poArgs, 0, &pImgInstance)) return Py_BadArgument(); - CGraphicImageInstance::Delete((CGraphicImageInstance *) iHandle); + CGraphicImageInstance::Delete(pImgInstance); return Py_BuildNone(); } diff --git a/src/UserInterface/PythonSkill.cpp b/src/UserInterface/PythonSkill.cpp index 7736127..abee50b 100644 --- a/src/UserInterface/PythonSkill.cpp +++ b/src/UserInterface/PythonSkill.cpp @@ -2092,11 +2092,11 @@ PyObject * skillGetIconInstanceNew(PyObject * poSelf, PyObject * poArgs) PyObject * skillDeleteIconInstance(PyObject * poSelf, PyObject * poArgs) { - unsigned long long iHandle; - if (!PyTuple_GetUnsignedLongLong(poArgs, 0, &iHandle)) + CGraphicImageInstance* pImgInstance; + if (!PyTuple_GetPointer(poArgs, 0, &pImgInstance)) return Py_BadArgument(); - CGraphicImageInstance::Delete((CGraphicImageInstance *) iHandle); + CGraphicImageInstance::Delete(pImgInstance); return Py_BuildNone(); }