changeset 33243:d9ed1a322311

move global panic functions and macros to separate panic.h and panic.cc files * panic.h, panic.cc: New files. Move declaration of global panic functions and macros here from error.h and error.cc. * libinterp/corefcn/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Sat, 23 Mar 2024 13:17:02 -0400
parents 432e0151f652
children 08ab46f6e241
files libinterp/corefcn/error.cc libinterp/corefcn/error.h libinterp/corefcn/module.mk libinterp/corefcn/panic.cc libinterp/corefcn/panic.h
diffstat 5 files changed, 116 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/error.cc	Sat Mar 23 13:02:24 2024 -0400
+++ b/libinterp/corefcn/error.cc	Sat Mar 23 13:17:02 2024 -0400
@@ -1113,25 +1113,6 @@
   va_end (args);
 }
 
-OCTAVE_NORETURN
-void
-vpanic (const char *fmt, va_list args)
-{
-  octave::error_system& es = octave::__get_error_system__ ();
-
-  es.vpanic (fmt, args);
-}
-
-OCTAVE_NORETURN
-void
-panic (const char *fmt, ...)
-{
-  va_list args;
-  va_start (args, fmt);
-  vpanic (fmt, args);
-  va_end (args);
-}
-
 OCTAVE_BEGIN_NAMESPACE(octave)
 
 void
--- a/libinterp/corefcn/error.h	Sat Mar 23 13:02:24 2024 -0400
+++ b/libinterp/corefcn/error.h	Sat Mar 23 13:17:02 2024 -0400
@@ -35,6 +35,10 @@
 #include "unwind-prot.h"
 
 #include "oct-map.h"
+// Include panic.h here for backward compatibility with previous
+// versions of Octave that declared the global panic functions and
+// macros here.
+#include "panic.h"
 
 class octave_value_list;
 
@@ -489,32 +493,6 @@
 extern OCTINTERP_API void
 parse_error_with_id (const char *id, const char *fmt, ...);
 
-OCTAVE_NORETURN
-extern OCTINTERP_API void vpanic (const char *fmt, va_list args);
-
-OCTAVE_FORMAT_PRINTF (1, 2)
-OCTAVE_NORETURN
-extern OCTINTERP_API void panic (const char *fmt, ...);
-
-// To allow the __FILE__ and __LINE__ macros to work as expected, the
-// panic_impossible, panic_if, panic_unless, error_impossible, error_if,
-// and error_unless symbols must be defined as macros.
-
-#define panic_impossible()                                              \
-  ::panic ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__)
-
-#if defined (NDEBUG)
-#  define panic_if(cond)
-#else
-#  define panic_if(cond) do { if (cond) panic_impossible (); } while (0)
-#endif
-
-#if defined (NDEBUG)
-#  define panic_unless(cond)
-#else
-#  define panic_unless(cond) panic_if (! (cond))
-#endif
-
 #define error_impossible()                                              \
   ::error ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__)
 
--- a/libinterp/corefcn/module.mk	Sat Mar 23 13:02:24 2024 -0400
+++ b/libinterp/corefcn/module.mk	Sat Mar 23 13:17:02 2024 -0400
@@ -79,6 +79,7 @@
   %reldir%/oct.h \
   %reldir%/octave-default-image.h \
   %reldir%/pager.h \
+  %reldir%/panic.h \
   %reldir%/pr-flt-fmt.h \
   %reldir%/pr-output.h \
   %reldir%/procstream.h \
@@ -235,6 +236,7 @@
   %reldir%/ordqz.cc \
   %reldir%/ordschur.cc \
   %reldir%/pager.cc \
+  %reldir%/panic.cc \
   %reldir%/perms.cc \
   %reldir%/pinv.cc \
   %reldir%/pow2.cc \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libinterp/corefcn/panic.cc	Sat Mar 23 13:17:02 2024 -0400
@@ -0,0 +1,51 @@
+////////////////////////////////////////////////////////////////////////
+//
+// Copyright (C) 1993-2024 The Octave Project Developers
+//
+// See the file COPYRIGHT.md in the top-level directory of this
+// distribution or <https://octave.org/copyright/>.
+//
+// This file is part of Octave.
+//
+// Octave is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Octave is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Octave; see the file COPYING.  If not, see
+// <https://www.gnu.org/licenses/>.
+//
+////////////////////////////////////////////////////////////////////////
+
+#if defined (HAVE_CONFIG_H)
+#  include "config.h"
+#endif
+
+#include "error.h"
+#include "interpreter-private.h"
+#include "panic.h"
+
+OCTAVE_NORETURN
+void
+vpanic (const char *fmt, va_list args)
+{
+  octave::error_system& es = octave::__get_error_system__ ();
+
+  es.vpanic (fmt, args);
+}
+
+OCTAVE_NORETURN
+void
+panic (const char *fmt, ...)
+{
+  va_list args;
+  va_start (args, fmt);
+  vpanic (fmt, args);
+  va_end (args);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libinterp/corefcn/panic.h	Sat Mar 23 13:17:02 2024 -0400
@@ -0,0 +1,59 @@
+////////////////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2024 The Octave Project Developers
+//
+// See the file COPYRIGHT.md in the top-level directory of this
+// distribution or <https://octave.org/copyright/>.
+//
+// This file is part of Octave.
+//
+// Octave is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Octave is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Octave; see the file COPYING.  If not, see
+// <https://www.gnu.org/licenses/>.
+//
+////////////////////////////////////////////////////////////////////////
+
+#if ! defined (octave_panic_h)
+#define octave_panic_h 1
+
+#include "octave-config.h"
+
+#include <cstdarg>
+
+OCTAVE_NORETURN
+extern OCTINTERP_API void vpanic (const char *fmt, va_list args);
+
+OCTAVE_FORMAT_PRINTF (1, 2)
+OCTAVE_NORETURN
+extern OCTINTERP_API void panic (const char *fmt, ...);
+
+// To allow the __FILE__ and __LINE__ macros to work as expected, the
+// panic_impossible, panic_if, panic_unless, error_impossible, error_if,
+// and error_unless symbols must be defined as macros.
+
+#define panic_impossible()                                              \
+  ::panic ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__)
+
+#if defined (NDEBUG)
+#  define panic_if(cond)
+#else
+#  define panic_if(cond) do { if (cond) panic_impossible (); } while (0)
+#endif
+
+#if defined (NDEBUG)
+#  define panic_unless(cond)
+#else
+#  define panic_unless(cond) panic_if (! (cond))
+#endif
+
+#endif