From: Andreas Monzner Date: Sat, 25 Nov 2006 17:18:48 +0000 (+0000) Subject: python object refcount debugging code second try X-Git-Tag: 2.6.0~2669 X-Git-Url: https://git.cweiske.de/enigma2.git/commitdiff_plain/6dcb75c26bbfec04b381bb99d75404f9fe50635d python object refcount debugging code second try --- diff --git a/lib/actions/action.cpp b/lib/actions/action.cpp index 8b298ead..56ad89a1 100644 --- a/lib/actions/action.cpp +++ b/lib/actions/action.cpp @@ -54,12 +54,11 @@ void eActionMap::bindAction(const std::string &context, int priority, int id, eW bnd.m_context = context; bnd.m_widget = widget; - bnd.m_fnc = 0; bnd.m_id = id; m_bindings.insert(std::pair(priority, bnd)); } -void eActionMap::bindAction(const std::string &context, int priority, PyObject *function) +void eActionMap::bindAction(const std::string &context, int priority, ePyObject function) { eActionBinding bnd; @@ -80,7 +79,7 @@ void eActionMap::unbindAction(eWidget *widget, int id) } } -void eActionMap::unbindAction(const std::string &context, PyObject *function) +void eActionMap::unbindAction(const std::string &context, ePyObject function) { for (std::multimap::iterator i(m_bindings.begin()); i != m_bindings.end(); ++i) { @@ -126,11 +125,11 @@ void eActionMap::bindKey(const std::string &device, int key, int flags, const st struct call_entry { - PyObject *m_fnc, *m_arg; + ePyObject m_fnc, m_arg; eWidget *m_widget; void *m_widget_arg, *m_widget_arg2; - call_entry(PyObject *fnc, PyObject *arg): m_fnc(fnc), m_arg(arg), m_widget(0), m_widget_arg(0) { } - call_entry(eWidget *widget, void *arg, void *arg2): m_fnc(0), m_arg(0), m_widget(widget), m_widget_arg(arg), m_widget_arg2(arg2) { } + call_entry(ePyObject fnc, ePyObject arg): m_fnc(fnc), m_arg(arg), m_widget(0), m_widget_arg(0) { } + call_entry(eWidget *widget, void *arg, void *arg2): m_widget(widget), m_widget_arg(arg), m_widget_arg2(arg2) { } }; void eActionMap::keyPressed(const std::string &device, int key, int flags) @@ -183,7 +182,7 @@ void eActionMap::keyPressed(const std::string &device, int key, int flags) ((k->second.m_device == device) || (k->second.m_device == "generic")) ) { - PyObject *pArgs = PyTuple_New(2); + ePyObject pArgs = PyTuple_New(2); PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(k->first.c_str())); PyTuple_SET_ITEM(pArgs, 1, PyString_FromString(k->second.m_action.c_str())); ++k; @@ -195,7 +194,7 @@ void eActionMap::keyPressed(const std::string &device, int key, int flags) } else { eDebug("wildcard."); - PyObject *pArgs = PyTuple_New(2); + ePyObject pArgs = PyTuple_New(2); PyTuple_SET_ITEM(pArgs, 0, PyInt_FromLong(key)); PyTuple_SET_ITEM(pArgs, 1, PyInt_FromLong(flags)); Py_INCREF(i->second.m_fnc); diff --git a/lib/actions/action.h b/lib/actions/action.h index 560fdbbf..f2e0d8f4 100644 --- a/lib/actions/action.h +++ b/lib/actions/action.h @@ -7,7 +7,6 @@ #include #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L -#include #include #include #include @@ -29,8 +28,8 @@ public: void unbindAction(eWidget *widget, int id); #endif - void bindAction(const std::string &context, int priority, PyObject *function); - void unbindAction(const std::string &context, PyObject *function); + void bindAction(const std::string &context, int priority, SWIG_PYOBJECT(ePyObject) function); + void unbindAction(const std::string &context, SWIG_PYOBJECT(ePyObject) function); void bindKey(const std::string &device, int key, int flags, const std::string &context, const std::string &action); @@ -45,7 +44,7 @@ private: // eActionContext *m_context; std::string m_context; // FIXME - PyObject *m_fnc; + ePyObject m_fnc; eWidget *m_widget; int m_id; diff --git a/lib/base/ebase.cpp b/lib/base/ebase.cpp index 67e02347..480c8ea8 100644 --- a/lib/base/ebase.cpp +++ b/lib/base/ebase.cpp @@ -131,7 +131,7 @@ void eMainloop::removeSocketNotifier(eSocketNotifier *sn) eFatal("removed socket notifier which is not present"); } -int eMainloop::processOneEvent(unsigned int user_timeout, PyObject **res, PyObject *additional) +int eMainloop::processOneEvent(unsigned int user_timeout, PyObject **res, ePyObject additional) { int return_reason = 0; /* get current time */ @@ -222,7 +222,7 @@ int eMainloop::processOneEvent(unsigned int user_timeout, PyObject **res, PyObje { if (!*res) *res = PyList_New(0); - PyObject *it = PyTuple_New(2); + ePyObject it = PyTuple_New(2); PyTuple_SET_ITEM(it, 0, PyInt_FromLong(pfd[i].fd)); PyTuple_SET_ITEM(it, 1, PyInt_FromLong(pfd[i].revents)); PyList_Append(*res, it); @@ -272,7 +272,7 @@ void eMainloop::removeTimer(eTimer* e) m_timer_list.remove(e); } -int eMainloop::iterate(unsigned int user_timeout, PyObject **res, PyObject *dict) +int eMainloop::iterate(unsigned int user_timeout, PyObject **res, ePyObject dict) { int ret = 0; @@ -320,9 +320,9 @@ void eMainloop::reset() app_quit_now=false; } -PyObject *eMainloop::poll(PyObject *timeout, PyObject *dict) +PyObject *eMainloop::poll(ePyObject timeout, ePyObject dict) { - PyObject *res = 0; + PyObject *res=0; if (app_quit_now) { @@ -333,11 +333,12 @@ PyObject *eMainloop::poll(PyObject *timeout, PyObject *dict) int user_timeout = (timeout == Py_None) ? 0 : PyInt_AsLong(timeout); iterate(user_timeout, &res, dict); + ePyObject ret(res); - if (!res) /* return empty list on timeout */ - res = PyList_New(0); + if (!ret) /* return empty list on timeout */ + return PyList_New(0); - return res; + return ret; } void eMainloop::interruptPoll() diff --git a/lib/base/ebase.h b/lib/base/ebase.h index cf973c89..a399667e 100644 --- a/lib/base/ebase.h +++ b/lib/base/ebase.h @@ -179,7 +179,7 @@ class eMainloop ePtrList m_timer_list; bool app_quit_now; int loop_level; - int processOneEvent(unsigned int user_timeout, PyObject **res=0, PyObject *additional=0); + int processOneEvent(unsigned int user_timeout, PyObject **res=0, ePyObject additional=ePyObject()); int retval; pthread_mutex_t recalcLock; @@ -219,14 +219,14 @@ public: 1 - timeout 2 - signal */ - int iterate(unsigned int timeout=0, PyObject **res=0, PyObject *additional=0); - + int iterate(unsigned int timeout=0, PyObject **res=0, SWIG_PYOBJECT(ePyObject) additional=(PyObject*)0); + /* run will iterate endlessly until the app is quit, and return the exit code */ int runLoop(); /* our new shared polling interface. */ - PyObject *poll(PyObject *dict, PyObject *timeout); + PyObject *poll(SWIG_PYOBJECT(ePyObject) dict, SWIG_PYOBJECT(ePyObject) timeout); void interruptPoll(); void reset(); }; diff --git a/lib/base/nconfig.cpp b/lib/base/nconfig.cpp index 562b3503..31b0a36f 100644 --- a/lib/base/nconfig.cpp +++ b/lib/base/nconfig.cpp @@ -1,9 +1,9 @@ #include -#include +#include -PyObject *ePythonConfigQuery::m_queryFunc; +ePyObject ePythonConfigQuery::m_queryFunc; -void ePythonConfigQuery::setQueryFunc(PyObject *queryFunc) +void ePythonConfigQuery::setQueryFunc(ePyObject queryFunc) { if (m_queryFunc) Py_DECREF(m_queryFunc); @@ -16,9 +16,9 @@ RESULT ePythonConfigQuery::getConfigValue(const char *key, std::string &value) { if (key && PyCallable_Check(m_queryFunc)) { - PyObject *pArgs = PyTuple_New(1); + ePyObject pArgs = PyTuple_New(1); PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(key)); - PyObject *pRet = PyObject_CallObject(m_queryFunc, pArgs); + ePyObject pRet = PyObject_CallObject(m_queryFunc, pArgs); Py_DECREF(pArgs); if (pRet) { diff --git a/lib/base/nconfig.h b/lib/base/nconfig.h index 2c87491a..36674392 100644 --- a/lib/base/nconfig.h +++ b/lib/base/nconfig.h @@ -5,11 +5,11 @@ class ePythonConfigQuery { - static PyObject *m_queryFunc; + static ePyObject m_queryFunc; ePythonConfigQuery() {} ~ePythonConfigQuery() {} public: - static void setQueryFunc(PyObject *func); + static void setQueryFunc(SWIG_PYOBJECT(ePyObject) func); #ifndef SWIG static RESULT getConfigValue(const char *key, std::string &value); #endif diff --git a/lib/dvb/epgcache.cpp b/lib/dvb/epgcache.cpp index e8394c40..7cd56b94 100644 --- a/lib/dvb/epgcache.cpp +++ b/lib/dvb/epgcache.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include int eventData::CacheSize=0; descriptorMap eventData::descriptors; @@ -1522,9 +1522,9 @@ RESULT eEPGCache::getNextTimeEntry(ePtr &result) return -1; } -void fillTuple(PyObject *tuple, char *argstring, int argcount, PyObject *service, ePtr &ptr, PyObject *nowTime, PyObject *service_name ) +void fillTuple(ePyObject tuple, char *argstring, int argcount, ePyObject service, ePtr &ptr, ePyObject nowTime, ePyObject service_name ) { - PyObject *tmp=NULL; + ePyObject tmp; int pos=0; while(pos < argcount) { @@ -1575,12 +1575,12 @@ void fillTuple(PyObject *tuple, char *argstring, int argcount, PyObject *service } } -int handleEvent(ePtr &ptr, PyObject *dest_list, char* argstring, int argcount, PyObject *service, PyObject *nowTime, PyObject *service_name, PyObject *convertFunc, PyObject *convertFuncArgs) +int handleEvent(ePtr &ptr, ePyObject dest_list, char* argstring, int argcount, ePyObject service, ePyObject nowTime, ePyObject service_name, ePyObject convertFunc, ePyObject convertFuncArgs) { if (convertFunc) { fillTuple(convertFuncArgs, argstring, argcount, service, ptr, nowTime, service_name); - PyObject *result = PyObject_CallObject(convertFunc, convertFuncArgs); + ePyObject result = PyObject_CallObject(convertFunc, convertFuncArgs); if (result == NULL) { if (service_name) @@ -1599,7 +1599,7 @@ int handleEvent(ePtr &ptr, PyObject *dest_list, char* argstring, } else { - PyObject *tuple = PyTuple_New(argcount); + ePyObject tuple = PyTuple_New(argcount); fillTuple(tuple, argstring, argcount, service, ptr, nowTime, service_name); PyList_Append(dest_list, tuple); Py_DECREF(tuple); @@ -1631,9 +1631,9 @@ int handleEvent(ePtr &ptr, PyObject *dest_list, char* argstring, // when type is time then it is the start_time ( 0 for now_time ) // the fourth is the end_time .. ( optional .. for query all events in time range) -PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc) +PyObject *eEPGCache::lookupEvent(ePyObject list, ePyObject convertFunc) { - PyObject *convertFuncArgs=NULL; + ePyObject convertFuncArgs; int argcount=0; char *argstring=NULL; if (!PyList_Check(list)) @@ -1654,7 +1654,7 @@ PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc) } else { - PyObject *argv=PyList_GET_ITEM(list, 0); // borrowed reference! + ePyObject argv=PyList_GET_ITEM(list, 0); // borrowed reference! if (PyString_Check(argv)) { argstring = PyString_AS_STRING(argv); @@ -1677,17 +1677,17 @@ PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc) convertFuncArgs = PyTuple_New(argcount); } - PyObject *nowTime = strchr(argstring, 'C') ? + ePyObject nowTime = strchr(argstring, 'C') ? PyLong_FromLong(eDVBLocalTimeHandler::getInstance()->nowTime()) : NULL; bool must_get_service_name = strchr(argstring, 'N') ? true : false; // create dest list - PyObject *dest_list=PyList_New(0); + ePyObject dest_list=PyList_New(0); while(listSize > listIt) { - PyObject *item=PyList_GET_ITEM(list, listIt++); // borrowed reference! + ePyObject item=PyList_GET_ITEM(list, listIt++); // borrowed reference! if (PyTuple_Check(item)) { bool service_changed=false; @@ -1697,10 +1697,10 @@ PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc) int minutes=0; int tupleSize=PyTuple_Size(item); int tupleIt=0; - PyObject *service=NULL; + ePyObject service; while(tupleSize > tupleIt) // parse query args { - PyObject *entry=PyTuple_GET_ITEM(item, tupleIt); // borrowed reference! + ePyObject entry=PyTuple_GET_ITEM(item, tupleIt); // borrowed reference! switch(tupleIt++) { case 0: @@ -1756,7 +1756,7 @@ PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc) } } - PyObject *service_name=NULL; + ePyObject service_name; if (must_get_service_name) { ePtr sptr; @@ -1821,9 +1821,9 @@ skip_entry: return dest_list; } -void fillTuple2(PyObject *tuple, const char *argstring, int argcount, eventData *evData, ePtr &ptr, PyObject *service_name, PyObject *service_reference) +void fillTuple2(ePyObject tuple, const char *argstring, int argcount, eventData *evData, ePtr &ptr, ePyObject service_name, ePyObject service_reference) { - PyObject *tmp=NULL; + ePyObject tmp; int pos=0; while(pos < argcount) { @@ -1901,9 +1901,9 @@ void fillTuple2(PyObject *tuple, const char *argstring, int argcount, eventData // 0 = case sensitive (CASE_CHECK) // 1 = case insensitive (NO_CASECHECK) -PyObject *eEPGCache::search(PyObject *arg) +PyObject *eEPGCache::search(ePyObject arg) { - PyObject *ret = 0; + ePyObject ret; int descridx = -1; __u32 descr[512]; int eventid = -1; @@ -1919,7 +1919,7 @@ PyObject *eEPGCache::search(PyObject *arg) int tuplesize=PyTuple_Size(arg); if (tuplesize > 0) { - PyObject *obj = PyTuple_GET_ITEM(arg,0); + ePyObject obj = PyTuple_GET_ITEM(arg,0); if (PyString_Check(obj)) { argcount = PyString_GET_SIZE(obj); @@ -1950,7 +1950,7 @@ PyObject *eEPGCache::search(PyObject *arg) querytype = PyLong_AsLong(PyTuple_GET_ITEM(arg, 2)); if (tuplesize > 4 && querytype == 0) { - PyObject *obj = PyTuple_GET_ITEM(arg, 3); + ePyObject obj = PyTuple_GET_ITEM(arg, 3); if (PyString_Check(obj)) { refstr = PyString_AS_STRING(obj); @@ -2007,7 +2007,7 @@ PyObject *eEPGCache::search(PyObject *arg) } else if (tuplesize > 4 && (querytype == 1 || querytype == 2) ) { - PyObject *obj = PyTuple_GET_ITEM(arg, 3); + ePyObject obj = PyTuple_GET_ITEM(arg, 3); if (PyString_Check(obj)) { int casetype = PyLong_AsLong(PyTuple_GET_ITEM(arg, 4)); @@ -2124,8 +2124,8 @@ PyObject *eEPGCache::search(PyObject *arg) ++cit; continue; } - PyObject *service_name=0; - PyObject *service_reference=0; + ePyObject service_name; + ePyObject service_reference; timeMap &evmap = cit->second.second; // check all events for (timeMap::iterator evit(evmap.begin()); evit != evmap.end() && maxcount; ++evit) @@ -2191,7 +2191,7 @@ PyObject *eEPGCache::search(PyObject *arg) if (!ret) ret = PyList_New(0); // create tuple - PyObject *tuple = PyTuple_New(argcount); + ePyObject tuple = PyTuple_New(argcount); // fill tuple fillTuple2(tuple, argstring, argcount, evit->second, ptr, service_name, service_reference); PyList_Append(ret, tuple); diff --git a/lib/dvb/epgcache.h b/lib/dvb/epgcache.h index fe768aee..16274965 100644 --- a/lib/dvb/epgcache.h +++ b/lib/dvb/epgcache.h @@ -338,8 +338,8 @@ public: CASE_CHECK, NO_CASE_CHECK }; - PyObject *lookupEvent(PyObject *list, PyObject *convertFunc=NULL); - PyObject *search(PyObject *); + PyObject *lookupEvent(SWIG_PYOBJECT(ePyObject) list, SWIG_PYOBJECT(ePyObject) convertFunc=(PyObject*)0); + PyObject *search(SWIG_PYOBJECT(ePyObject)); // eServiceEvent are parsed epg events.. it's safe to use them after cache unlock // for use from python ( members: m_start_time, m_duration, m_short_description, m_extended_description ) diff --git a/lib/dvb/frontend.cpp b/lib/dvb/frontend.cpp index 2712134c..133aa0f7 100644 --- a/lib/dvb/frontend.cpp +++ b/lib/dvb/frontend.cpp @@ -660,9 +660,9 @@ int eDVBFrontend::readFrontendData(int type) return 0; } -void PutToDict(PyObject *dict, const char*key, long value) +void PutToDict(ePyObject &dict, const char*key, long value) { - PyObject *item = PyInt_FromLong(value); + ePyObject item = PyInt_FromLong(value); if (item) { if (PyDict_SetItemString(dict, key, item)) @@ -673,9 +673,9 @@ void PutToDict(PyObject *dict, const char*key, long value) eDebug("could not create PyObject for %s", key); } -void PutToDict(PyObject *dict, const char*key, const char *value) +void PutToDict(ePyObject &dict, const char*key, const char *value) { - PyObject *item = PyString_FromString(value); + ePyObject item = PyString_FromString(value); if (item) { if (PyDict_SetItemString(dict, key, item)) @@ -686,7 +686,7 @@ void PutToDict(PyObject *dict, const char*key, const char *value) eDebug("could not create PyObject for %s", key); } -void fillDictWithSatelliteData(PyObject *dict, const FRONTENDPARAMETERS &parm, eDVBFrontend *fe) +void fillDictWithSatelliteData(ePyObject dict, const FRONTENDPARAMETERS &parm, eDVBFrontend *fe) { int freq_offset=0; int csw=0; @@ -770,7 +770,7 @@ void fillDictWithSatelliteData(PyObject *dict, const FRONTENDPARAMETERS &parm, e PutToDict(dict, "system", tmp); } -void fillDictWithCableData(PyObject *dict, const FRONTENDPARAMETERS &parm) +void fillDictWithCableData(ePyObject dict, const FRONTENDPARAMETERS &parm) { const char *tmp=0; PutToDict(dict, "frequency", parm_frequency/1000); @@ -831,7 +831,7 @@ void fillDictWithCableData(PyObject *dict, const FRONTENDPARAMETERS &parm) PutToDict(dict, "modulation", tmp); } -void fillDictWithTerrestrialData(PyObject *dict, const FRONTENDPARAMETERS &parm) +void fillDictWithTerrestrialData(ePyObject dict, const FRONTENDPARAMETERS &parm) { const char *tmp=0; PutToDict(dict, "frequency", parm_frequency); @@ -973,7 +973,7 @@ void fillDictWithTerrestrialData(PyObject *dict, const FRONTENDPARAMETERS &parm) PyObject *eDVBFrontend::readTransponderData(bool original) { - PyObject *ret=PyDict_New(); + ePyObject ret=PyDict_New(); if (ret) { diff --git a/lib/dvb/pmt.cpp b/lib/dvb/pmt.cpp index bdb10b18..4b0acdfa 100644 --- a/lib/dvb/pmt.cpp +++ b/lib/dvb/pmt.cpp @@ -141,7 +141,7 @@ void eDVBServicePMTHandler::PATready(int) PyObject *eDVBServicePMTHandler::getCaIds() { - PyObject *ret=0; + ePyObject ret; program prog; @@ -157,7 +157,7 @@ PyObject *eDVBServicePMTHandler::getCaIds() } } - return ret ? ret : PyList_New(0); + return ret ? (PyObject*)ret : (PyObject*)PyList_New(0); } int eDVBServicePMTHandler::getProgramInfo(struct program &program) diff --git a/lib/dvb/sec.cpp b/lib/dvb/sec.cpp index 86f549c2..7342a4b7 100644 --- a/lib/dvb/sec.cpp +++ b/lib/dvb/sec.cpp @@ -1102,7 +1102,7 @@ struct sat_compare PyObject *eDVBSatelliteEquipmentControl::get_exclusive_satellites(int tu1, int tu2) { - PyObject *ret=0; + ePyObject ret; if (tu1 != tu2) { diff --git a/lib/dvb_ci/dvbci_ui.cpp b/lib/dvb_ci/dvbci_ui.cpp index 1ff0c326..9fb89b39 100644 --- a/lib/dvb_ci/dvbci_ui.cpp +++ b/lib/dvb_ci/dvbci_ui.cpp @@ -19,7 +19,6 @@ eDVBCI_UI::eDVBCI_UI() instance = this; for(int i=0;i +#include #include #define MAX_SLOTS 4 @@ -15,7 +15,7 @@ struct slot_ui_data { std::string appName; int state; - PyObject *mmiScreen; + ePyObject mmiScreen; int mmiTuplePos; int mmiScreenReady; }; diff --git a/lib/gdi/picload.cpp b/lib/gdi/picload.cpp index b3ffe2a8..43dfe3a0 100644 --- a/lib/gdi/picload.cpp +++ b/lib/gdi/picload.cpp @@ -1,5 +1,6 @@ -#include "picload.h" +#include #include "picexif.h" +#include #include @@ -335,7 +336,7 @@ static int png_load(const char *filename, int *x, int *y) PyObject *getExif(const char *filename) { - PyObject *list = 0; + ePyObject list; Cexif exif; if(exif.DecodeExif(filename)) { @@ -388,7 +389,7 @@ PyObject *getExif(const char *filename) PyList_SET_ITEM(list, 0, PyString_FromString(exif.m_szLastError)); } - return list ? list : PyList_New(0); + return list ? (PyObject*)list : (PyObject*)PyList_New(0); } //--------------------------------------------------------------------------------------------- diff --git a/lib/gui/elistboxcontent.cpp b/lib/gui/elistboxcontent.cpp index 261c548b..d4272a0a 100644 --- a/lib/gui/elistboxcontent.cpp +++ b/lib/gui/elistboxcontent.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include /* The basic idea is to have an interface which gives all relevant list @@ -50,7 +50,6 @@ DEFINE_REF(eListboxPythonStringContent); eListboxPythonStringContent::eListboxPythonStringContent() { - m_list = 0; } eListboxPythonStringContent::~eListboxPythonStringContent() @@ -104,7 +103,7 @@ int eListboxPythonStringContent::currentCursorSelectable() { if (m_list && cursorValid()) { - PyObject *item = PyList_GET_ITEM(m_list, m_cursor); + ePyObject item = PyList_GET_ITEM(m_list, m_cursor); if (!PyTuple_Check(item)) return 1; if (PyTuple_Size(item) >= 2) @@ -145,7 +144,7 @@ void eListboxPythonStringContent::paint(gPainter &painter, eWindowStyle &style, if (m_list && cursorValid()) { int gray = 0; - PyObject *item = PyList_GET_ITEM(m_list, m_cursor); // borrowed reference! + ePyObject item = PyList_GET_ITEM(m_list, m_cursor); // borrowed reference! painter.setFont(fnt); /* the user can supply tuples, in this case the first one will be displayed. */ @@ -177,12 +176,12 @@ void eListboxPythonStringContent::paint(gPainter &painter, eWindowStyle &style, painter.clippop(); } -void eListboxPythonStringContent::setList(PyObject *list) +void eListboxPythonStringContent::setList(ePyObject list) { Py_XDECREF(m_list); if (!PyList_Check(list)) { - m_list = 0; + m_list = ePyObject(); } else { m_list = list; @@ -200,7 +199,7 @@ PyObject *eListboxPythonStringContent::getCurrentSelection() Py_INCREF(Py_None); return Py_None; } - PyObject *r = PyList_GET_ITEM(m_list, m_cursor); + ePyObject r = PyList_GET_ITEM(m_list, m_cursor); Py_XINCREF(r); return r; } @@ -236,8 +235,8 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, if (m_list && cursorValid()) { /* get current list item */ - PyObject *item = PyList_GET_ITEM(m_list, m_cursor); // borrowed reference! - PyObject *text = 0, *value = 0; + ePyObject item = PyList_GET_ITEM(m_list, m_cursor); // borrowed reference! + ePyObject text, value; painter.setFont(fnt); /* the first tuple element is a string for the left side. @@ -266,7 +265,7 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, value = PyTuple_GET_ITEM(item, 1); if (value) { - PyObject *args = PyTuple_New(1); + ePyObject args = PyTuple_New(1); PyTuple_SET_ITEM(args, 0, PyInt_FromLong(selected)); /* CallObject will call __call__ which should return the value tuple */ @@ -283,14 +282,14 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, if (value && PyTuple_Check(value)) { /* convert type to string */ - PyObject *type = PyTuple_GET_ITEM(value, 0); + ePyObject type = PyTuple_GET_ITEM(value, 0); const char *atype = (type && PyString_Check(type)) ? PyString_AsString(type) : 0; if (atype) { if (!strcmp(atype, "text")) { - PyObject *pvalue = PyTuple_GET_ITEM(value, 1); + ePyObject pvalue = PyTuple_GET_ITEM(value, 1); const char *value = (pvalue && PyString_Check(pvalue)) ? PyString_AsString(pvalue) : ""; painter.setFont(fnt2); if (value_alignment_left) @@ -301,8 +300,8 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, /* pvalue is borrowed */ } else if (!strcmp(atype, "slider")) { - PyObject *pvalue = PyTuple_GET_ITEM(value, 1); - PyObject *psize = PyTuple_GET_ITEM(value, 2); + ePyObject pvalue = PyTuple_GET_ITEM(value, 1); + ePyObject psize = PyTuple_GET_ITEM(value, 2); /* convert value to Long. fallback to -1 on error. */ int value = (pvalue && PyInt_Check(pvalue)) ? PyInt_AsLong(pvalue) : -1; @@ -321,7 +320,7 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, /* pvalue is borrowed */ } else if (!strcmp(atype, "mtext")) { - PyObject *pvalue = PyTuple_GET_ITEM(value, 1); + ePyObject pvalue = PyTuple_GET_ITEM(value, 1); const char *text = (pvalue && PyString_Check(pvalue)) ? PyString_AsString(pvalue) : ""; int xoffs = value_alignment_left ? 0 : m_seperation; ePtr para = new eTextPara(eRect(offset + eSize(xoffs, 0), item_right)); @@ -330,7 +329,7 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, para->realign(value_alignment_left ? eTextPara::dirLeft : eTextPara::dirRight); int glyphs = para->size(); - PyObject *plist = 0; + ePyObject plist; if (PyTuple_Size(value) >= 3) plist = PyTuple_GET_ITEM(value, 2); @@ -342,7 +341,7 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, for (int i = 0; i < entries; ++i) { - PyObject *entry = PyList_GET_ITEM(plist, i); + ePyObject entry = PyList_GET_ITEM(plist, i); int num = PyInt_Check(entry) ? PyInt_AsLong(entry) : -1; if ((num < 0) || (num >= glyphs)) @@ -387,7 +386,6 @@ int eListboxPythonConfigContent::currentCursorSelectable() RESULT SwigFromPython(ePtr &res, PyObject *obj); eListboxPythonMultiContent::eListboxPythonMultiContent() - :m_buildFunc(0) { } @@ -404,7 +402,7 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal); painter.clear(); - PyObject *items=0; + ePyObject items; if (m_list && cursorValid()) { @@ -438,7 +436,7 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c int size = PyList_Size(items); for (int i = 1; i < size; ++i) { - PyObject *item = PyList_GET_ITEM(items, i); // borrowed reference! + ePyObject item = PyList_GET_ITEM(items, i); // borrowed reference! if (!item) { @@ -446,7 +444,7 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c goto error_out; } - PyObject *px = 0, *py = 0, *pwidth = 0, *pheight = 0, *pfnt = 0, *pstring = 0, *pflags = 0, *pcolor = 0; + ePyObject px, py, pwidth, pheight, pfnt, pstring, pflags, pcolor; /* we have a list of tuples: @@ -630,7 +628,7 @@ error_out: painter.clippop(); } -void eListboxPythonMultiContent::setBuildFunc(PyObject *cb) +void eListboxPythonMultiContent::setBuildFunc(ePyObject cb) { if (m_buildFunc) Py_DECREF(m_buildFunc); @@ -644,7 +642,7 @@ int eListboxPythonMultiContent::currentCursorSelectable() /* each list-entry is a list of tuples. if the first of these is none, it's not selectable */ if (m_list && cursorValid()) { - PyObject *item = PyList_GET_ITEM(m_list, m_cursor); + ePyObject item = PyList_GET_ITEM(m_list, m_cursor); if (PyList_Check(item)) { item = PyList_GET_ITEM(item, 0); diff --git a/lib/gui/elistboxcontent.h b/lib/gui/elistboxcontent.h index f7e5d2b6..d86d592d 100644 --- a/lib/gui/elistboxcontent.h +++ b/lib/gui/elistboxcontent.h @@ -11,7 +11,7 @@ public: eListboxPythonStringContent(); ~eListboxPythonStringContent(); - void setList(PyObject *list); + void setList(SWIG_PYOBJECT(ePyObject) list); PyObject *getCurrentSelection(); int getCurrentSelectionIndex() { return m_cursor; } void invalidateEntry(int index); @@ -40,7 +40,7 @@ protected: virtual void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected); protected: - PyObject *m_list; + ePyObject m_list; int m_cursor, m_saved_cursor; eSize m_itemsize; #endif @@ -58,7 +58,7 @@ private: class eListboxPythonMultiContent: public eListboxPythonStringContent { - PyObject *m_buildFunc; + ePyObject m_buildFunc; public: eListboxPythonMultiContent(); ~eListboxPythonMultiContent(); @@ -67,7 +67,7 @@ public: int currentCursorSelectable(); void setFont(int fnt, gFont *fnt); - void setBuildFunc(PyObject *func); + void setBuildFunc(SWIG_PYOBJECT(ePyObject) func); private: std::map > m_font; }; diff --git a/lib/gui/epositiongauge.cpp b/lib/gui/epositiongauge.cpp index 68a4b46d..fbb24571 100644 --- a/lib/gui/epositiongauge.cpp +++ b/lib/gui/epositiongauge.cpp @@ -59,7 +59,7 @@ void ePositionGauge::setPointer(int which, gPixmap *pixmap, const ePoint ¢er updatePosition(); } -void ePositionGauge::setInOutList(PyObject *list) +void ePositionGauge::setInOutList(ePyObject list) { if (!PyList_Check(list)) return; @@ -70,14 +70,14 @@ void ePositionGauge::setInOutList(PyObject *list) for (i=0; i #include -#include +#include void eNavigation::serviceEvent(iPlayableService* service, int event) { @@ -99,11 +99,9 @@ RESULT eNavigation::stopRecordService(ePtr &service) return -1; } -extern PyObject *New_iRecordableServicePtr(const ePtr &ref); // defined in enigma_python.i - PyObject *eNavigation::getRecordings(void) { - PyObject *result = PyList_New(m_recordings.size()); + ePyObject result = PyList_New(m_recordings.size()); int pos=0; for (std::map, ePtr >::iterator it(m_recordings.begin()); it != m_recordings.end(); ++it) PyList_SET_ITEM(result, pos++, New_iRecordableServicePtr(it->first)); diff --git a/lib/python/connections.cpp b/lib/python/connections.cpp index c24c9399..fd3e2a4b 100644 --- a/lib/python/connections.cpp +++ b/lib/python/connections.cpp @@ -1,9 +1,29 @@ #include -PSignal1 testsignal; +PSignal::PSignal() +{ + m_list = PyList_New(0); + Py_INCREF(m_list); +} -void connect(Slot1 &slot, PyObject *fnc) +PSignal::~PSignal() { - printf("CONNECT !\n"); + Py_DECREF(m_list); } +void PSignal::callPython(ePyObject tuple) +{ + int size = PyList_Size(m_list); + int i; + for (i=0; i #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L -#include + #include class PSignal { + ePyObject m_list; public: - PyObject *m_list; -public: - PSignal() - { - m_list = PyList_New(0); - Py_INCREF(m_list); - } - ~PSignal() - { - Py_DECREF(m_list); - } - - void callPython(PyObject *tuple) - { - int size = PyList_Size(m_list); - int i; - for (i=0; i::operator()(); } }; @@ -72,7 +52,7 @@ public: PyObject *pArgs = PyTuple_New(1); PyTuple_SET_ITEM(pArgs, 0, PyFrom(a0)); callPython(pArgs); - Py_DECREF(pArgs); + Org_Py_DECREF(pArgs); return Signal1::operator()(a0); } }; @@ -87,7 +67,7 @@ public: PyTuple_SET_ITEM(pArgs, 0, PyFrom(a0)); PyTuple_SET_ITEM(pArgs, 1, PyFrom(a1)); callPython(pArgs); - Py_DECREF(pArgs); + Org_Py_DECREF(pArgs); return Signal2::operator()(a0, a1); } }; diff --git a/lib/python/python.cpp b/lib/python/python.cpp index 119bff1c..8947bb3c 100644 --- a/lib/python/python.cpp +++ b/lib/python/python.cpp @@ -1,62 +1,130 @@ -#include #include /* avoid warnigs :) */ #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L -#include - extern "C" void init_enigma(); extern void bsodFatal(); -DEFINE_REF(TestObj); +#define SKIP_PART2 +#include +#undef SKIP_PART2 -TestObj::TestObj() +#ifdef PYTHON_REFCOUNT_DEBUG +ePyObject &ePyObject::operator=(PyObject *ob) { - eDebug("create %p", this); + m_ob=ob; + m_file=0; + m_line=0; + m_from=m_to=0; + m_erased=false; + return *this; } -TestObj::~TestObj() +ePyObject &ePyObject::operator=(const ePyObject &ob) { - eDebug("destroy %p", this); + m_ob=ob.m_ob; + m_file=ob.m_file; + m_line=ob.m_line; + m_from=ob.m_from; + m_to=ob.m_to; + m_erased=ob.m_erased; + return *this; } -#if 0 -ePyObject::ePyObject(void *ptr): m_object(ptr) +ePyObject::operator PyObject*() { - Py_XINCREF((PyObject*)ptr); + if (m_ob) + { + if (!m_erased && m_ob->ob_refcnt > 0) + return m_ob; + eDebug("invalid access PyObject %s with refcount <= 0 %d", + m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt); + if (m_file) + eDebug("last modified in file %s line %d from %d to %d", + m_file, m_line, m_from, m_to); + bsodFatal(); + } + return 0; } -ePyObject::ePyObject(ePyObject &p) +void ePyObject::incref(const char *file, int line) { - m_object = p.m_object; - Py_XINCREF((PyObject*)m_object); + if (!m_ob) + { + eDebug("invalid incref python object with null pointer %s %d!!!", file, line); + if (m_file) + eDebug("last modified in file %s line %d from %d to %d", + m_file, m_line, m_from, m_to); + bsodFatal(); + } + if (m_erased || m_ob->ob_refcnt <= 0) + { + eDebug("invalid incref %s python object with refcounting value %d in file %s line %d!!!", + m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt, file, line); + if (m_file) + eDebug("last modified in file %s line %d from %d to %d", + m_file, m_line, m_from, m_to); + bsodFatal(); + } + if (m_ob->ob_refcnt == 0x7FFFFFFF) + { + eDebug("invalid incref %s python object with refcounting value %d (MAX_INT!!!) in file %s line %d!!!", + m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt, file, line); + if (m_file) + eDebug("last modified in file %s line %d from %d to %d", + m_file, m_line, m_from, m_to); + bsodFatal(); + } + m_file = file; + m_line = line; + m_from = m_ob->ob_refcnt; + m_to = m_from+1; + Py_INCREF(m_ob); } -ePyObject::ePyObject(): m_object(0) +void ePyObject::decref(const char *file, int line) { + if (!m_ob) + { + eDebug("invalid decref python object with null pointer %s %d!!!", file, line); + if (m_file) + eDebug("last modified in file %s line %d from %d to %d", + m_file, m_line, m_from, m_to); + bsodFatal(); + } + if (m_erased || m_ob->ob_refcnt <= 0) + { + eDebug("invalid decref %s python object with refcounting value %d in file %s line %d!!!", + m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt, file, line); + if (m_file) + eDebug("last modified in file %s line %d from %d to %d", + m_file, m_line, m_from, m_to); + bsodFatal(); + } + m_file = file; + m_line = line; + m_from = m_ob->ob_refcnt; + m_to = m_from-1; + m_erased = !m_to; + Py_DECREF(m_ob); } +#endif // PYTHON_REFCOUNT_DEBUG -ePyObject::~ePyObject() -{ - Py_XDECREF((PyObject*)m_object); -} +#define SKIP_PART1 +#include +#undef SKIP_PART1 + +DEFINE_REF(TestObj); -ePyObject &ePyObject::operator=(ePyObject &p) +TestObj::TestObj() { - Py_XDECREF((PyObject*)m_object); - m_object = p.m_object; - Py_XINCREF((PyObject*)m_object); - return *this; + eDebug("create %p", this); } -ePyObject &ePyObject::operator=(void *object) +TestObj::~TestObj() { - Py_XDECREF((PyObject*)m_object); - m_object = object; - Py_XINCREF((PyObject*)m_object); - return *this; + eDebug("destroy %p", this); } -#endif ePython::ePython() { @@ -76,13 +144,13 @@ ePython::~ePython() int ePython::execute(const std::string &pythonfile, const std::string &funcname) { - PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue; + ePyObject pName, pModule, pDict, pFunc, pArgs, pValue; pName = PyString_FromString(pythonfile.c_str()); pModule = PyImport_Import(pName); Py_DECREF(pName); - if (pModule != NULL) + if (pModule) { pDict = PyModule_GetDict(pModule); @@ -94,7 +162,7 @@ int ePython::execute(const std::string &pythonfile, const std::string &funcname) // implement arguments.. pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); - if (pValue != NULL) + if (pValue) { printf("Result of call: %ld\n", PyInt_AsLong(pValue)); Py_DECREF(pValue); @@ -114,14 +182,14 @@ int ePython::execute(const std::string &pythonfile, const std::string &funcname) return 0; } -int ePython::call(PyObject *pFunc, PyObject *pArgs) +int ePython::call(ePyObject pFunc, ePyObject pArgs) { int res = -1; - PyObject *pValue; + ePyObject pValue; if (pFunc && PyCallable_Check(pFunc)) { pValue = PyObject_CallObject(pFunc, pArgs); - if (pValue != NULL) + if (pValue) { if (PyInt_Check(pValue)) res = PyInt_AsLong(pValue); @@ -137,26 +205,22 @@ int ePython::call(PyObject *pFunc, PyObject *pArgs) return res; } -PyObject *ePython::resolve(const std::string &pythonfile, const std::string &funcname) +ePyObject ePython::resolve(const std::string &pythonfile, const std::string &funcname) { - PyObject *pName, *pModule, *pDict, *pFunc; + ePyObject pName, pModule, pDict, pFunc; pName = PyString_FromString(pythonfile.c_str()); pModule = PyImport_Import(pName); Py_DECREF(pName); - if (pModule != NULL) + if (pModule) { pDict = PyModule_GetDict(pModule); pFunc = PyDict_GetItemString(pDict, funcname.c_str()); Py_XINCREF(pFunc); Py_DECREF(pModule); - return pFunc; - } else - { - if (PyErr_Occurred()) - PyErr_Print(); - return 0; - } + } else if (PyErr_Occurred()) + PyErr_Print(); + return pFunc; } diff --git a/lib/python/python.h b/lib/python/python.h index 46e1a03d..bcea49c5 100644 --- a/lib/python/python.h +++ b/lib/python/python.h @@ -1,14 +1,144 @@ -#ifndef __lib_python_python_h -#define __lib_python_python_h +#ifndef __lib_python_python_class_h + +#ifndef SKIP_PART2 + #define __lib_python_python_class_h +#endif #include #include +#include -typedef struct _object PyObject; +#define PYTHON_REFCOUNT_DEBUG -// useable for debugging python refcounting +#if !defined(SKIP_PART1) && !defined(SWIG) +class ePyObject +{ + PyObject *m_ob; +#ifdef PYTHON_REFCOUNT_DEBUG + const char *m_file; + int m_line, m_from, m_to; + bool m_erased; +#endif +public: + inline ePyObject(); + inline ePyObject(const ePyObject &ob); + inline ePyObject(PyObject *ob); + inline ePyObject(PyDictObject *ob); + inline ePyObject(PyTupleObject *ob); + inline ePyObject(PyListObject *ob); + inline ePyObject(PyStringObject *ob); + operator bool() { return !!m_ob; } + ePyObject &operator=(const ePyObject &); + ePyObject &operator=(PyObject *); + ePyObject &operator=(PyDictObject *ob) { return operator=((PyObject*)ob); } + ePyObject &operator=(PyTupleObject *ob) { return operator=((PyObject*)ob); } + ePyObject &operator=(PyListObject *ob) { return operator=((PyObject*)ob); } + ePyObject &operator=(PyStringObject *ob) { return operator=((PyObject*)ob); } + operator PyObject*(); + operator PyTupleObject*() { return (PyTupleObject*)operator PyObject*(); } + operator PyListObject*() { return (PyListObject*)operator PyObject*(); } + operator PyStringObject*() { return (PyStringObject*)operator PyObject*(); } + operator PyDictObject*() { return (PyDictObject*)operator PyObject*(); } + PyObject *operator->() { return operator PyObject*(); } +#ifdef PYTHON_REFCOUNT_DEBUG + void incref(const char *file, int line); + void decref(const char *file, int line); +#else + void incref(); + void decref(); +#endif +}; -extern PyObject *New_TestObj(); +inline ePyObject::ePyObject() + :m_ob(0) +#ifdef PYTHON_REFCOUNT_DEBUG + ,m_file(0), m_line(0), m_from(0), m_to(0), m_erased(false) +#endif +{ +} + +inline ePyObject::ePyObject(const ePyObject &ob) + :m_ob(ob.m_ob) +#ifdef PYTHON_REFCOUNT_DEBUG + ,m_file(ob.m_file), m_line(ob.m_line) + ,m_from(ob.m_from), m_to(ob.m_to), m_erased(ob.m_erased) +#endif +{ +} + +inline ePyObject::ePyObject(PyObject *ob) + :m_ob(ob) +#ifdef PYTHON_REFCOUNT_DEBUG + ,m_file(0), m_line(0), m_from(0), m_to(0), m_erased(false) +#endif +{ +} + +inline ePyObject::ePyObject(PyDictObject *ob) + :m_ob((PyObject*)ob) +#ifdef PYTHON_REFCOUNT_DEBUG + ,m_file(0), m_line(0), m_from(0), m_to(0), m_erased(false) +#endif +{ +} + +inline ePyObject::ePyObject(PyTupleObject *ob) + :m_ob((PyObject*)ob) +#ifdef PYTHON_REFCOUNT_DEBUG + ,m_file(0), m_line(0), m_from(0), m_to(0), m_erased(false) +#endif +{ +} + +inline ePyObject::ePyObject(PyListObject *ob) + :m_ob((PyObject*)ob) +#ifdef PYTHON_REFCOUNT_DEBUG + ,m_file(0), m_line(0), m_from(0), m_to(0), m_erased(false) +#endif +{ +} + +inline ePyObject::ePyObject(PyStringObject *ob) + :m_ob((PyObject*)ob) +#ifdef PYTHON_REFCOUNT_DEBUG + ,m_file(0), m_line(0), m_from(0), m_to(0), m_erased(false) +#endif +{ +} + +#ifndef PYTHON_REFCOUNT_DEBUG +inline ePyObject &ePyObject::operator=(PyObject *ob) +{ + m_ob=ob; + return *this; +} + +inline ePyObject &ePyObject::operator=(const ePyObject &ob) +{ + m_ob=ob.m_ob; + return *this; +} + +inline ePyObject::operator PyObject*() +{ + return m_ob; +} + +inline void ePyObject::incref() +{ + Py_INCREF(m_ob); +} + +inline void ePyObject::decref() +{ + Py_DECREF(m_ob); +} + +#endif // ! PYTHON_REFCOUNT_DEBUG + +#endif // !SWIG && !SKIP_PART1 + +#ifndef SKIP_PART2 class TestObj { @@ -19,19 +149,76 @@ public: }; TEMPLATE_TYPEDEF(ePtr, TestObjPtr); +extern PyObject *New_TestObj(); + #ifndef SWIG -/* class ePyObject + +#ifdef PYTHON_REFCOUNT_DEBUG +inline void Impl_Py_DECREF(const char* file, int line, const ePyObject &obj) { - void *m_object; -public: - ePyObject(void *ptr); - ePyObject(ePyObject &p); - ePyObject(); - ePyObject &operator=(ePyObject &p); - ePyObject &operator=(void *p); - ~ePyObject(); - void *get() { return m_object; } -}; */ + ((ePyObject*)(&obj))->decref(file, line); +} + +inline void Impl_Py_INCREF(const char* file, int line, const ePyObject &obj) +{ + ((ePyObject*)(&obj))->incref(file, line); +} + +inline void Impl_Py_XDECREF(const char* file, int line, const ePyObject &obj) +{ + if (obj) + ((ePyObject*)(&obj))->decref(file, line); +} + +inline void Impl_Py_XINCREF(const char* file, int line, const ePyObject &obj) +{ + if (obj) + ((ePyObject*)(&obj))->incref(file, line); +} +#else +inline void Impl_Py_DECREF(const ePyObject &obj) +{ + ((ePyObject*)(&obj))->decref(); +} + +inline void Impl_Py_INCREF(const ePyObject &obj) +{ + ((ePyObject*)(&obj))->incref(); +} + +inline void Impl_Py_XDECREF(const ePyObject &obj) +{ + if (obj) + ((ePyObject*)(&obj))->decref(); +} + +inline void Impl_Py_XINCREF(const ePyObject &obj) +{ + if (obj) + ((ePyObject*)(&obj))->incref(); +} +#endif + +inline void Impl_DECREF(PyObject *ob) +{ + Py_DECREF(ob); +} +#define Org_Py_DECREF(obj) Impl_DECREF(obj) +#undef Py_DECREF +#undef Py_XDECREF +#undef Py_INCREF +#undef Py_XINCREF +#ifdef PYTHON_REFCOUNT_DEBUG +#define Py_DECREF(obj) Impl_Py_DECREF(__FILE__, __LINE__, obj) +#define Py_XDECREF(obj) Impl_Py_XDECREF(__FILE__, __LINE__, obj) +#define Py_INCREF(obj) Impl_Py_INCREF(__FILE__, __LINE__, obj) +#define Py_XINCREF(obj) Impl_Py_XINCREF(__FILE__, __LINE__, obj) +#else +#define Py_DECREF(obj) Impl_Py_DECREF(obj) +#define Py_XDECREF(obj) Impl_Py_XDECREF(obj) +#define Py_INCREF(obj) Impl_Py_INCREF(obj) +#define Py_XINCREF(obj) Impl_Py_XINCREF(obj) +#endif class ePython { @@ -39,10 +226,12 @@ public: ePython(); ~ePython(); int execute(const std::string &pythonfile, const std::string &funcname); - static int call(PyObject *pFunc, PyObject *args); - static PyObject *resolve(const std::string &pythonfile, const std::string &funcname); + static int call(ePyObject pFunc, ePyObject args); + static ePyObject resolve(const std::string &pythonfile, const std::string &funcname); private: }; + #endif // SWIG +#endif // SKIP_PART2 -#endif +#endif // __lib_python_python_class_h diff --git a/lib/python/swig.h b/lib/python/swig.h index c9be9695..c094b646 100644 --- a/lib/python/swig.h +++ b/lib/python/swig.h @@ -18,11 +18,13 @@ typedef x y; \ #define SWIG_OUTPUT OUTPUT #define SWIG_NAMED_OUTPUT(x) OUTPUT #define SWIG_VOID(x) void +#define SWIG_PYOBJECT(x) PyObject* #else #define SWIG_INPUT #define SWIG_OUTPUT #define SWIG_NAMED_OUTPUT(x) x #define SWIG_VOID(x) x +#define SWIG_PYOBJECT(x) x #endif #endif diff --git a/lib/service/iservice.h b/lib/service/iservice.h index 1dd419c1..25935b2f 100644 --- a/lib/service/iservice.h +++ b/lib/service/iservice.h @@ -460,7 +460,7 @@ class iCueSheet: public iObject public: /* returns a list of (pts, what)-tuples */ virtual PyObject *getCutList() = 0; - virtual void setCutList(PyObject *list) = 0; + virtual void setCutList(SWIG_PYOBJECT(ePyObject) list) = 0; virtual void setCutListEnable(int enable) = 0; enum { cutIn = 0, cutOut = 1, cutMark = 2 }; }; @@ -473,7 +473,7 @@ class PyList; class iSubtitleOutput: public iObject { public: - virtual RESULT enableSubtitles(eWidget *parent, PyObject *entry)=0; + virtual RESULT enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) entry)=0; virtual RESULT disableSubtitles(eWidget *parent)=0; virtual PyObject *getSubtitleList()=0; virtual PyObject *getCachedSubtitle()=0; @@ -575,7 +575,12 @@ public: TEMPLATE_TYPEDEF(ePtr, iRecordableServicePtr); -PyObject *PyFrom(ePtr&); // implemented in servicedvbrecord.cpp +extern PyObject *New_iRecordableServicePtr(const ePtr &ref); // defined in enigma_python.i + +inline PyObject *PyFrom(ePtr &c) +{ + return New_iRecordableServicePtr(c); +} // TEMPLATE_TYPEDEF(std::list, eServiceReferenceList); diff --git a/lib/service/service.cpp b/lib/service/service.cpp index 8ac7ebd4..181ec22f 100644 --- a/lib/service/service.cpp +++ b/lib/service/service.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include eServiceReference::eServiceReference(const std::string &string) { diff --git a/lib/service/servicedvb.cpp b/lib/service/servicedvb.cpp index 71c2ae60..627ccec0 100644 --- a/lib/service/servicedvb.cpp +++ b/lib/service/servicedvb.cpp @@ -406,7 +406,7 @@ RESULT eDVBServiceList::getContent(std::list &list, bool sort // unknown format string chars are returned as python None values ! PyObject *eDVBServiceList::getContent(const char* format, bool sorted) { - PyObject *ret=0; + ePyObject ret; std::list tmplist; int retcount=1; @@ -428,10 +428,10 @@ PyObject *eDVBServiceList::getContent(const char* format, bool sorted) for (int cnt=0; cnt < services; ++cnt) { eServiceReference &ref=*it++; - PyObject *tuple = retcount > 1 ? PyTuple_New(retcount) : 0; + ePyObject tuple = retcount > 1 ? PyTuple_New(retcount) : 0; for (int i=0; i < retcount; ++i) { - PyObject *tmp=0; + ePyObject tmp; switch(format[i]) { case 'R': // service reference (swig)object @@ -478,7 +478,7 @@ PyObject *eDVBServiceList::getContent(const char* format, bool sorted) PyList_SET_ITEM(ret, cnt, tuple); } } - return ret ? ret : PyList_New(0); + return ret ? (PyObject*)ret : (PyObject*)PyList_New(0); } RESULT eDVBServiceList::getNext(eServiceReference &ref) @@ -1383,7 +1383,7 @@ int eDVBServiceBase::getFrontendInfo(int w) PyObject *eDVBServiceBase::getFrontendData(bool original) { - PyObject *ret=0; + ePyObject ret; eUsePtr channel; if(!m_service_handler.getChannel(channel)) @@ -1401,8 +1401,8 @@ PyObject *eDVBServiceBase::getFrontendData(bool original) eDVBFrontendParametersSatellite osat; if (!feparm->getDVBS(osat)) { - void PutToDict(PyObject *, const char*, long); - void PutToDict(PyObject *, const char*, const char*); + void PutToDict(ePyObject &, const char*, long); + void PutToDict(ePyObject &, const char*, const char*); PutToDict(ret, "orbital_position", osat.orbital_position); const char *tmp = "UNKNOWN"; switch(osat.polarisation) @@ -1526,11 +1526,11 @@ RESULT eDVBServicePlay::activateTimeshift() PyObject *eDVBServicePlay::getCutList() { - PyObject *list = PyList_New(0); + ePyObject list = PyList_New(0); for (std::multiset::iterator i(m_cue_entries.begin()); i != m_cue_entries.end(); ++i) { - PyObject *tuple = PyTuple_New(2); + ePyObject tuple = PyTuple_New(2); PyTuple_SetItem(tuple, 0, PyLong_FromLongLong(i->where)); PyTuple_SetItem(tuple, 1, PyInt_FromLong(i->what)); PyList_Append(list, tuple); @@ -1540,7 +1540,7 @@ PyObject *eDVBServicePlay::getCutList() return list; } -void eDVBServicePlay::setCutList(PyObject *list) +void eDVBServicePlay::setCutList(ePyObject list) { if (!PyList_Check(list)) return; @@ -1551,7 +1551,7 @@ void eDVBServicePlay::setCutList(PyObject *list) for (i=0; icommitSpans(); } -RESULT eDVBServicePlay::enableSubtitles(eWidget *parent, PyObject *tuple) +RESULT eDVBServicePlay::enableSubtitles(eWidget *parent, ePyObject tuple) { if (m_subtitle_widget) disableSubtitles(parent); - PyObject *entry = 0; + ePyObject entry; int tuplesize = PyTuple_Size(tuple); int type = 0; @@ -2109,7 +2109,7 @@ PyObject *eDVBServicePlay::getCachedSubtitle() { unsigned int data = (unsigned int)tmp; int pid = (data&0xFFFF0000)>>16; - PyObject *tuple = PyTuple_New(4); + ePyObject tuple = PyTuple_New(4); eDVBServicePMTHandler::program program; eDVBServicePMTHandler &h = m_timeshift_active ? m_service_handler_timeshift : m_service_handler; if (!h.getProgramInfo(program)) @@ -2137,7 +2137,7 @@ PyObject *eDVBServicePlay::getSubtitleList() return Py_None; } - PyObject *l = PyList_New(0); + ePyObject l = PyList_New(0); std::set added_ttx_pages; std::set &subs = @@ -2161,7 +2161,7 @@ PyObject *eDVBServicePlay::getSubtitleList() int hash = magazine_number << 8 | page_number; if (added_ttx_pages.find(hash) == added_ttx_pages.end()) { - PyObject *tuple = PyTuple_New(5); + ePyObject tuple = PyTuple_New(5); PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(1)); PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(it->pid)); PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(page_number)); @@ -2176,7 +2176,7 @@ PyObject *eDVBServicePlay::getSubtitleList() case 0x10 ... 0x13: case 0x20 ... 0x23: // dvb subtitles { - PyObject *tuple = PyTuple_New(5); + ePyObject tuple = PyTuple_New(5); PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(0)); PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(it->pid)); PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(it->composition_page_id)); @@ -2198,7 +2198,7 @@ PyObject *eDVBServicePlay::getSubtitleList() int hash = magazine_number << 8 | page_number; if (added_ttx_pages.find(hash) == added_ttx_pages.end()) { - PyObject *tuple = PyTuple_New(5); + ePyObject tuple = PyTuple_New(5); PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(1)); PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(it->pid)); PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(page_number)); diff --git a/lib/service/servicedvb.h b/lib/service/servicedvb.h index 27f48b57..979a9cab 100644 --- a/lib/service/servicedvb.h +++ b/lib/service/servicedvb.h @@ -156,11 +156,11 @@ public: // iCueSheet PyObject *getCutList(); - void setCutList(PyObject *); + void setCutList(SWIG_PYOBJECT(ePyObject)); void setCutListEnable(int enable); // iSubtitleOutput - RESULT enableSubtitles(eWidget *parent, PyObject *entry); + RESULT enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) entry); RESULT disableSubtitles(eWidget *parent); PyObject *getSubtitleList(); PyObject *getCachedSubtitle(); diff --git a/lib/service/servicedvbrecord.cpp b/lib/service/servicedvbrecord.cpp index 6164ca17..d3c3704b 100644 --- a/lib/service/servicedvbrecord.cpp +++ b/lib/service/servicedvbrecord.cpp @@ -5,13 +5,6 @@ DEFINE_REF(eDVBServiceRecord); -extern PyObject *New_iRecordableServicePtr(const ePtr &ref); // defined in enigma_python.i - -PyObject *PyFrom(ePtr &c) -{ - return New_iRecordableServicePtr(c); -} - eDVBServiceRecord::eDVBServiceRecord(const eServiceReferenceDVB &ref): m_ref(ref) { CONNECT(m_service_handler.serviceEvent, eDVBServiceRecord::serviceEvent); diff --git a/lib/service/servicefs.cpp b/lib/service/servicefs.cpp index 16948854..b0023212 100644 --- a/lib/service/servicefs.cpp +++ b/lib/service/servicefs.cpp @@ -186,7 +186,7 @@ RESULT eServiceFS::getContent(std::list &list, bool sorted) // unknown format string chars are returned as python None values ! PyObject *eServiceFS::getContent(const char* format, bool sorted) { - PyObject *ret=0; + ePyObject ret; std::list tmplist; int retcount=1; @@ -208,10 +208,10 @@ PyObject *eServiceFS::getContent(const char* format, bool sorted) for (int cnt=0; cnt < services; ++cnt) { eServiceReference &ref=*it++; - PyObject *tuple = retcount > 1 ? PyTuple_New(retcount) : 0; + ePyObject tuple = retcount > 1 ? PyTuple_New(retcount) : 0; for (int i=0; i < retcount; ++i) { - PyObject *tmp=0; + ePyObject tmp; switch(format[i]) { case 'R': // service reference (swig)object @@ -258,7 +258,7 @@ PyObject *eServiceFS::getContent(const char* format, bool sorted) PyList_SET_ITEM(ret, cnt, tuple); } } - return ret ? ret : PyList_New(0); + return ret ? (PyObject*)ret : (PyObject*)PyList_New(0); } RESULT eServiceFS::getNext(eServiceReference &ptr) diff --git a/lib/service/servicefs.h b/lib/service/servicefs.h index abd10f37..479718d8 100644 --- a/lib/service/servicefs.h +++ b/lib/service/servicefs.h @@ -35,7 +35,7 @@ public: virtual ~eServiceFS(); RESULT getContent(std::list &list, bool sorted=false); - RESULT getContent(PyObject *list, bool sorted=false); + RESULT getContent(SWIG_PYOBJECT(ePyObject) list, bool sorted=false); PyObject *getContent(const char *format, bool sorted=false); RESULT getNext(eServiceReference &ptr); int compareLessEqual(const eServiceReference &, const eServiceReference &); diff --git a/main/bsod.cpp b/main/bsod.cpp index 938ddd2b..b646394e 100644 --- a/main/bsod.cpp +++ b/main/bsod.cpp @@ -172,7 +172,7 @@ void handleFatalSignal(int signum, siginfo_t *si, void *ctx) ucontext_t *uc = (ucontext_t*)ctx; eDebug("KILLED BY signal %d", signum); #ifndef NO_OOPS_SUPPORT - oops(uc->uc_mcontext, signum == SIGSEGV); + oops(uc->uc_mcontext, signum == SIGSEGV || signum == SIGABRT); #endif eDebug("-------"); bsodFatal(); @@ -191,6 +191,7 @@ void bsodCatchSignals() sigaction(SIGSEGV, &act, 0); sigaction(SIGILL, &act, 0); sigaction(SIGBUS, &act, 0); + sigaction(SIGABRT, &act, 0); } void bsodLogInit()