Commit 373f13e5 authored by ussrhero's avatar ussrhero
Browse files

Merge branch 'tuple_inc_ref' into 'master'

fixed memory corruption in PyTuple_SetItem

See merge request !3
parents e43d5c39 4a1bb96d
......@@ -67,6 +67,7 @@ void PySys_SetArgv_Py3(int argc, wchar_t **argv);
int PyRun_SimpleString(const char* str);
PyObject* PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals);
PyObject* PyRun_File(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals);
PyObject* PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, int closeit, void *flags);
typedef void(*PyCapsule_Destructor)(PyObject *);
PyObject* PyCapsule_New(void *pointer, const char *name, PyCapsule_Destructor destructor);
......
......@@ -214,7 +214,9 @@ static PyObject* getPythonClass() { \
PyObject* args = PyTuple_New(4); \
Py_IncRef(PyProperty_Type()); \
PyTuple_SetItem(args, 0, methodObj); \
Py_IncRef(Py_None()); \
PyTuple_SetItem(args, 1, Py_None()); \
Py_IncRef(Py_None()); \
PyTuple_SetItem(args, 2, Py_None()); \
PyTuple_SetItem(args, 3, IsPy3() ? PyUnicode_FromString(doc) : PyString_FromString(doc));\
PyObject* propertyObj = PyObject_CallObject(PyProperty_Type(), args); \
......
......@@ -84,6 +84,7 @@ public:
PyObject* ( *PyRun_String)(const char *str, int start, PyObject *globals, PyObject *locals);
int( *PyRun_SimpleString)(const char* str);
PyObject* ( *PyRun_File)(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals);
PyObject* ( *PyRun_FileExFlags)(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, int closeit, void *flags);
PyObject* ( *PyDict_New)();
int( *PyDict_SetItemString)(PyObject *p, const char *key, PyObject *val);
PyObject*( *PyDict_GetItemString)(PyObject *p, const char* key);
......@@ -438,6 +439,7 @@ PyModule::PyModule(int majorVesion, int minorVersion)
*reinterpret_cast<FARPROC*>(&PyRun_String) = GetProcAddress(m_handlePython, "PyRun_String");
*reinterpret_cast<FARPROC*>(&PyRun_SimpleString) = GetProcAddress(m_handlePython, "PyRun_SimpleString");
*reinterpret_cast<FARPROC*>(&PyRun_File) = GetProcAddress(m_handlePython, "PyRun_File");
*reinterpret_cast<FARPROC*>(&PyRun_FileExFlags) = GetProcAddress(m_handlePython, "PyRun_FileExFlags");
*reinterpret_cast<FARPROC*>(&PyDict_New) = GetProcAddress(m_handlePython, "PyDict_New");
*reinterpret_cast<FARPROC*>(&PyDict_SetItemString) = GetProcAddress(m_handlePython, "PyDict_SetItemString");
*reinterpret_cast<FARPROC*>(&PyDict_GetItemString) = GetProcAddress(m_handlePython, "PyDict_GetItemString");
......@@ -850,6 +852,12 @@ PyObject* PyRun_File(FILE *fp, const char *filename, int start, PyObject *globa
return PythonSingleton::get()->currentInterpreter()->m_module->PyRun_File(fp, filename, start, globals, locals);
}
PyObject* PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, int closeit, void *flags)
{
return PythonSingleton::get()->currentInterpreter()->m_module->PyRun_FileExFlags(fp, filename, start, globals, locals, closeit, flags);
}
PyObject* PyUnicode_FromString(const char* str)
{
return PythonSingleton::get()->currentInterpreter()->m_module->PyUnicode_FromString(str);
......
......@@ -3,7 +3,7 @@
#define PYKDEXT_VERSION_MAJOR 2
#define PYKDEXT_VERSION_MINOR 0
#define PYKDEXT_VERSION_SUBVERSION 0
#define PYKDEXT_VERSION_BUILDNO 23
#define PYKDEXT_VERSION_BUILDNO 24
#define __VER_STR2__(x) #x
#define __VER_STR1__(x) __VER_STR2__(x)
......
......@@ -428,8 +428,8 @@ py(
FILE* fs = _Py_fopen(scriptFileName.c_str(), "r");
if ( !fs )
throw std::invalid_argument("script not found\n");
PyObjectRef result = PyRun_File(fs, scriptFileName.c_str(), Py_file_input, globals, globals);
PyObjectRef result = PyRun_FileExFlags(fs, scriptFileName.c_str(), Py_file_input, globals, globals, 1, NULL);
}
}
else
......@@ -595,9 +595,14 @@ void handleException()
PyObjectRef format_exception = PyObject_GetAttrString(traceback_module, "format_exception");
PyObjectRef args = PyTuple_New(3);
PyTuple_SetItem(args, 0, errtype ? static_cast<PyObject*>(errtype) : Py_None());
PyTuple_SetItem(args, 1, errvalue ? static_cast<PyObject*>(errvalue) : Py_None());
PyTuple_SetItem(args, 2, traceback ? static_cast<PyObject*>(traceback) : Py_None());
PyObject* arg0 = errtype ? static_cast<PyObject*>(errtype) : Py_None(); Py_IncRef(arg0);
PyObject* arg1 = errvalue ? static_cast<PyObject*>(errvalue) : Py_None(); Py_IncRef(arg1);
PyObject* arg2 = traceback ? static_cast<PyObject*>(traceback) : Py_None(); Py_IncRef(arg2);
PyTuple_SetItem(args, 0, arg0);
PyTuple_SetItem(args, 1, arg1);
PyTuple_SetItem(args, 2, arg2);
PyObjectRef lst = PyObject_Call(format_exception, args, NULL);
......@@ -654,12 +659,7 @@ void getPathList( std::list<std::string> &pathStringLst)
std::string getScriptFileName(const std::string &scriptName)
{
char* ext = NULL;
if (scriptName.length() <= 3 || scriptName.find_last_of(".py") != scriptName.length() - 3 )
{
ext = ".py";
}
char* ext = ".py";
DWORD searchResult = SearchPathA(
NULL,
......@@ -671,7 +671,7 @@ std::string getScriptFileName(const std::string &scriptName)
if ( searchResult == 0 )
{
return "";
return "";
}
std::vector<char> pathBuffer(searchResult);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment