boost exception test.
authorCarl Hetherington <cth@carlh.net>
Sun, 2 Feb 2020 18:56:22 +0000 (19:56 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 2 Feb 2020 19:17:35 +0000 (20:17 +0100)
src/lib/audio_buffers.cc
src/lib/dcpomatic_assert.h
src/tools/dcpomatic.cc
src/tools/wscript
test/wscript
wscript

index 63204dd6a8684fd50897e68dff0b6b8d15ea30c5..f426c2b98af01748746bf1ae12fae85e37c5f32a 100644 (file)
@@ -185,10 +185,14 @@ AudioBuffers::copy_from (AudioBuffers const * from, int32_t frames_to_copy, int3
                return;
        }
 
-       DCPOMATIC_ASSERT (from->channels() == channels());
-
+       read_offset = -1; // XXX
        DCPOMATIC_ASSERT (from);
-       DCPOMATIC_ASSERT (read_offset >= 0 && (read_offset + frames_to_copy) <= from->_allocated_frames);
+       DCPOMATIC_ASSERT (from->channels() == channels());
+       DCPOMATIC_ASSERT_MESSAGE (
+                       read_offset >= 0 && (read_offset + frames_to_copy) <= from->_allocated_frames,
+                       "(read_offset=%1, frames_to_copy=%2, _allocated_frames=%3)",
+                       read_offset, read_offset + frames_to_copy, from->_allocated_frames
+                       );
        DCPOMATIC_ASSERT (write_offset >= 0 && (write_offset + frames_to_copy) <= _allocated_frames);
 
        for (int i = 0; i < _channels; ++i) {
index a9851d0f886c5825a18f97ca9083a180cd1d3f48..b8adc5225202c78529ab47d0e518ff8c06d3034d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+#ifndef DCPOMATIC_ASSERT_H
+#define DCPOMATIC_ASSERT_H
+
 #include "exceptions.h"
+#include <boost/stacktrace.hpp>
+#include <boost/exception/all.hpp>
+
+typedef boost::error_info<struct tag_stacktrace, boost::stacktrace::stacktrace> traced;
+
+template <class E>
+void throw_with_trace(E const& e)
+{
+       throw boost::enable_error_info(e) << traced(boost::stacktrace::stacktrace());
+}
+
+#define DCPOMATIC_ASSERT(x) if (!(x)) throw_with_trace(ProgrammingError (__FILE__, __LINE__));
+#define DCPOMATIC_ASSERT_MESSAGE(x, m, ...) if (!(x)) throw_with_trace(ProgrammingError(__FILE__, __LINE__, String::compose(m, __VA_ARGS__)));
 
-#define DCPOMATIC_ASSERT(x) if (!(x)) throw ProgrammingError (__FILE__, __LINE__);
+#endif
index 47851a21874249f67244ed168259c2c47d9ddbb6..d50604740590b79153cf323759cc183b92a2ff6d 100644 (file)
@@ -450,6 +450,11 @@ public:
        catch (std::exception& e) {
                wxString p = std_to_wx (file.string ());
                wxCharBuffer b = p.ToUTF8 ();
+               boost::stacktrace::stacktrace* st = boost::get_error_info<traced>(e);
+               std::cout << "Amiga!\n";
+               if (st) {
+                       std::cout << "Awooga! " << *st << "\n";
+               }
                error_dialog (this, wxString::Format (_("Could not open film at %s"), p.data()), std_to_wx (e.what()));
        }
 
@@ -1683,6 +1688,11 @@ private:
                                        )
                                );
                } catch (exception& e) {
+                       boost::stacktrace::stacktrace* st = boost::get_error_info<traced>(e);
+                       std::cout << "Amiga!\n";
+                       if (st) {
+                               std::cout << "Awooga! " << *st << "\n";
+                       }
                        error_dialog (
                                0,
                                wxString::Format (
index 3b2c0a04ca6eb5b3aaf778563e36a3dcef0f068e..ad8d00c256ec897374daf1539b330fea90b2792f 100644 (file)
@@ -35,6 +35,9 @@ def build(bld):
     if bld.env.TARGET_WINDOWS:
         uselib += 'WINSOCK2 DBGHELP SHLWAPI MSWSOCK BOOST_LOCALE WINSOCK2 OLE32 DSOUND WINMM KSUSER '
 
+    if bld.env.TARGET_LINUX:
+        uselib += 'DL'
+
     cli_tools = []
     if bld.env.VARIANT == 'swaroop-theater':
         cli_tools = [ 'dcpomatic_uuid']
index 3c6170dcf3ef2e4f9c4190b786e562544e68f4d4..71990c9277a4e5f23f14b8499885c8e8a5ebb1d7 100644 (file)
@@ -39,6 +39,8 @@ def build(bld):
     obj.uselib += 'AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE SWRESAMPLE POSTPROC CXML SUB GLIB CURL SSH XMLSEC BOOST_REGEX ICU NETTLE MAGICK PNG '
     if bld.env.TARGET_WINDOWS:
         obj.uselib += 'WINSOCK2 DBGHELP SHLWAPI MSWSOCK BOOST_LOCALE '
+    if bld.env.TARGET_LINUX:
+        obj.uselib += 'DL '
     obj.use    = 'libdcpomatic2'
     obj.source = """
                  4k_test.cc
diff --git a/wscript b/wscript
index c61b86782229a692d02e6b5fd0f914dc4f3d6f5c..f2b0c43f30447546c4a6da5e2391f830cd6c1804 100644 (file)
--- a/wscript
+++ b/wscript
@@ -187,7 +187,7 @@ def configure(conf):
         conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_POSIX')
         boost_lib_suffix = ''
         boost_thread = 'boost_thread'
-        conf.env.append_value('LINKFLAGS', '-pthread')
+        conf.env.append_value('LINKFLAGS', ['-pthread'])
 
     # Linux
     if conf.env.TARGET_LINUX:
@@ -196,6 +196,7 @@ def configure(conf):
         conf.env.append_value('CXXFLAGS', '-DLINUX_SHARE_PREFIX="%s/share/dcpomatic2"' % conf.env['INSTALL_PREFIX'])
         conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_LINUX')
         conf.env.append_value('CXXFLAGS', ['-Wlogical-op', '-Wcast-align'])
+        conf.check(lib='dl', uselib_store='DL', msg="Checking for library dl")
         if not conf.env.DISABLE_GUI:
             conf.check_cfg(package='gtk+-2.0', args='--cflags --libs', uselib_store='GTK', mandatory=True)