]> git.lyx.org Git - features.git/commitdiff
Store the forked calls in boost::shared_ptr rather than a raw pointer.
authorAngus Leeming <leeming@lyx.org>
Tue, 23 Mar 2004 14:39:41 +0000 (14:39 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 23 Mar 2004 14:39:41 +0000 (14:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8518 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/ispell.C
src/lyx_cb.C
src/support/ChangeLog
src/support/forkedcall.h
src/support/forkedcontr.C
src/support/forkedcontr.h

index 8b4c3ecb1573befc428bb12c9132de509c3f6941..c480db6f73bdd278da8694e6f9d409e5a4b840d4 100644 (file)
@@ -1,3 +1,9 @@
+2004-03-23  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <lasgouttes@lyx.org>
 
        * lyxfunc.C (getStatus): handle read-only buffers correctly;
index 8cfdddf97f8bf47aaa44e2685f6dc95b855de910..08de736d831aedb0491d357087913f720d84cebc 100644 (file)
 #endif
 #include <sys/time.h>
 
+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<lyx::support::ForkedProcess> clone() const {
-               return auto_ptr<lyx::support::ForkedProcess>(new LaunchIspell(*this));
+       virtual shared_ptr<ForkedProcess> clone() const {
+               return shared_ptr<ForkedProcess>(new LaunchIspell(*this));
        }
        ///
        int start();
index bdfe5e83f86ef72a3ae719976d93fb78fbad6627..9009677032c6919e29a9c677a1e4b12d249e2381 100644 (file)
@@ -44,6 +44,8 @@
 #include "support/path_defines.h"
 #include "support/systemcall.h"
 
+#include <boost/shared_ptr.hpp>
+
 #include <cerrno>
 #include <fstream>
 
@@ -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<ForkedProcess> clone() const {
-               return auto_ptr<ForkedProcess>(new AutoSaveBuffer(*this));
+       virtual shared_ptr<ForkedProcess> clone() const
+       {
+               return shared_ptr<ForkedProcess>(new AutoSaveBuffer(*this));
        }
        ///
        int start();
index d5f2c1d15576b259d46711cb0eac8cd097387d18..52efd0e293034e905aa9d090656032256bce5aa9 100644 (file)
@@ -1,3 +1,11 @@
+2004-03-23  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <leeming@lyx.org>
 
        * forkedcontr.[Ch] (childrenChanged, getPIDs, getCommand): remove
index f456d431e757ffe402e6d8ec1596a49e935344fe..abe1938b151e20ceaf37b4d35a685984452b1179 100644 (file)
@@ -32,8 +32,6 @@
 
 #include <sys/types.h>
 
-#include <memory>
-
 namespace lyx {
 namespace support {
 
@@ -52,7 +50,7 @@ public:
        ///
        virtual ~ForkedProcess() {}
        ///
-       virtual std::auto_ptr<ForkedProcess> clone() const = 0;
+       virtual boost::shared_ptr<ForkedProcess> 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<ForkedProcess> clone() const {
-               return std::auto_ptr<ForkedProcess>(new Forkedcall(*this));
+       virtual boost::shared_ptr<ForkedProcess> clone() const {
+               return boost::shared_ptr<ForkedProcess>(new Forkedcall(*this));
        }
 
        /** Start the child process.
index 5124453e21254c3bb2c994ea5d5d6da2d99fdcc0..e45c4002ba99c945a81a1a1f1757e39497dbe903 100644 (file)
@@ -22,6 +22,7 @@
 #include "frontends/Timeout.h"
 
 #include <boost/bind.hpp>
+#include <boost/iterator/indirect_iterator.hpp>
 
 #include <cerrno>
 #include <cstdlib>
@@ -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<ListType::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
index ca02d23b02b87cc60cd043eca2071511fdd54b91..1ba6c78386d6206aaeeee60fe9113224ac9151e2 100644 (file)
@@ -16,8 +16,8 @@
 #ifndef FORKEDCONTR_H
 #define FORKEDCONTR_H
 
+#include <boost/shared_ptr.hpp>
 #include <sys/types.h> // needed for pid_t
-
 #include <list>
 
 class Timeout;
@@ -54,7 +54,8 @@ private:
        void timer();
 
        /// The child processes
-       typedef std::list<ForkedProcess *> ListType;
+       typedef boost::shared_ptr<ForkedProcess> ForkedProcessPtr;
+       typedef std::list<ForkedProcessPtr> ListType;
        ///
        ListType forkedCalls;