mirror of
https://github.com/cemu-project/idapython.git
synced 2024-11-28 03:54:18 +01:00
python.cpp: Added float support for extlang_python
python.cpp: Proper error reporting implemented
This commit is contained in:
parent
ec4d2f7a06
commit
490fa999c4
21
python.cpp
21
python.cpp
@ -21,6 +21,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ida.hpp>
|
#include <ida.hpp>
|
||||||
#include <idp.hpp>
|
#include <idp.hpp>
|
||||||
|
#include <ieee.h>
|
||||||
#include <bytes.hpp>
|
#include <bytes.hpp>
|
||||||
#include <diskio.hpp>
|
#include <diskio.hpp>
|
||||||
#include <expr.hpp>
|
#include <expr.hpp>
|
||||||
@ -289,6 +290,7 @@ bool idaapi IDAPython_extlang_calcexpr(ea_t current_ea,
|
|||||||
PyObject *result;
|
PyObject *result;
|
||||||
PyObject *ptype, *pvalue, *ptraceback;
|
PyObject *ptype, *pvalue, *ptraceback;
|
||||||
PyObject *module = PyImport_AddModule("__main__");
|
PyObject *module = PyImport_AddModule("__main__");
|
||||||
|
double dresult;
|
||||||
|
|
||||||
if (module == NULL)
|
if (module == NULL)
|
||||||
return false;
|
return false;
|
||||||
@ -299,10 +301,24 @@ bool idaapi IDAPython_extlang_calcexpr(ea_t current_ea,
|
|||||||
|
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
{
|
{
|
||||||
|
/* Return a formatted error or just print it to the console */
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
|
{
|
||||||
|
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
|
||||||
|
result = PyObject_Repr(pvalue);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
qsnprintf(errbuf, errbufsize, "ERROR: %s", PyString_AsString(result));
|
||||||
|
PyErr_Clear();
|
||||||
|
Py_XDECREF(ptype);
|
||||||
|
Py_XDECREF(pvalue);
|
||||||
|
Py_XDECREF(ptraceback);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,8 +347,9 @@ bool idaapi IDAPython_extlang_calcexpr(ea_t current_ea,
|
|||||||
|
|
||||||
if (PyFloat_Check(result))
|
if (PyFloat_Check(result))
|
||||||
{
|
{
|
||||||
rv->num = PyInt_AsLong(result);
|
dresult = PyFloat_AsDouble(result);
|
||||||
rv->vtype = VT_LONG;
|
ieee_realcvt((void *)&dresult, rv->e, 3);
|
||||||
|
rv->vtype = VT_FLOAT;
|
||||||
Py_XDECREF(result);
|
Py_XDECREF(result);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user