From f0406bb2b7c92199fef55d3a4e22cd29ebc84433 Mon Sep 17 00:00:00 2001
From: g0dil <g0dil@wiback.org>
Date: Mon, 3 Sep 2007 10:38:23 +0000
Subject: [PATCH] Better SENF configuration support (local_config.hh) Packets:
 Fix PacketImpl::updateIterators implemantation (don't access invalidated
 iterators) Scheduler: Remove access to invalidated timerMap_ iterator Socket:
 BUGFIX: Fix generic WriteRange implementation

---
 Packets/PacketImpl.cc                |  6 ++--
 Packets/PacketImpl.cci               | 13 ++++++---
 Packets/PacketImpl.cti               |  3 +-
 Packets/PacketImpl.hh                |  2 +-
 Packets/ParseArray.cti               |  8 ------
 SConstruct                           | 27 +++++++++--------
 Scheduler/Scheduler.cc               |  2 +-
 Socket/ClientSocketHandle.ct         | 16 +++++++----
 Socket/ClientSocketHandle.cti        | 21 +++++++-------
 Socket/ClientSocketHandle.ih         |  4 +--
 Socket/ProtocolClientSocketHandle.hh |  2 +-
 Socket/ProtocolServerSocketHandle.hh |  1 +
 Utils/Buffer.hh                      | 22 +-------------
 Utils/IteratorTraits.ih              | 11 ++++---
 Utils/IteratorTraits.test.cc         |  2 +-
 Utils/impl/membind.hh                |  2 +-
 Utils/mpl.hh                         |  5 +---
 debian/config.h => config.hh         | 43 ++++++++++++++++++++++++++--
 debian/libsenf-dev.install           |  2 +-
 debian/local_config.hh               |  2 ++
 debian/rules                         |  7 +++--
 find-sources.sh                      |  1 +
 run-test-gdb.sh                      | 22 +++++++++-----
 senfscons/SENFSCons.py               |  2 ++
 24 files changed, 127 insertions(+), 99 deletions(-)
 rename debian/config.h => config.hh (54%)
 create mode 100644 debian/local_config.hh

diff --git a/Packets/PacketImpl.cc b/Packets/PacketImpl.cc
index 8dfd75e10..777fae749 100644
--- a/Packets/PacketImpl.cc
+++ b/Packets/PacketImpl.cc
@@ -57,7 +57,7 @@ prefix_ void senf::detail::PacketImpl::clear(PacketData * self)
         truncateInterpreters(n);
     iterator first (boost::next(begin(),self->begin_));
     data_.erase(first, boost::next(begin(),self->end_));
-    updateIterators(self,first,-self->size());
+    updateIterators(self,self->begin_,-self->size());
 }
 
 // private members
@@ -73,7 +73,7 @@ prefix_ void senf::detail::PacketImpl::eraseInterpreters(interpreter_list::itera
     }
 }
 
-prefix_ void senf::detail::PacketImpl::updateIterators(PacketData * self, iterator pos,
+prefix_ void senf::detail::PacketImpl::updateIterators(PacketData * self, difference_type pos,
                                                        difference_type n)
 {
     // I hate to change the PacketData representation from here, I would have preferred to let
@@ -101,7 +101,7 @@ prefix_ void senf::detail::PacketImpl::updateIterators(PacketData * self, iterat
     // c)
     interpreter_list::iterator const i_end (interpreters_.end());
     if (++i != i_end)
-        if (std::distance(begin(), pos) < difference_type(i->begin_))
+        if (pos <= difference_type(i->begin_))
             // pos is before the packet, it must then be before all futher packets ...
             for (; i != i_end; ++i) {
                 i->begin_ += n;
diff --git a/Packets/PacketImpl.cci b/Packets/PacketImpl.cci
index f2293a8ec..0197b2486 100644
--- a/Packets/PacketImpl.cci
+++ b/Packets/PacketImpl.cci
@@ -148,27 +148,32 @@ prefix_ senf::detail::PacketImpl::size_type senf::detail::PacketImpl::size()
 
 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, byte v)
 {
+    difference_type ix (std::distance(begin(),pos));
     data_.insert(pos,v);
-    updateIterators(self,pos,1);
+    updateIterators(self,ix,1);
 }
 
 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, size_type n,
                                               byte v)
 {
+    difference_type ix (std::distance(begin(),pos));
     data_.insert(pos,n,v);
-    updateIterators(self,pos,n);
+    updateIterators(self,ix,n);
 }
 
 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator pos)
 {
+    difference_type ix (std::distance(begin(),pos));
     data_.erase(pos);
-    updateIterators(self,pos,-1);
+    updateIterators(self,ix,-1);
 }
 
 prefix_ void senf::detail::PacketImpl::erase(PacketData * self, iterator first, iterator last)
 {
+    difference_type ix (std::distance(begin(),first));
+    difference_type delta (std::distance(first,last));
     data_.erase(first,last);
-    updateIterators(self,first,-std::distance(first,last));
+    updateIterators(self,ix,-delta);
 }
 
 ///////////////////////////////////////////////////////////////////////////
diff --git a/Packets/PacketImpl.cti b/Packets/PacketImpl.cti
index 2e3fada18..ae6cc1e1b 100644
--- a/Packets/PacketImpl.cti
+++ b/Packets/PacketImpl.cti
@@ -37,8 +37,9 @@ template <class ForwardIterator>
 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, ForwardIterator f,
                                               ForwardIterator l)
 {
+    difference_type ix (std::distance(begin(),pos));
     data_.insert(pos,f,l);
-    updateIterators(self,pos,std::distance(f,l));
+    updateIterators(self,ix,std::distance(f,l));
 }
 
 template <class InputIterator>
diff --git a/Packets/PacketImpl.hh b/Packets/PacketImpl.hh
index 614eba218..ad254d64d 100644
--- a/Packets/PacketImpl.hh
+++ b/Packets/PacketImpl.hh
@@ -121,7 +121,7 @@ namespace detail {
         interpreter_list interpreters_;
 
         void eraseInterpreters(interpreter_list::iterator b, interpreter_list::iterator e);
-        void updateIterators(PacketData * self, iterator pos, difference_type n);
+        void updateIterators(PacketData * self, difference_type pos, difference_type n);
     };
 
 }}
diff --git a/Packets/ParseArray.cti b/Packets/ParseArray.cti
index 14d99cb57..ee2732d48 100644
--- a/Packets/ParseArray.cti
+++ b/Packets/ParseArray.cti
@@ -26,13 +26,6 @@
 #include "ParseArray.ih"
 
 // Custom includes
-#include <algorithm>
-#if defined(_STLP_ALGORITHM) || (__GNUC__<4 && __GNUC_MINOR__<4)
-#define copy_n std::copy_n
-#else
-#include <ext/algorithm>
-#define copy_n __gnu_cxx::copy_n
-#endif
 
 #define prefix_ inline
 ///////////////////////////////cti.p///////////////////////////////////////
@@ -154,7 +147,6 @@ prefix_ void senf::detail::Parse_Array_iterator<ElementParser>::advance(int n)
     i_ += n*ElementParser::fixed_bytes;
 }
 
-#undef copy_n
 ///////////////////////////////cti.e///////////////////////////////////////
 #undef prefix_
 
diff --git a/SConstruct b/SConstruct
index ed68a6797..e723e4661 100644
--- a/SConstruct
+++ b/SConstruct
@@ -33,7 +33,7 @@ def nonemptyFile(f):
     except OSError: return False
 
 def checkLocalConf(target, source, env):
-    if nonemptyFile('SConfig') or nonemptyFile('Doxyfile.local'):
+    if [ True for f in env['CONFIG_FILES'] if nonemptyFile(f) ]:
         print
         print "You have made local modifications to 'SConfig' and/or 'Doxyfile.local'."
         print "Building a debian package would remove those files."
@@ -73,8 +73,11 @@ logname = os.environ.get('LOGNAME')
 if not logname:
     logname = pwd.getpwuid(os.getuid()).pw_name
 
+def configFilesOpts(target, source, env, for_signature):
+    return [ '-I%s' % os.path.split(f)[1] for f in env['CONFIG_FILES'] ]
+
 env.Append(
-   CPPPATH = [ ],
+   CPPPATH = [ '#' ],
    LIBS = [ 'iberty', '$BOOSTREGEXLIB' ],
    DOXY_XREF_TYPES = [ 'bug', 'fixme', 'todo', 'idea' ],
    DOXY_HTML_XSL = '#/doclib/html-munge.xsl',
@@ -83,8 +86,10 @@ env.Append(
            'LOGNAME' : logname, # needed by the debian build scripts
            'CONCURRENCY_LEVEL' : env.GetOption('num_jobs') or "1"
            },
+   CONFIG_FILES = [ 'Doxyfile.local', 'SConfig', 'local_config.hh' ],
+   CONFIG_FILES_OPTS = configFilesOpts,
    CLEAN_PATTERNS = [ '*.pyc', 'semantic.cache', '.sconsign', '.sconsign.dblite' ],
-   BUILDPACKAGE_COMMAND = "dpkg-buildpackage -us -uc -rfakeroot -I.svn -IDoxyfile.local -ISConfig",
+   BUILDPACKAGE_COMMAND = "dpkg-buildpackage -us -uc -rfakeroot -I.svn $CONFIG_FILES_OPTS",
 )
 
 Export('env')
@@ -94,15 +99,9 @@ Export('env')
 if not env.GetOption('clean') and not os.path.exists("Doxyfile.local"):
     Execute(Touch("Doxyfile.local"))
 
-# Create config.h
-file("config.h","w").write(
-"""#ifndef H_config_
-#define H_config_ 1
-// This looks stupid. However, we need this since the debian packaged Version
-// of SENF is installed in a 'senf' subdirectory which the source Version is not
-#define SENF_ABSOLUTE_INCLUDE_PATH(senf_relative_include_file_path) <%s/senf_relative_include_file_path>
-#endif
-""" % env.Dir('#').abspath)
+# Create local_config.h
+if not env.GetOption('clean') and not os.path.exists("local_config.hh"):
+    Execute(Touch("local_config.hh"))
 
 ###########################################################################
 # Define build targets
@@ -116,6 +115,8 @@ SENFSCons.DoxyXRef(env,
                    HTML_HEADER = '#/doclib/doxy-header-overview.html',
                    HTML_FOOTER = '#/doclib/doxy-footer.html')
 
+SENFSCons.InstallIncludeFiles(env, [ 'config.hh' ])
+
 # Build combined library 'libsenf'
 libsenf = env.Library(
     SENFSCons.LibPath('senf'),
@@ -141,5 +142,3 @@ env.Clean('all', [ os.path.join(path,f)
                    for path, subdirs, files in os.walk('.')
                    for pattern in env['CLEAN_PATTERNS']
                    for f in fnmatch.filter(files,pattern) ])
-
-env.Clean('all', 'config.h')
diff --git a/Scheduler/Scheduler.cc b/Scheduler/Scheduler.cc
index e6e8b855d..09971a84e 100644
--- a/Scheduler/Scheduler.cc
+++ b/Scheduler/Scheduler.cc
@@ -201,8 +201,8 @@ prefix_ void senf::Scheduler::process()
                 i->second.cb();
             else
                 break;
-            timerMap_.erase(i);
             timerQueue_.pop();
+            timerMap_.erase(i);
         }
 
         if (events <= 0)
diff --git a/Socket/ClientSocketHandle.ct b/Socket/ClientSocketHandle.ct
index 1b8190c3e..6ad40407c 100644
--- a/Socket/ClientSocketHandle.ct
+++ b/Socket/ClientSocketHandle.ct
@@ -60,25 +60,29 @@ readfrom(Handle & handle, ForwardWritableRange & range, typename Handle::Address
 // senf::detail::WriteRange<Handle,ForwardReadableRange,IsContiguous>
 
 template <class Handle, class ForwardReadableRange, bool IsContiguous>
-prefix_ typename boost::range_iterator<ForwardReadableRange>::type
+prefix_ typename boost::range_const_iterator<ForwardReadableRange>::type
 senf::detail::WriteRange<Handle,ForwardReadableRange,IsContiguous>::
 write(Handle & handle, ForwardReadableRange & range)
 {
     typename boost::range_size<ForwardReadableRange>::type nwrite (boost::size(range));
+    typename boost::range_const_iterator<ForwardReadableRange>::type i (boost::begin(range));
     SENF_SCOPED_BUFFER(char, buffer, nwrite);
-    std::copy(boost::begin(range), boost::end(range), buffer);
-    return handle.write(std::make_pair(buffer, buffer+nwrite));
+    std::copy(i, boost::end(range), buffer);
+    std::advance(i, handle.write(std::make_pair(buffer, buffer+nwrite)) - buffer);
+    return i;
 }
 
 template <class Handle, class ForwardReadableRange, bool IsContiguous>
-prefix_ typename boost::range_iterator<ForwardReadableRange>::type
+prefix_ typename boost::range_const_iterator<ForwardReadableRange>::type
 senf::detail::WriteRange<Handle,ForwardReadableRange,IsContiguous>::
 writeto(Handle & handle, ForwardReadableRange & range, typename Handle::Address const & addr)
 {
     typename boost::range_size<ForwardReadableRange>::type nwrite (boost::size(range));
+    typename boost::range_const_iterator<ForwardReadableRange>::type i (boost::begin(range));
     SENF_SCOPED_BUFFER(char, buffer, nwrite);
-    std::copy(boost::begin(range), boost::end(range), buffer);
-    return handle.writeto(std::make_pair(buffer, buffer+nwrite), addr);
+    std::copy(i, boost::end(range), buffer);
+    std::advance(i, handle.writeto(std::make_pair(buffer, buffer+nwrite), addr) - buffer);
+    return i;
 }
 
 ///////////////////////////////////////////////////////////////////////////
diff --git a/Socket/ClientSocketHandle.cti b/Socket/ClientSocketHandle.cti
index f584a18e0..b2e721fe6 100644
--- a/Socket/ClientSocketHandle.cti
+++ b/Socket/ClientSocketHandle.cti
@@ -68,13 +68,13 @@ prefix_ typename boost::range_const_iterator<ForwardReadableRange>::type
 senf::detail::WriteRange<Handle, ForwardReadableRange, true>::
 write(Handle & handle, ForwardReadableRange & range)
 {
-    typename boost::range_const_iterator<ForwardReadableRange>::type const i 
+    typename boost::range_const_iterator<ForwardReadableRange>::type i 
         (boost::const_begin(range));
     char const * const ic (reinterpret_cast<char const *>(storage_iterator(i)));
-    return i + (handle.write(ic,
-                             reinterpret_cast<char const *>(
-                                 storage_iterator(boost::const_end(range))))
-                - ic);
+    std::advance(i, handle.write(ic,
+                                 reinterpret_cast<char const *>(
+                                     storage_iterator(boost::const_end(range)))) - ic);
+    return i;
 }
 
 template <class Handle, class ForwardReadableRange>
@@ -82,14 +82,13 @@ prefix_ typename boost::range_const_iterator<ForwardReadableRange>::type
 senf::detail::WriteRange<Handle, ForwardReadableRange, true>::
 writeto(Handle & handle, ForwardReadableRange & range, typename Handle::Address const & addr)
 {
-    typename boost::range_const_iterator<ForwardReadableRange>::type const i 
+    typename boost::range_const_iterator<ForwardReadableRange>::type i 
         (boost::const_begin(range));
     char const * const ic (reinterpret_cast<char const *>(storage_iterator(i)));
-    return i + (handle.writeto(addr,
-                               ic,
-                               reinterpret_cast<char const *>(
-                                   storage_iterator(boost::const_end(range))))
-                - ic);
+    std::advance(i, handle.writeto(addr, ic,
+                                   reinterpret_cast<char const *>(
+                                       storage_iterator(boost::const_end(range)))) - ic);
+    return i;
 }
 
 ///////////////////////////////////////////////////////////////////////////
diff --git a/Socket/ClientSocketHandle.ih b/Socket/ClientSocketHandle.ih
index 83f49bccc..619f52417 100644
--- a/Socket/ClientSocketHandle.ih
+++ b/Socket/ClientSocketHandle.ih
@@ -79,10 +79,10 @@ namespace detail {
     template <class Handle, class ForwardReadableRange, bool IsContiguous>
     struct WriteRange
     {
-        static typename boost::range_iterator<ForwardReadableRange>::type
+        static typename boost::range_const_iterator<ForwardReadableRange>::type
         write(Handle & handle, ForwardReadableRange & range);
         
-        static typename boost::range_iterator<ForwardReadableRange>::type
+        static typename boost::range_const_iterator<ForwardReadableRange>::type
         writeto(Handle & handle, ForwardReadableRange & range,
                 typename Handle::Address const & addr);
     };
diff --git a/Socket/ProtocolClientSocketHandle.hh b/Socket/ProtocolClientSocketHandle.hh
index c40515bad..ea00e0462 100644
--- a/Socket/ProtocolClientSocketHandle.hh
+++ b/Socket/ProtocolClientSocketHandle.hh
@@ -29,7 +29,7 @@
 
 // Custom includes
 #include "ClientSocketHandle.hh"
-#include "../config.h"
+#include "../config.hh"
 
 #include "ProtocolClientSocketHandle.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
diff --git a/Socket/ProtocolServerSocketHandle.hh b/Socket/ProtocolServerSocketHandle.hh
index bd9200daa..49b8dc0d1 100644
--- a/Socket/ProtocolServerSocketHandle.hh
+++ b/Socket/ProtocolServerSocketHandle.hh
@@ -29,6 +29,7 @@
 
 // Custom includes
 #include "ServerSocketHandle.hh"
+#include "../config.hh"
 
 #include "ProtocolServerSocketHandle.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
diff --git a/Utils/Buffer.hh b/Utils/Buffer.hh
index b61d13ed4..6ce84a60f 100644
--- a/Utils/Buffer.hh
+++ b/Utils/Buffer.hh
@@ -27,31 +27,11 @@
 #define HH_Buffer_ 1
 
 // Custom includes
+#include "../config.hh"
 
 //#include "Buffer.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
 
-#if !defined(SENF_BUFFER_USE_LOCALS) && !defined(SENF_BUFFER_USE_ALLOCA) && !defined(SENF_BUFFER_USE_NEW)
-#   
-#
-#   if defined(__GNUC__)
-#       define SENF_BUFFER_USE_LOCALS 1
-#
-#   // Add other compilers here ...
-#
-#   // dynamic arrays are part of C99. Which is NOT part of C++ 
-#   // but lets try nonetheless ...
-#   elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-#       define SENF_BUFFER_USE_LOCALS 1
-#
-#   endif
-#
-#   if !defined(SENF_BUFFER_USE_LOCALS) && !defined(SENF_BUFFER_USE_ALLOCA)
-#       define SENF_BUFFER_USE_NEW 1
-#   endif
-#
-#endif
-
 #if defined(SENF_BUFFER_USE_LOCALS)
 
 #   define SENF_SCOPED_BUFFER(type, sym, size)  \
diff --git a/Utils/IteratorTraits.ih b/Utils/IteratorTraits.ih
index 780490e2e..9533e3d30 100644
--- a/Utils/IteratorTraits.ih
+++ b/Utils/IteratorTraits.ih
@@ -32,21 +32,20 @@
 
 namespace senf {
 
-    // It is not very nice that we need to specialize on the exact iterator names.
-    // The preprocessor guard will need to be expanded by also giving the correct
-    // version numbers. We need to disable it when using stlport and so on ... 
-    // The problem is, that typedefs are not expanded when specializing ...
+    // It is not very nice that we need to specialize on the exact iterator names.  The preprocessor
+    // guard will need to be expanded by also giving the correct version numbers.  The problem is,
+    // that typedefs are not expanded when specializing ...
 
 #if defined(__GNUG__)
     template <class T, class Alloc>
     struct contiguous_storage_iterator<
-        __gnu_cxx::__normal_iterator<T*, std::vector<T,Alloc> > >
+        ::__gnu_cxx::__normal_iterator<T*, std::vector<T,Alloc> > >
         : public boost::true_type
     {};
 
     template <class CharT, class Traits, class Alloc>
     struct contiguous_storage_iterator< 
-        __gnu_cxx::__normal_iterator<CharT*, std::basic_string<CharT, Traits, Alloc> > >
+        ::__gnu_cxx::__normal_iterator<CharT*, std::basic_string<CharT, Traits, Alloc> > >
         : public boost::true_type
     {};
 #endif
diff --git a/Utils/IteratorTraits.test.cc b/Utils/IteratorTraits.test.cc
index ddfe60e7f..d874e2294 100644
--- a/Utils/IteratorTraits.test.cc
+++ b/Utils/IteratorTraits.test.cc
@@ -41,7 +41,7 @@ BOOST_AUTO_UNIT_TEST(iteratorTraits)
 {
     BOOST_CHECK_EQUAL( senf::contiguous_storage_iterator<int*>::value, true );
     BOOST_CHECK_EQUAL( senf::contiguous_storage_iterator<void>::value, false );
-#ifdef __GNUG__
+#if defined(__GNUG__) && ! defined(_GLIBCXX_DEBUG)
     BOOST_CHECK_EQUAL( senf::contiguous_storage_iterator<std::vector<int>::iterator>::value, true);
     BOOST_CHECK_EQUAL( senf::contiguous_storage_iterator<std::string::iterator>::value, true);
 #endif
diff --git a/Utils/impl/membind.hh b/Utils/impl/membind.hh
index 7dc1930ad..6b6681c9c 100644
--- a/Utils/impl/membind.hh
+++ b/Utils/impl/membind.hh
@@ -27,7 +27,7 @@
 #include <boost/preprocessor/cat.hpp>
 #include <boost/preprocessor/repetition/enum_shifted.hpp>
 #include <boost/preprocessor/iteration/iterate.hpp>
-#include "../../config.h"
+#include "../../config.hh"
 
 template <typename R, typename T>
 boost::function<R()> membind(R (T::* fn)(),scOBTYPE ob)
diff --git a/Utils/mpl.hh b/Utils/mpl.hh
index 5eee0c5f9..ba6008358 100644
--- a/Utils/mpl.hh
+++ b/Utils/mpl.hh
@@ -27,6 +27,7 @@
 #define HH_mpl_ 1
 
 // Custom includes
+#include "../config.hh"
 
 //#include "mpl.mpp"
 #include "mpl.ih"
@@ -38,10 +39,6 @@ namespace mpl {
     /** \defgroup senfmpl Low-level template meta programming helpers
      */
 
-#   ifndef SENF_MPL_RV_ALIGNMENT
-#       define SENF_MPL_RV_ALIGNMENT 16
-#   endif
-
     /** \brief Return-value type used to implement overload selection
 
         The senf::mpl::rv type is used together with \ref SENF_MPL_RV() to select template
diff --git a/debian/config.h b/config.hh
similarity index 54%
rename from debian/config.h
rename to config.hh
index c30ab032b..a0e1cbcbd 100644
--- a/debian/config.h
+++ b/config.hh
@@ -23,15 +23,52 @@
 /** \file
     \brief config public header */
 
-#ifndef H_config_
-#define H_config_ 1
+#ifndef HH_config_
+#define HH_config_ 1
 
 // Custom includes
 
 //#include "config.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
 
-#define SENF_ABSOLUTE_INCLUDE_PATH(senf_relative_include_file_path) <senf/senf_relative_include_file_path>
+# include "local_config.hh"
+
+# ifndef SENF_ABSOLUTE_INCLUDE_PATH
+#     define SENF_ABSOLUTE_INCLUDE_PATH(senf_relative_include_file_path) <senf_relative_include_file_path>
+# endif
+
+# ifndef SENF_copy_n
+#     include <algorithm>
+#     if defined(__GNUC__) && ! defined(_STLP_ALGORITHM) && (__GNUC__>=4 || (__GNUC__==3 && __GNUC_MINOR__>=4))
+#         include <ext/algorithm>
+#         define SENF_copy_n __gnu_cxx::copy_n
+#     else
+#         define SENF_copy_n std::copy_n
+#     endif
+# endif
+
+# ifndef SENF_MPL_RV_ALIGNMENT
+#     define SENF_MPL_RV_ALIGNMENT 16
+# endif
+
+# if !defined(SENF_BUFFER_USE_LOCALS) && !defined(SENF_BUFFER_USE_ALLOCA) && !defined(SENF_BUFFER_USE_NEW)
+#
+#     if defined(__GNUC__)
+#         define SENF_BUFFER_USE_LOCALS 1
+#
+#     // Add other compilers here ...
+#
+#     // dynamic arrays are part of C99. Which is NOT part of C++ 
+#     // but lets try nonetheless ...
+#     elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#         define SENF_BUFFER_USE_LOCALS 1
+#     endif
+#
+#     if !defined(SENF_BUFFER_USE_LOCALS) && !defined(SENF_BUFFER_USE_ALLOCA)
+#         define SENF_BUFFER_USE_NEW 1
+#     endif
+#
+# endif
 
 ///////////////////////////////hh.e////////////////////////////////////////
 //#include "config.cci"
diff --git a/debian/libsenf-dev.install b/debian/libsenf-dev.install
index 1fc59c50a..cdb869b3f 100644
--- a/debian/libsenf-dev.install
+++ b/debian/libsenf-dev.install
@@ -6,7 +6,7 @@ debian/tmp/usr/include/Scheduler usr/include/senf
 debian/tmp/usr/include/Socket usr/include/senf
 debian/tmp/usr/include/Utils usr/include/senf
 boost usr/include/senf
-debian/config.h usr/include/senf
+debian/local_config.hh usr/include/senf
 debian/Socket.hh usr/include/senf
 debian/Packets.hh usr/include/senf
 debian/PPI.hh usr/include/senf
diff --git a/debian/local_config.hh b/debian/local_config.hh
new file mode 100644
index 000000000..1ee04a4fa
--- /dev/null
+++ b/debian/local_config.hh
@@ -0,0 +1,2 @@
+
+#define SENF_ABSOLUTE_INCLUDE_PATH(senf_relative_include_file_path) <senf/senf_relative_include_file_path>
diff --git a/debian/rules b/debian/rules
index b6a8e662d..ea893a069 100755
--- a/debian/rules
+++ b/debian/rules
@@ -37,9 +37,10 @@ configure: configure-stamp
 configure-stamp:
 	dh_testdir
 #	# Add here commands to configure the package.
-	rm -f Doxyfile.local SConfig
-#       If needed, we could create new 'Doxyfile.local' and/or 'SConfig' files here.
-#       We don't remove them in 'clean' to allow building a source package from an 
+	rm -f Doxyfile.local SConfig local_config.hh
+#       If needed, we could create new files 'Doxyfile.local',
+#       'SConfig' and/or 'local_config.hh' here.  We don't remove them
+#       in 'clean' to allow building a source package from an
 #       individually configured svn working copy.
 	touch configure-stamp
 
diff --git a/find-sources.sh b/find-sources.sh
index 32008f470..be469650d 100755
--- a/find-sources.sh
+++ b/find-sources.sh
@@ -22,6 +22,7 @@ set -f
 find . \
 	-name .svn -prune -o \
 	-name doc -prune -o \
+	-name debian -prune -o \
 	-name "*.a" -o \
 	-name "*.o" -o \
 	-name "*~" -o \
diff --git a/run-test-gdb.sh b/run-test-gdb.sh
index 8d87f2ad8..7fa122a46 100755
--- a/run-test-gdb.sh
+++ b/run-test-gdb.sh
@@ -8,9 +8,6 @@
 # This script will run the .test.bin test driver within gdb and will
 # create a backtrace for every exception caught by the test driver.
 #
-# NOTE: If your unit test (excplicitly) writes output to stderr, this
-# output will be lost
-#
 # NOTE: This works by setting a breakpoint in the std::exception
 # constructor. This is, where the backtrace is created from. If you do
 # some funky manipulations with your exceptions, the backtrace might
@@ -38,8 +35,9 @@ EOF
 # correctly (cought before the reach the unit test driver). It will
 # also truncate the backtrace at the first stackframe within the unit
 # test subsystem since we are only interested in the user code.
-gdb -batch -x .run-test-gdb.cmd ./.test.bin 2>/dev/null | perl -e '
+gdb -batch -x .run-test-gdb.cmd ./.test.bin 2>&1 | perl -e '
   $mode=0;
+  $silent=0;
   while (<STDIN>) {
     if ($mode==0) {
       if (/^$/) {
@@ -49,7 +47,7 @@ gdb -batch -x .run-test-gdb.cmd ./.test.bin 2>/dev/null | perl -e '
       }
     }
     elsif ($mode==1) {
-      if (/^Breakpoint 1, exception/) {
+      if (/^(Breakpoint 1, exception|Program received signal )/) {
         $mode=2;
         @l=();
       } else {
@@ -62,16 +60,26 @@ gdb -batch -x .run-test-gdb.cmd ./.test.bin 2>/dev/null | perl -e '
       if (/^(#?[0-9]| )/) {
         push @l,$_ if /^#/;
         $l[$#l] .= $_ if @l && /^ /;
-      } elsif (/^Current language:  auto;/) {
+      } elsif (/^(Current language:  auto;|\[Switching to Thread)/) {
         ;
       } else {
         $mode=0;
         if (/: fatal error in /) {
+          print "\n";
           for (@l[1..$#l]) {
              last if /^#[0-9]+ +0x[0-9a-f]+ in boost::unit_test::ut_detail::invoker/;
-             print;
+             if ($silent) {
+	       unless (/at \/usr\/lib\/gcc\//) {
+		 print;
+		 $silent=0;
+	       }
+             } else {
+               print unless /in \?\?/;
+               $silent=1 if /__gnu_debug::/;
+             }
           }
           print;
+          print "\n";
         } else {
           redo;
         }
diff --git a/senfscons/SENFSCons.py b/senfscons/SENFSCons.py
index 373b5d6e5..da2014163 100644
--- a/senfscons/SENFSCons.py
+++ b/senfscons/SENFSCons.py
@@ -245,6 +245,8 @@ def MakeEnvironment():
                    CPPDEFINES = [ 'NDEBUG' ])
     else:
         env.Append(CXXFLAGS = [ '-O0', '-g', '-fno-inline' ],
+    # The unit-test framework is not compiled with _GLIBCXX_DEBUG so this fails.
+    #               CPPDEFINES = [ '_GLIBCXX_DEBUG', 'BOOST_REGEX_NO_LIB' ],
                    LINKFLAGS = [ '-g' ])
 
     env.Append(CPPDEFINES = [ '$EXTRA_DEFINES' ],
-- 
GitLab