From 63bae75ab8aaaee8bca8175918d376bb729bf65d Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Tue, 18 Nov 2008 15:17:52 +0100 Subject: don't hold debug lock while doing bsodFatal --- lib/base/eerror.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/base') diff --git a/lib/base/eerror.cpp b/lib/base/eerror.cpp index 1e4d348f..7ebac213 100644 --- a/lib/base/eerror.cpp +++ b/lib/base/eerror.cpp @@ -86,9 +86,11 @@ void eFatal(const char* fmt, ...) va_start(ap, fmt); vsnprintf(buf, 1024, fmt, ap); va_end(ap); - singleLock s(DebugLock); - logOutput(lvlFatal, "FATAL: " + std::string(buf) + "\n"); - fprintf(stderr, "FATAL: %s\n",buf ); + { + singleLock s(DebugLock); + logOutput(lvlFatal, "FATAL: " + std::string(buf) + "\n"); + fprintf(stderr, "FATAL: %s\n",buf ); + } bsodFatal(); } -- cgit v1.2.3 From d924772eeced2429c007e51ce6dcb50dadec2836 Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Tue, 18 Nov 2008 15:47:32 +0100 Subject: don't try to look for python files when handling a C++ crash --- lib/base/eerror.cpp | 4 ++-- lib/python/python.cpp | 16 ++++++++-------- main/bsod.cpp | 51 ++++++++++++++++++++++++++++----------------------- main/bsod.h | 2 +- main/enigma.cpp | 2 +- 5 files changed, 40 insertions(+), 35 deletions(-) (limited to 'lib/base') diff --git a/lib/base/eerror.cpp b/lib/base/eerror.cpp index 7ebac213..4c4d6551 100644 --- a/lib/base/eerror.cpp +++ b/lib/base/eerror.cpp @@ -77,7 +77,7 @@ int logOutputConsole=1; static pthread_mutex_t DebugLock = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP; -extern void bsodFatal(); +extern void bsodFatal(const char *component); void eFatal(const char* fmt, ...) { @@ -91,7 +91,7 @@ void eFatal(const char* fmt, ...) logOutput(lvlFatal, "FATAL: " + std::string(buf) + "\n"); fprintf(stderr, "FATAL: %s\n",buf ); } - bsodFatal(); + bsodFatal("enigma2"); } #ifdef DEBUG diff --git a/lib/python/python.cpp b/lib/python/python.cpp index 50b66103..c5faeed4 100644 --- a/lib/python/python.cpp +++ b/lib/python/python.cpp @@ -5,7 +5,7 @@ extern "C" void init_enigma(); extern "C" void eBaseInit(void); extern "C" void eConsoleInit(void); -extern void bsodFatal(); +extern void bsodFatal(const char *component); #define SKIP_PART2 #include @@ -44,7 +44,7 @@ ePyObject::operator PyObject*() if (m_file) eDebug("last modified in file %s line %d from %d to %d", m_file, m_line, m_from, m_to); - bsodFatal(); + bsodFatal("enigma2, refcnt"); } return 0; } @@ -57,7 +57,7 @@ void ePyObject::incref(const char *file, int 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(); + bsodFatal("enigma2, refcnt"); } if (m_erased || m_ob->ob_refcnt <= 0) { @@ -66,7 +66,7 @@ void ePyObject::incref(const char *file, int 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(); + bsodFatal("enigma2, refcnt"); } if (m_ob->ob_refcnt == 0x7FFFFFFF) { @@ -75,7 +75,7 @@ void ePyObject::incref(const char *file, int 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(); + bsodFatal("enigma2, refcnt"); } m_file = file; m_line = line; @@ -92,7 +92,7 @@ void ePyObject::decref(const char *file, int 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(); + bsodFatal("enigma2, refcnt"); } if (m_erased || m_ob->ob_refcnt <= 0) { @@ -101,7 +101,7 @@ void ePyObject::decref(const char *file, int 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(); + bsodFatal("enigma2, refcnt"); } m_file = file; m_line = line; @@ -207,7 +207,7 @@ int ePython::call(ePyObject pFunc, ePyObject pArgs) eDebug("(PyObject_CallObject(%s,%s) failed)", PyString_AS_STRING(FuncStr), PyString_AS_STRING(ArgStr)); Py_DECREF(FuncStr); Py_DECREF(ArgStr); - bsodFatal(); + bsodFatal(0); } } return res; diff --git a/main/bsod.cpp b/main/bsod.cpp index 173a2cce..583107d7 100644 --- a/main/bsod.cpp +++ b/main/bsod.cpp @@ -67,7 +67,7 @@ extern std::string getLogBuffer(); #define INFOFILE "/maintainer.info" -void bsodFatal() +void bsodFatal(const char *component) { char logfile[128]; sprintf(logfile, "/media/hdd/enigma2_crash_%u.log", (unsigned int)time(0)); @@ -81,30 +81,35 @@ void bsodFatal() char crash_emailaddr[256] = CRASH_EMAILADDR; char crash_component[256] = "enigma2"; - while ((start = lines.find("\n File \"", start)) != std::string::npos) + if (component) + snprintf(crash_component, 256, component); + else { - start += 9; - size_t end = lines.find("\"", start); - if (end == std::string::npos) - break; - end = lines.rfind("/", end); - if (end == std::string::npos) - break; - if (end - start >= (256 - strlen(INFOFILE))) - continue; - char filename[256]; - snprintf(filename, 256, "%s%s", lines.substr(start, end - start).c_str(), INFOFILE); - FILE *cf = fopen(filename, "r"); - if (cf) + while ((start = lines.find("\n File \"", start)) != std::string::npos) { - fgets(crash_emailaddr, sizeof crash_emailaddr, cf); - if (*crash_emailaddr && crash_emailaddr[strlen(crash_emailaddr)-1] == '\n') - crash_emailaddr[strlen(crash_emailaddr)-1] = 0; + start += 9; + size_t end = lines.find("\"", start); + if (end == std::string::npos) + break; + end = lines.rfind("/", end); + if (end == std::string::npos) + break; + if (end - start >= (256 - strlen(INFOFILE))) + continue; + char filename[256]; + snprintf(filename, 256, "%s%s", lines.substr(start, end - start).c_str(), INFOFILE); + FILE *cf = fopen(filename, "r"); + if (cf) + { + fgets(crash_emailaddr, sizeof crash_emailaddr, cf); + if (*crash_emailaddr && crash_emailaddr[strlen(crash_emailaddr)-1] == '\n') + crash_emailaddr[strlen(crash_emailaddr)-1] = 0; - fgets(crash_component, sizeof crash_component, cf); - if (*crash_component && crash_component[strlen(crash_component)-1] == '\n') - crash_component[strlen(crash_component)-1] = 0; - fclose(cf); + fgets(crash_component, sizeof crash_component, cf); + if (*crash_component && crash_component[strlen(crash_component)-1] == '\n') + crash_component[strlen(crash_component)-1] = 0; + fclose(cf); + } } } @@ -242,7 +247,7 @@ void handleFatalSignal(int signum, siginfo_t *si, void *ctx) oops(uc->uc_mcontext, signum == SIGSEGV || signum == SIGABRT); #endif eDebug("-------"); - bsodFatal(); + bsodFatal("enigma2, signal"); } void bsodCatchSignals() diff --git a/main/bsod.h b/main/bsod.h index aa8cfb74..4ee4c48b 100644 --- a/main/bsod.h +++ b/main/bsod.h @@ -3,6 +3,6 @@ void bsodLogInit(); void bsodCatchSignals(); -void bsodFatal(); +void bsodFatal(const char *component); #endif diff --git a/main/enigma.cpp b/main/enigma.cpp index 0893b035..98175c49 100644 --- a/main/enigma.cpp +++ b/main/enigma.cpp @@ -248,7 +248,7 @@ int main(int argc, char **argv) if (exit_code == 5) /* python crash */ { eDebug("(exit code 5)"); - bsodFatal(); + bsodFatal(0); } dsk.paint(); -- cgit v1.2.3 From ea644879586a9472041552d84dd7b7ebba29ec3e Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 18 Nov 2008 16:17:28 +0100 Subject: fix FATAL: ebase.cpp:129 ASSERTION notifiers.find(fd) == notifiers.end() FAILED! --- lib/base/ebase.cpp | 23 ++++++++++++++++++----- lib/base/ebase.h | 3 ++- 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'lib/base') diff --git a/lib/base/ebase.cpp b/lib/base/ebase.cpp index bd2ec589..f42b72b8 100644 --- a/lib/base/ebase.cpp +++ b/lib/base/ebase.cpp @@ -126,6 +126,18 @@ eMainloop::~eMainloop() void eMainloop::addSocketNotifier(eSocketNotifier *sn) { int fd = sn->getFD(); + std::map::iterator it(notifiers.find(fd)); + if (m_inActivate && m_inActivate->ref.count == 1) + { + /* when the current active SocketNotifier's refcount is one, + then no more external references are existing. + So it gets destroyed when the activate callback is finished (->AddRef() / ->Release() calls in processOneEvent). + But then the sn->stop() is called to late for the next Asserion. + Thus we call sn->stop() here (this implicitly calls eMainloop::removeSocketNotifier) and we don't get trouble + with the next Assertion. + */ + m_inActivate->stop(); + } ASSERT(notifiers.find(fd) == notifiers.end()); notifiers[fd]=sn; } @@ -243,14 +255,15 @@ int eMainloop::processOneEvent(unsigned int twisted_timeout, PyObject **res, ePy if (it != notifiers.end() && it->second->state == 1) // added and in poll { - eSocketNotifier *sn = it->second; - int req = sn->getRequested(); + m_inActivate = it->second; + int req = m_inActivate->getRequested(); if (pfd[i].revents & req) { - sn->AddRef(); - sn->activate(pfd[i].revents & req); - sn->Release(); + m_inActivate->AddRef(); + m_inActivate->activate(pfd[i].revents & req); + m_inActivate->Release(); } pfd[i].revents &= ~req; + m_inActivate = 0; } if (pfd[i].revents & (POLLERR|POLLHUP|POLLNVAL)) eDebug("poll: unhandled POLLERR/HUP/NVAL for fd %d(%d)", pfd[i].fd, pfd[i].revents); diff --git a/lib/base/ebase.h b/lib/base/ebase.h index 84845a95..524052bd 100644 --- a/lib/base/ebase.h +++ b/lib/base/ebase.h @@ -195,6 +195,7 @@ class eMainloop int processOneEvent(unsigned int user_timeout, PyObject **res=0, ePyObject additional=ePyObject()); int retval; int m_is_idle; + eSocketNotifier *m_inActivate; int m_interrupt_requested; timespec m_twisted_timer; // twisted timer @@ -209,7 +210,7 @@ public: #endif eMainloop() - :app_quit_now(0),loop_level(0),retval(0), m_is_idle(0), m_interrupt_requested(0) + :app_quit_now(0),loop_level(0),retval(0), m_is_idle(0), m_inActivate(0), m_interrupt_requested(0) { existing_loops.push_back(this); } -- cgit v1.2.3 From a8455f54b7c4eeb1ebf769e7194a089098ab4959 Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 18 Nov 2008 16:25:11 +0100 Subject: remove unneeded code --- lib/base/ebase.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/base') diff --git a/lib/base/ebase.cpp b/lib/base/ebase.cpp index f42b72b8..313732ab 100644 --- a/lib/base/ebase.cpp +++ b/lib/base/ebase.cpp @@ -126,7 +126,6 @@ eMainloop::~eMainloop() void eMainloop::addSocketNotifier(eSocketNotifier *sn) { int fd = sn->getFD(); - std::map::iterator it(notifiers.find(fd)); if (m_inActivate && m_inActivate->ref.count == 1) { /* when the current active SocketNotifier's refcount is one, -- cgit v1.2.3 From 371e23c22dcec461ee3fbc8c989859cd08717b3d Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 25 Nov 2008 00:34:29 +0100 Subject: fix some refcounting bugs --- lib/base/nconfig.cpp | 1 + lib/dvb/dvb.cpp | 6 ++++-- lib/dvb/epgcache.cpp | 2 +- lib/gui/elistboxcontent.cpp | 17 +++++++++++------ 4 files changed, 17 insertions(+), 9 deletions(-) (limited to 'lib/base') diff --git a/lib/base/nconfig.cpp b/lib/base/nconfig.cpp index 31b0a36f..106558ac 100644 --- a/lib/base/nconfig.cpp +++ b/lib/base/nconfig.cpp @@ -25,6 +25,7 @@ RESULT ePythonConfigQuery::getConfigValue(const char *key, std::string &value) if (PyString_Check(pRet)) { value.assign(PyString_AS_STRING(pRet)); + Py_DECREF(pRet); return 0; } Py_DECREF(pRet); diff --git a/lib/dvb/dvb.cpp b/lib/dvb/dvb.cpp index 7e9a39c6..eac4554d 100644 --- a/lib/dvb/dvb.cpp +++ b/lib/dvb/dvb.cpp @@ -1502,7 +1502,7 @@ RESULT eDVBChannel::setCIRouting(const eDVBCIRouting &routing) void eDVBChannel::SDTready(int result) { - ePyObject args = PyTuple_New(2); + ePyObject args = PyTuple_New(2), ret; bool ok=false; if (!result) { @@ -1521,7 +1521,9 @@ void eDVBChannel::SDTready(int result) Py_INCREF(Py_None); Py_INCREF(Py_None); } - PyObject_CallObject(m_tsid_onid_callback, args); + ret = PyObject_CallObject(m_tsid_onid_callback, args); + if (ret) + Py_DECREF(ret); Py_DECREF(args); Py_DECREF(m_tsid_onid_callback); m_tsid_onid_callback = ePyObject(); diff --git a/lib/dvb/epgcache.cpp b/lib/dvb/epgcache.cpp index 0bb6e25b..222cba32 100644 --- a/lib/dvb/epgcache.cpp +++ b/lib/dvb/epgcache.cpp @@ -1672,7 +1672,7 @@ int handleEvent(eServiceEvent *ptr, ePyObject dest_list, const char* argstring, { fillTuple(convertFuncArgs, argstring, argcount, service, ptr, nowTime, service_name); ePyObject result = PyObject_CallObject(convertFunc, convertFuncArgs); - if (result) + if (!result) { if (service_name) Py_DECREF(service_name); diff --git a/lib/gui/elistboxcontent.cpp b/lib/gui/elistboxcontent.cpp index beb12044..69f72a41 100644 --- a/lib/gui/elistboxcontent.cpp +++ b/lib/gui/elistboxcontent.cpp @@ -467,7 +467,8 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, /* type is borrowed */ } else eWarning("eListboxPythonConfigContent: second value of tuple is not a tuple."); - /* value is borrowed */ + if (value) + Py_DECREF(value); } if (selected && (!local_style || !local_style->m_selection)) @@ -622,7 +623,7 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c painter.clip(itemregion); clearRegion(painter, style, local_style, ePyObject(), ePyObject(), ePyObject(), ePyObject(), selected, itemregion, sel_clip); - ePyObject items; + ePyObject items, buildfunc_ret; if (m_list && cursorValid()) { @@ -638,7 +639,7 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c if (PyCallable_Check(m_buildFunc)) // when we have a buildFunc then call it { if (PyTuple_Check(items)) - items = PyObject_CallObject(m_buildFunc, items); + buildfunc_ret = items = PyObject_CallObject(m_buildFunc, items); else eDebug("items is no tuple"); } @@ -983,8 +984,8 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry); error_out: - if (m_buildFunc && PyCallable_Check(m_buildFunc) && items) - Py_DECREF(items); + if (buildfunc_ret) + Py_DECREF(buildfunc_ret); painter.clippop(); } @@ -1015,7 +1016,11 @@ int eListboxPythonMultiContent::currentCursorSelectable() { ePyObject ret = PyObject_CallObject(m_selectableFunc, args); if (ret) - return ret == Py_True; + { + bool retval = ret == Py_True; + Py_DECREF(ret); + return ret; + } eDebug("call m_selectableFunc failed!!! assume not callable"); } else -- cgit v1.2.3