From e7972737bc49bbf590dce3e219c9001634419168 Mon Sep 17 00:00:00 2001 From: randomdan Date: Tue, 25 Jan 2011 00:24:29 +0000 Subject: Fix Presenter's inheritance of CommonObjects Use smart pointers to stages, they are refcounted after all Have variables keep a handle to their row sources, fixes crash during stage destruction --- project2/cgi/cgiAppEngine.cpp | 6 ++---- project2/cgi/cgiAppEngine.h | 12 +++++++----- project2/presenter.h | 2 +- project2/rowSet.h | 1 + project2/variables.cpp | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 12a30d7..d1c1579 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -48,9 +48,7 @@ void CgiApplicationEngine::process() const { while (!doc && currentStage) { - Stage * prev = currentStage; currentStage = currentStage->run(); - delete prev; } if (!sessionID.is_nil()) { header->setCookie(cgicc::HTTPCookie(SESSIONID, sessionID.str(), "Session ID", @@ -82,7 +80,7 @@ CgiApplicationEngine::PresentStage::~PresentStage() { } -CgiApplicationEngine::Stage * +CgiApplicationEngine::StagePtr CgiApplicationEngine::PresentStage::run() { BOOST_FOREACH(OrderedParamCheckers::value_type pc, parameterChecks) { @@ -150,7 +148,7 @@ CgiApplicationEngine::RequestStage::RequestStage(const CgiApplicationEngine * e, CgiApplicationEngine::RequestStage::~RequestStage() { } -CgiApplicationEngine::Stage * +CgiApplicationEngine::StagePtr CgiApplicationEngine::RequestStage::run() { BOOST_FOREACH(OrderedParamCheckers::value_type pc, parameterChecks) { diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h index abd4b9e..532b74d 100644 --- a/project2/cgi/cgiAppEngine.h +++ b/project2/cgi/cgiAppEngine.h @@ -37,11 +37,13 @@ class CgiApplicationEngine : public ApplicationEngine { mutable cgicc::HTTPContentHeader * header; private: mutable boost::shared_ptr doc; - class Stage : public CommonObjects { + class Stage; + typedef boost::intrusive_ptr StagePtr; + class Stage : public virtual CommonObjects { public: Stage(const CgiApplicationEngine *); virtual ~Stage() = 0; - virtual Stage * run() = 0; + virtual StagePtr run() = 0; protected: const CgiApplicationEngine * appEngine; }; @@ -49,7 +51,7 @@ class CgiApplicationEngine : public ApplicationEngine { public: RequestStage(const CgiApplicationEngine *, const std::string & id); virtual ~RequestStage(); - virtual Stage * run(); + virtual StagePtr run(); std::string present; protected: OrderedParamCheckers parameterChecks; @@ -60,9 +62,9 @@ class CgiApplicationEngine : public ApplicationEngine { PresentStage(const CgiApplicationEngine *, const std::string & id); PresentStage(const CgiApplicationEngine *, const std::string & group, const std::string & id); virtual ~PresentStage(); - virtual Stage * run(); + virtual StagePtr run(); }; - mutable Stage * currentStage; + mutable StagePtr currentStage; mutable UUID sessionID; }; diff --git a/project2/presenter.h b/project2/presenter.h index b0f3262..13468f3 100644 --- a/project2/presenter.h +++ b/project2/presenter.h @@ -9,7 +9,7 @@ #include "paramChecker.h" #include "commonObjects.h" -class Presenter : public CommonObjects, public virtual IntrusivePtrBase { +class Presenter : public virtual CommonObjects, public virtual IntrusivePtrBase { public: Presenter(const std::string & group, const std::string & file); virtual ~Presenter() = 0; diff --git a/project2/rowSet.h b/project2/rowSet.h index f25f937..d85f77b 100644 --- a/project2/rowSet.h +++ b/project2/rowSet.h @@ -14,6 +14,7 @@ class RowProcessor; class RowSet; typedef boost::intrusive_ptr RowSetPtr; +typedef boost::intrusive_ptr ConstRowSetPtr; typedef std::map RowSets; class RowSet : public virtual SourceObject { diff --git a/project2/variables.cpp b/project2/variables.cpp index 2267e8b..5c4508f 100644 --- a/project2/variables.cpp +++ b/project2/variables.cpp @@ -183,11 +183,11 @@ class VariableParent : public VariableImplDyn, public RowUser { boost::bind((gCV)&RowSet::getCurrentValue, _2, name)); } } - mutable const RowSet * row; + mutable ConstRowSetPtr row; const size_t depth; const bool attr; const RowUser * dep; - mutable boost::function2 getValue; + mutable boost::function2 getValue; }; class VariableParse : public VariableImplDyn, public RowUser { -- cgit v1.2.3