From e942a15dd8284d6c756bf752d5d56d0f818f70f1 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 23 Mar 2004 14:39:41 +0000 Subject: [PATCH] Store the forked calls in boost::shared_ptr rather than a raw pointer. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8518 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 6 ++++++ src/ispell.C | 8 +++++--- src/lyx_cb.C | 10 +++++++--- src/support/ChangeLog | 8 ++++++++ src/support/forkedcall.h | 8 +++----- src/support/forkedcontr.C | 32 ++++++++++++++------------------ src/support/forkedcontr.h | 5 +++-- 7 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8b4c3ecb15..c480db6f73 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2004-03-23 Angus Leeming + + * ispell.C (LaunchIspell): + * lyx_cb.C (AutoSaveBuffer): change the signature of clone to return + a boost::shred_ptr rather than a std::auto_ptr. + 2004-03-22 Jean-Marc Lasgouttes * lyxfunc.C (getStatus): handle read-only buffers correctly; diff --git a/src/ispell.C b/src/ispell.C index 8cfdddf97f..08de736d83 100644 --- a/src/ispell.C +++ b/src/ispell.C @@ -30,13 +30,14 @@ #endif #include +using boost::shared_ptr; + #ifndef CXX_GLOBAL_CSTD using std::strcpy; using std::strlen; using std::strpbrk; #endif -using std::auto_ptr; using std::endl; using std::max; using std::string; @@ -45,14 +46,15 @@ using std::string; namespace { class LaunchIspell : public lyx::support::ForkedProcess { + typedef lyx::support::ForkedProcess ForkedProcess; public: /// LaunchIspell(BufferParams const & p, string const & l, int * in, int * out, int * err) : params(p), lang(l), pipein(in), pipeout(out), pipeerr(err) {} /// - virtual auto_ptr clone() const { - return auto_ptr(new LaunchIspell(*this)); + virtual shared_ptr clone() const { + return shared_ptr(new LaunchIspell(*this)); } /// int start(); diff --git a/src/lyx_cb.C b/src/lyx_cb.C index bdfe5e83f8..9009677032 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -44,6 +44,8 @@ #include "support/path_defines.h" #include "support/systemcall.h" +#include + #include #include @@ -71,7 +73,8 @@ using lyx::support::user_lyxdir; namespace os = lyx::support::os; -using std::auto_ptr; +using boost::shared_ptr; + using std::back_inserter; using std::copy; using std::endl; @@ -221,8 +224,9 @@ public: AutoSaveBuffer(BufferView & bv, string const & fname) : bv_(bv), fname_(fname) {} /// - virtual auto_ptr clone() const { - return auto_ptr(new AutoSaveBuffer(*this)); + virtual shared_ptr clone() const + { + return shared_ptr(new AutoSaveBuffer(*this)); } /// int start(); diff --git a/src/support/ChangeLog b/src/support/ChangeLog index d5f2c1d155..52efd0e293 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,11 @@ +2004-03-23 Angus Leeming + + * forkedcall.h (ForkedProcess, Forkedcall): change the signature of + clone to return a boost::shred_ptr rather than a std::auto_ptr. + + * forkedcontr.[Ch]: store the forked calls as boost::shared_ptrs rather + than raw pointers. + 2004-03-22 Angus Leeming * forkedcontr.[Ch] (childrenChanged, getPIDs, getCommand): remove diff --git a/src/support/forkedcall.h b/src/support/forkedcall.h index f456d431e7..abe1938b15 100644 --- a/src/support/forkedcall.h +++ b/src/support/forkedcall.h @@ -32,8 +32,6 @@ #include -#include - namespace lyx { namespace support { @@ -52,7 +50,7 @@ public: /// virtual ~ForkedProcess() {} /// - virtual std::auto_ptr clone() const = 0; + virtual boost::shared_ptr clone() const = 0; /** A SignalType signal is can be emitted once the forked process * has finished. It passes: @@ -141,8 +139,8 @@ private: class Forkedcall : public ForkedProcess { public: /// - virtual std::auto_ptr clone() const { - return std::auto_ptr(new Forkedcall(*this)); + virtual boost::shared_ptr clone() const { + return boost::shared_ptr(new Forkedcall(*this)); } /** Start the child process. diff --git a/src/support/forkedcontr.C b/src/support/forkedcontr.C index 5124453e21..e45c4002ba 100644 --- a/src/support/forkedcontr.C +++ b/src/support/forkedcontr.C @@ -22,6 +22,7 @@ #include "frontends/Timeout.h" #include +#include #include #include @@ -65,11 +66,6 @@ ForkedcallsController::ForkedcallsController() // I want to print or something. ForkedcallsController::~ForkedcallsController() { - for (ListType::iterator it = forkedCalls.begin(); - it != forkedCalls.end(); ++it) { - delete *it; - } - delete timeout_; } @@ -79,7 +75,7 @@ void ForkedcallsController::addCall(ForkedProcess const & newcall) if (!timeout_->running()) timeout_->start(); - forkedCalls.push_back(newcall.clone().release()); + forkedCalls.push_back(newcall.clone()); } @@ -90,7 +86,7 @@ void ForkedcallsController::timer() ListType::iterator it = forkedCalls.begin(); ListType::iterator end = forkedCalls.end(); while (it != end) { - ForkedProcess * actCall = *it; + ForkedProcess * actCall = it->get(); pid_t pid = actCall->pid(); int stat_loc; @@ -134,10 +130,8 @@ void ForkedcallsController::timer() } if (remove_it) { - forkedCalls.erase(it); - actCall->emitSignal(); - delete actCall; + forkedCalls.erase(it); /* start all over: emiting the signal can result * in changing the list (Ab) @@ -158,19 +152,21 @@ void ForkedcallsController::timer() // within tolerance secs void ForkedcallsController::kill(pid_t pid, int tolerance) { - ListType::iterator it = - find_if(forkedCalls.begin(), forkedCalls.end(), - lyx::compare_memfun(&Forkedcall::pid, pid)); + typedef boost::indirect_iterator iterator; + + iterator begin = boost::make_indirect_iterator(forkedCalls.begin()); + iterator end = boost::make_indirect_iterator(forkedCalls.end()); + iterator it = find_if(begin, end, + lyx::compare_memfun(&Forkedcall::pid, pid)); - if (it == forkedCalls.end()) + if (it == end) return; - (*it)->kill(tolerance); - forkedCalls.erase(it); + it->kill(tolerance); + forkedCalls.erase(it.base()); - if (forkedCalls.empty()) { + if (forkedCalls.empty()) timeout_->stop(); - } } } // namespace support diff --git a/src/support/forkedcontr.h b/src/support/forkedcontr.h index ca02d23b02..1ba6c78386 100644 --- a/src/support/forkedcontr.h +++ b/src/support/forkedcontr.h @@ -16,8 +16,8 @@ #ifndef FORKEDCONTR_H #define FORKEDCONTR_H +#include #include // needed for pid_t - #include class Timeout; @@ -54,7 +54,8 @@ private: void timer(); /// The child processes - typedef std::list ListType; + typedef boost::shared_ptr ForkedProcessPtr; + typedef std::list ListType; /// ListType forkedCalls; -- 2.39.5