]> git.lyx.org Git - features.git/commitdiff
make smart_ptr.hpp usable without exceptions
authorLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 20 Feb 2001 13:39:03 +0000 (13:39 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 20 Feb 2001 13:39:03 +0000 (13:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1569 a592a061-630c-0410-9148-cb99ea01b6c8

boost/boost/smart_ptr.hpp

index 162b458bd70cfad276e7bbf5637739ad08b67c5b..0f6d559d599059aae7e52e3867622cff87e191bc 100644 (file)
@@ -1,3 +1,11 @@
+// Baruch Even  baruch@ev-en.org  2001-02-20
+//  This version is a modified version for use in LyX
+//  The modifications are done in order to use it where exceptions are disabled
+//  Currently it has no "no memory" checks in place, asserts are probably the
+//  only real way.
+//  all changed are #ifded'ed by LYX_NO_EXCEPTIONS
+#define LYX_NO_EXCEPTIONS
+
 //  Boost smart_ptr.hpp header file  -----------------------------------------//
 
 //  (C) Copyright Greg Colvin and Beman Dawes 1998, 1999. Permission to copy,
@@ -129,8 +137,12 @@ template<typename T> class shared_ptr {
    typedef T element_type;
 
    explicit shared_ptr(T* p =0) : px(p) {
+#ifndef LYX_NO_EXCEPTIONS
       try { pn = new long(1); }  // fix: prevent leak if new throws
       catch (...) { delete p; throw; } 
+#else
+         pn = new long(1);
+#endif
    }
 
    shared_ptr(const shared_ptr& r) : px(r.px) { ++*(pn = r.pn); }  // never throws
@@ -200,12 +212,16 @@ template<typename T> class shared_ptr {
       if ( px == p ) return;  // fix: self-assignment safe
       if (--*pn == 0) { delete px; }
       else { // allocate new reference counter
+#ifndef LYX_NO_EXCEPTIONS                
         try { pn = new long; }  // fix: prevent leak if new throws
         catch (...) {
           ++*pn;  // undo effect of --*pn above to meet effects guarantee 
           delete p;
           throw;
         } // catch
+#else
+               pn = new long;
+#endif
       } // allocate new reference counter
       *pn = 1;
       px = p;
@@ -277,8 +293,12 @@ template<typename T> class shared_array {
    typedef T element_type;
 
    explicit shared_array(T* p =0) : px(p) {
+#ifndef LYX_NO_EXCEPTIONS
       try { pn = new long(1); }  // fix: prevent leak if new throws
       catch (...) { delete [] p; throw; } 
+#else
+         pn = new long(1);
+#endif
    }
 
    shared_array(const shared_array& r) : px(r.px)  // never throws
@@ -299,12 +319,16 @@ template<typename T> class shared_array {
       if ( px == p ) return;  // fix: self-assignment safe
       if (--*pn == 0) { delete [] px; }
       else { // allocate new reference counter
+#ifndef LYX_NO_EXCEPTIONS
         try { pn = new long; }  // fix: prevent leak if new throws
         catch (...) {
           ++*pn;  // undo effect of --*pn above to meet effects guarantee 
           delete [] p;
           throw;
         } // catch
+#else
+               pn = new long;
+#endif
       } // allocate new reference counter
       *pn = 1;
       px = p;