octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 1/2] Add a scoped warning disabler.


From: Jason Riedy
Subject: [RFC PATCH 1/2] Add a scoped warning disabler.
Date: Thu, 06 Dec 2007 16:31:16 -0800
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux)

Linking the warning enabled status to the scope helps with exceptions.
Use a struct rather than a class just to avoid dumping the common init
symbol into the global environment.
---
  This is just so I can disable sparse->full warnings cleanly.

 src/ChangeLog |   12 ++++++++++++
 src/error.cc  |   31 +++++++++++++++++++++++++++++++
 src/error.h   |   14 ++++++++++++++
 3 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 841e064..5278a66 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,15 @@
+2007-12-06  Jason Riedy  <address@hidden>
+
+       * error.h (struct octave_warning_suspend): New class for disabling
+       a warning within a scope.
+       * error.cc (octave_warning_suspend_init): Common init and
+       disabling code for octave_warning_suspend.  A function rather than
+       a method to limit symbols without playing with visibility.
+       (octave_warning_suspend::octave_warning_suspend): Define
+       constructors.
+       (octave_warning_suspend::~octave_warning_suspend): Define
+       destructor.
+
 2007-12-05  John W. Eaton  <address@hidden>
 
        * version.h (OCTAVE_VERSION): Now 2.9.18+.
diff --git a/src/error.cc b/src/error.cc
index e5f76db..2638a0c 100644
--- a/src/error.cc
+++ b/src/error.cc
@@ -1743,6 +1743,37 @@ to enter the debugger when a warning is encountered.\n\
   return SET_INTERNAL_VARIABLE (debug_on_warning);
 }
 
+static void
+octave_warning_suspend_init (octave_warning_suspend& x, const std::string& id)
+{
+  x.warning_id = std::string(id);
+  x.state = warning_enabled (x.warning_id);
+  if (x.state)
+    disable_warning (x.warning_id);
+}
+
+octave_warning_suspend::octave_warning_suspend (const char *id)
+{
+  octave_warning_suspend_init (*this, std::string(id));
+}
+
+octave_warning_suspend::octave_warning_suspend (const std::string& id)
+{
+  octave_warning_suspend_init (*this, id);
+}
+
+octave_warning_suspend::~octave_warning_suspend ()
+{
+  if (!state) return;
+
+  octave_value_list args;
+
+  args(1) = warning_id;
+  args(0) = "on";
+
+  Fwarning (args, 0);
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
diff --git a/src/error.h b/src/error.h
index 94eecec..456e03a 100644
--- a/src/error.h
+++ b/src/error.h
@@ -105,6 +105,20 @@ extern OCTINTERP_API bool discard_error_messages;
 // TRUE means warning messages are turned off.
 extern OCTINTERP_API bool discard_warning_messages;
 
+// Helper to suspend and restore a specific warning for a scope.
+struct
+OCTINTERP_API
+octave_warning_suspend
+{
+  std::string warning_id;
+  int state;
+
+  octave_warning_suspend () : state(0) {}
+  explicit octave_warning_suspend (const char* id);
+  explicit octave_warning_suspend (const std::string& id);
+  ~octave_warning_suspend ();
+};
+
 #endif
 
 /*
-- 
debian.1.5.3.7.1-dirty



reply via email to

[Prev in Thread] Current Thread [Next in Thread]