# HG changeset patch # User John W. Eaton # Date 1712437895 14400 # Node ID 56d234504c0118a887efc627b3b3f3831dfacb5d # Parent 3606817b9994955f0b102b16e177837f863e04ae eliminate some uses of panic_* functions Replace all uses of panic_* functions that result in compiler warnings when compiling with NDEBUG with calls to error instead. Files affected: graphics.cc, mex.cc, stack-frame.cc, ov-base-mat.cc, ov-fcn.cc, ov.cc, ops.h, lex.ll, oct-lvalue.cc, pt-idx.cc, and Array-util.cc. diff -r 3606817b9994 -r 56d234504c01 libinterp/corefcn/graphics.cc --- a/libinterp/corefcn/graphics.cc Sat Apr 06 14:38:17 2024 -0400 +++ b/libinterp/corefcn/graphics.cc Sat Apr 06 17:11:35 2024 -0400 @@ -5310,10 +5310,14 @@ // Including ones we do don't implement? // FIXME: This function is probably never called without mode == "reset". - // Verify this is the case with panic_unless() (1/6/2017). - // If there are reports of problems then figure out what code is - // calling it with the mode set to something else. - panic_unless (mode == "reset"); + // Error if this is not true. If there are reports of problems + // then figure out what code is calling it with the mode set to + // something else. It's apparently been this way since + // 1/6/2017 without any reports. Maybe we should eliminate the + // mode argument? + + if (mode != "reset") + error (R"(axes::properties::set_defaults: expected mode = "reset", found "%s")", mode.c_str ()); Matrix tlim (1, 2, 0.0); tlim(1) = 1; diff -r 3606817b9994 -r 56d234504c01 libinterp/corefcn/mex.cc --- a/libinterp/corefcn/mex.cc Sat Apr 06 14:38:17 2024 -0400 +++ b/libinterp/corefcn/mex.cc Sat Apr 06 17:11:35 2024 -0400 @@ -238,6 +238,12 @@ extern OCTINTERP_API void mxSetImagData (mxArray *ptr, void *pi); } +OCTAVE_NORETURN static void +error_impossible_call (const char *fcn_name) +{ + error ("unexpected call to %s - please report this bug", fcn_name); +} + static void * xmalloc (size_t n) { @@ -952,7 +958,7 @@ void request_mutation () const { if (m_mutate_flag) - panic_impossible (); + error ("unexpected: m_mutate_flag is true in mxArray_octave_value::request_mutation - please report this bug"); m_mutate_flag = true; } @@ -2080,9 +2086,9 @@ ~mxArray_interleaved_full () = default; - void * get_imag_data () const { panic_impossible (); } - - void set_imag_data (void */*pi*/) { panic_impossible (); } + void * get_imag_data () const { error_impossible_call ("mxArray_interleaved_full::get_imag_data"); } + + void set_imag_data (void */*pi*/) { error_impossible_call ("mxArray_interleaved_full::set_imag_data"); } protected: @@ -2162,55 +2168,55 @@ set_complexity (m_pi != nullptr); } - mxDouble * get_doubles () const { panic_impossible (); } - mxSingle * get_singles () const { panic_impossible (); } - mxInt8 * get_int8s () const { panic_impossible (); } - mxInt16 * get_int16s () const { panic_impossible (); } - mxInt32 * get_int32s () const { panic_impossible (); } - mxInt64 * get_int64s () const { panic_impossible (); } - mxUint8 * get_uint8s () const { panic_impossible (); } - mxUint16 * get_uint16s () const { panic_impossible (); } - mxUint32 * get_uint32s () const { panic_impossible (); } - mxUint64 * get_uint64s () const { panic_impossible (); } - - mxComplexDouble * get_complex_doubles () const { panic_impossible (); } - mxComplexSingle * get_complex_singles () const { panic_impossible (); } + mxDouble * get_doubles () const { error_impossible_call ("mxArray_separate_full::get_doubles"); } + mxSingle * get_singles () const { error_impossible_call ("mxArray_separate_full::get_singles"); } + mxInt8 * get_int8s () const { error_impossible_call ("mxArray_separate_full::get_int8s"); } + mxInt16 * get_int16s () const { error_impossible_call ("mxArray_separate_full::get_int16s"); } + mxInt32 * get_int32s () const { error_impossible_call ("mxArray_separate_full::get_int32s"); } + mxInt64 * get_int64s () const { error_impossible_call ("mxArray_separate_full::get_int64s"); } + mxUint8 * get_uint8s () const { error_impossible_call ("mxArray_separate_full::get_uint8s"); } + mxUint16 * get_uint16s () const { error_impossible_call ("mxArray_separate_full::get_uint16s"); } + mxUint32 * get_uint32s () const { error_impossible_call ("mxArray_separate_full::get_uint32s"); } + mxUint64 * get_uint64s () const { error_impossible_call ("mxArray_separate_full::get_uint64s"); } + + mxComplexDouble * get_complex_doubles () const { error_impossible_call ("mxArray_separate_full::get_complex_doubles"); } + mxComplexSingle * get_complex_singles () const { error_impossible_call ("mxArray_separate_full::get_complex_singles"); } // We don't have complex integer types, but for separate storage they // still would not work. - mxComplexInt8 * get_complex_int8s () const { panic_impossible (); } - mxComplexInt16 * get_complex_int16s () const { panic_impossible (); } - mxComplexInt32 * get_complex_int32s () const { panic_impossible (); } - mxComplexInt64 * get_complex_int64s () const { panic_impossible (); } - mxComplexUint8 * get_complex_uint8s () const { panic_impossible (); } - mxComplexUint16 * get_complex_uint16s () const { panic_impossible (); } - mxComplexUint32 * get_complex_uint32s () const { panic_impossible (); } - mxComplexUint64 * get_complex_uint64s () const { panic_impossible (); } - - int set_doubles (mxDouble *) { panic_impossible (); } - int set_singles (mxSingle *) { panic_impossible (); } - int set_int8s (mxInt8 *) { panic_impossible (); } - int set_int16s (mxInt16 *) { panic_impossible (); } - int set_int32s (mxInt32 *) { panic_impossible (); } - int set_int64s (mxInt64 *) { panic_impossible (); } - int set_uint8s (mxUint8 *) { panic_impossible (); } - int set_uint16s (mxUint16 *) { panic_impossible (); } - int set_uint32s (mxUint32 *) { panic_impossible (); } - int set_uint64s (mxUint64 *) { panic_impossible (); } - - int set_complex_doubles (mxComplexDouble *) { panic_impossible (); } - int set_complex_singles (mxComplexSingle *) { panic_impossible (); } + mxComplexInt8 * get_complex_int8s () const { error_impossible_call ("mxArray_separate_full::get_complex_int8s"); } + mxComplexInt16 * get_complex_int16s () const { error_impossible_call ("mxArray_separate_full::get_complex_int16s"); } + mxComplexInt32 * get_complex_int32s () const { error_impossible_call ("mxArray_separate_full::get_complex_int32s"); } + mxComplexInt64 * get_complex_int64s () const { error_impossible_call ("mxArray_separate_full::get_complex_int64s"); } + mxComplexUint8 * get_complex_uint8s () const { error_impossible_call ("mxArray_separate_full::get_complex_uint8s"); } + mxComplexUint16 * get_complex_uint16s () const { error_impossible_call ("mxArray_separate_full::get_complex_uint16s"); } + mxComplexUint32 * get_complex_uint32s () const { error_impossible_call ("mxArray_separate_full::get_complex_uint32s"); } + mxComplexUint64 * get_complex_uint64s () const { error_impossible_call ("mxArray_separate_full::get_complex_uint64s"); } + + int set_doubles (mxDouble *) { error_impossible_call ("mxArray_separate_full::set_doubles"); } + int set_singles (mxSingle *) { error_impossible_call ("mxArray_separate_full::set_singles"); } + int set_int8s (mxInt8 *) { error_impossible_call ("mxArray_separate_full::set_int8s"); } + int set_int16s (mxInt16 *) { error_impossible_call ("mxArray_separate_full::set_int16s"); } + int set_int32s (mxInt32 *) { error_impossible_call ("mxArray_separate_full::set_int32s"); } + int set_int64s (mxInt64 *) { error_impossible_call ("mxArray_separate_full::set_int64s"); } + int set_uint8s (mxUint8 *) { error_impossible_call ("mxArray_separate_full::set_uint8s"); } + int set_uint16s (mxUint16 *) { error_impossible_call ("mxArray_separate_full::set_uint16s"); } + int set_uint32s (mxUint32 *) { error_impossible_call ("mxArray_separate_full::set_uint32s"); } + int set_uint64s (mxUint64 *) { error_impossible_call ("mxArray_separate_full::set_uint64s"); } + + int set_complex_doubles (mxComplexDouble *) { error_impossible_call ("mxArray_separate_full::set_complex_doubles"); } + int set_complex_singles (mxComplexSingle *) { error_impossible_call ("mxArray_separate_full::set_complex_singles"); } // We don't have complex integer types, but for separate storage they // still would not work. - int set_complex_int8s (mxComplexInt8 *) { panic_impossible (); } - int set_complex_int16s (mxComplexInt16 *) { panic_impossible (); } - int set_complex_int32s (mxComplexInt32 *) { panic_impossible (); } - int set_complex_int64s (mxComplexInt64 *) { panic_impossible (); } - int set_complex_uint8s (mxComplexUint8 *) { panic_impossible (); } - int set_complex_uint16s (mxComplexUint16 *) { panic_impossible (); } - int set_complex_uint32s (mxComplexUint32 *) { panic_impossible (); } - int set_complex_uint64s (mxComplexUint64 *) { panic_impossible (); } + int set_complex_int8s (mxComplexInt8 *) { error_impossible_call ("mxArray_separate_full::set_complex_int8s"); } + int set_complex_int16s (mxComplexInt16 *) { error_impossible_call ("mxArray_separate_full::set_complex_int16s"); } + int set_complex_int32s (mxComplexInt32 *) { error_impossible_call ("mxArray_separate_full::set_complex_int32s"); } + int set_complex_int64s (mxComplexInt64 *) { error_impossible_call ("mxArray_separate_full::set_complex_int64s"); } + int set_complex_uint8s (mxComplexUint8 *) { error_impossible_call ("mxArray_separate_full::set_complex_uint8s"); } + int set_complex_uint16s (mxComplexUint16 *) { error_impossible_call ("mxArray_separate_full::set_complex_uint16s"); } + int set_complex_uint32s (mxComplexUint32 *) { error_impossible_call ("mxArray_separate_full::set_complex_uint32s"); } + int set_complex_uint64s (mxComplexUint64 *) { error_impossible_call ("mxArray_separate_full::set_complex_uint64s"); } octave_value as_octave_value () const { @@ -2536,9 +2542,9 @@ ~mxArray_interleaved_sparse () = default; - void * get_imag_data () const { panic_impossible (); } - - void set_imag_data (void */*pi*/) { panic_impossible (); } + void * get_imag_data () const { error_impossible_call ("mxArray_interleaved_sparse::get_imag_data"); } + + void set_imag_data (void */*pi*/) { error_impossible_call ("mxArray_interleaved_sparse::set_imag_data"); } }; class mxArray_separate_sparse : public mxArray_base_sparse @@ -2592,11 +2598,11 @@ set_complexity (m_pi != nullptr); } - mxDouble * get_doubles () const { panic_impossible (); } - mxComplexDouble * get_complex_doubles () const { panic_impossible (); } - - int set_doubles (mxDouble *) { panic_impossible (); } - int set_complex_doubles (mxComplexDouble *) { panic_impossible (); } + mxDouble * get_doubles () const { error_impossible_call ("mxArray_separate_sparse::get_doubles"); } + mxComplexDouble * get_complex_doubles () const { error_impossible_call ("mxArray_separate_sparse::get_complex_doubles"); } + + int set_doubles (mxDouble *) { error_impossible_call ("mxArray_separate_sparse::set_doubles"); } + int set_complex_doubles (mxComplexDouble *) { error_impossible_call ("mxArray_separate_sparse::set_complex_doubles"); } octave_value as_octave_value () const { diff -r 3606817b9994 -r 56d234504c01 libinterp/corefcn/stack-frame.cc --- a/libinterp/corefcn/stack-frame.cc Sat Apr 06 14:38:17 2024 -0400 +++ b/libinterp/corefcn/stack-frame.cc Sat Apr 06 17:11:35 2024 -0400 @@ -1302,7 +1302,7 @@ // scope_stack_frame objects. Anything else indicates an error in // the implementation. - panic_impossible (); + error ("unexpected call to stack_frame::size () - please report this bug"); } void @@ -1312,7 +1312,7 @@ // scope_stack_frame objects. Anything else indicates an error in // the implementation. - panic_impossible (); + error ("unexpected call to stack_frame::resize () - please report this bug"); } stack_frame::scope_flags @@ -1322,7 +1322,7 @@ // scope_stack_frame objects. Anything else indicates an error in // the implementation. - panic_impossible (); + error ("unexpected call to stack_frame::get_scope_flag (std::size_t) - please report this bug"); } void @@ -1332,7 +1332,7 @@ // scope_stack_frame objects. Anything else indicates an error in // the implementation. - panic_impossible (); + error ("unexpected call to stack_frame::get_scope_flag (std::size_t, scope_flags) - please report this bug"); } void @@ -1389,7 +1389,7 @@ // scope_stack_frame objects. Anything else indicates an error in // the implementation. - panic_impossible (); + error ("unexpected call to stack_frame::varval (std::size_t) - please report this bug"); } octave_value& @@ -1399,7 +1399,7 @@ // scope_stack_frame objects. Anything else indicates an error in // the implementation. - panic_impossible (); + error ("unexpected call to stack_frame::varref (std::size_t) - please report this bug"); } std::string @@ -1408,7 +1408,7 @@ // This function should only be called for user_fcn_stack_frame. // Anything else indicates an error in the implementation. - panic_impossible (); + error ("unexpected call to stack_frame::inputname (int, bool) - please report this bug"); } void @@ -1705,7 +1705,8 @@ // scope. If the symbol wasn't present before, it should be outside // the range so we need to resize then update offsets. - panic_unless (data_offset >= size ()); + if (data_offset < size ()) + error ("unexpected: data_offset < size () in script_stack_frame::resize_and_update_script_offsets - please report this bug"); resize (data_offset+1); @@ -1758,7 +1759,8 @@ if (sym) { - panic_unless (sym.frame_offset () == 0); + if (sym.frame_offset () != 0) + error ("unexpected: sym.frame_offset () != 0 in script_stack_frame::lookup_symbol - please report this bug"); return sym; } @@ -1788,7 +1790,9 @@ // All symbol records in a script scope should have zero offset, // which means we redirect our lookup using // lexical_frame_offsets and values_offets. - panic_unless (sym.frame_offset () == 0); + + if (sym.frame_offset () != 0) + error ("unexpected: sym.frame_offset () != 0 in script_stack_frame::insert_symbol - please report this bug"); return sym; } @@ -1798,7 +1802,8 @@ sym = scope.find_symbol (name); - panic_unless (sym.is_valid ()); + if (! sym.is_valid ()) + error ("unexpected: sym is not valid in script_stack_frame::insert_symbol - please report this bug"); resize_and_update_script_offsets (sym); @@ -2342,7 +2347,8 @@ sym = scope.find_symbol (name); - panic_unless (sym.is_valid ()); + if (! sym.is_valid ()) + error ("unexpected: sym is not valid in user_fcn_stack_frame::insert_symbol - please report this bug"); return sym; } @@ -2535,7 +2541,8 @@ sym = m_scope.find_symbol (name); - panic_unless (sym.is_valid ()); + if (! sym.is_valid ()) + error ("unexpected: sym is not valid in scope_stack_frame::insert_symbol - please report this bug"); return sym; } diff -r 3606817b9994 -r 56d234504c01 libinterp/octave-value/ov-base-mat.cc --- a/libinterp/octave-value/ov-base-mat.cc Sat Apr 06 14:38:17 2024 -0400 +++ b/libinterp/octave-value/ov-base-mat.cc Sat Apr 06 17:11:35 2024 -0400 @@ -60,7 +60,7 @@ break; default: - panic_impossible (); + error ("unexpected: index not '(', '{', or '.' in octave_base_matrix::simple_subsref - please report this bug"); } } diff -r 3606817b9994 -r 56d234504c01 libinterp/octave-value/ov-fcn.cc --- a/libinterp/octave-value/ov-fcn.cc Sat Apr 06 14:38:17 2024 -0400 +++ b/libinterp/octave-value/ov-fcn.cc Sat Apr 06 17:11:35 2024 -0400 @@ -42,25 +42,25 @@ octave_base_value * octave_function::clone () const { - panic_impossible (); + error ("unexpected call to octave_function::clone - please report this bug"); } octave_base_value * octave_function::empty_clone () const { - panic_impossible (); + error ("unexpected call to octave_function::empty_clone - please report this bug"); } octave::filepos octave_function::beg_pos () const { - panic_impossible (); + error ("unexpected call to octave_function::beg_pos - please report this bug"); } octave::filepos octave_function::end_pos () const { - panic_impossible (); + error ("unexpected call to octave_function::end_pos - please report this bug"); } octave_value_list diff -r 3606817b9994 -r 56d234504c01 libinterp/octave-value/ov.cc --- a/libinterp/octave-value/ov.cc Sat Apr 06 14:38:17 2024 -0400 +++ b/libinterp/octave-value/ov.cc Sat Apr 06 17:11:35 2024 -0400 @@ -2570,7 +2570,7 @@ return octave_scalar_map (); default: - panic_impossible (); + error ("unexpected: index not '(', '{', or '.' in octave_value::empty_conv - please report this bug"); } } else diff -r 3606817b9994 -r 56d234504c01 libinterp/operators/ops.h --- a/libinterp/operators/ops.h Sat Apr 06 14:38:17 2024 -0400 +++ b/libinterp/operators/ops.h Sat Apr 06 17:11:35 2024 -0400 @@ -138,34 +138,37 @@ } // FIXME: the following currently don't handle index. -#define DEFNDASSIGNOP_OP(name, t1, t2, f, op) \ - static octave_value \ - CONCAT2 (oct_assignop_, name) (octave_base_value& a1, \ - const octave_value_list& idx, \ - const octave_base_value& a2) \ - { \ - OCTAVE_CAST_BASE_VALUE (CONCAT2 (octave_, t1)&, v1, a1); \ - OCTAVE_CAST_BASE_VALUE (const CONCAT2 (octave_, t2)&, v2, a2); \ - \ - panic_unless (idx.empty ()); \ - v1.matrix_ref () op v2.CONCAT2 (f, _value) (); \ - \ - return octave_value (); \ + +#define DEFNDASSIGNOP_OP(name, t1, t2, f, op) \ + static octave_value \ + CONCAT2 (oct_assignop_, name) (octave_base_value& a1, \ + const octave_value_list& idx, \ + const octave_base_value& a2) \ + { \ + OCTAVE_CAST_BASE_VALUE (CONCAT2 (octave_, t1)&, v1, a1); \ + OCTAVE_CAST_BASE_VALUE (const CONCAT2 (octave_, t2)&, v2, a2); \ + \ + if (! idx.empty ()) \ + error ("unexpected: index is not empty in oct_assignop_ " #name " - please report this bug"); \ + v1.matrix_ref () op v2.CONCAT2 (f, _value) (); \ + \ + return octave_value (); \ } -#define DEFNDASSIGNOP_FNOP(name, t1, t2, f, fnop) \ - static octave_value \ - CONCAT2 (oct_assignop_, name) (octave_base_value& a1, \ - const octave_value_list& idx, \ - const octave_base_value& a2) \ - { \ - OCTAVE_CAST_BASE_VALUE (CONCAT2 (octave_, t1)&, v1, a1); \ - OCTAVE_CAST_BASE_VALUE (const CONCAT2 (octave_, t2)&, v2, a2); \ - \ - panic_unless (idx.empty ()); \ - fnop (v1.matrix_ref (), v2.CONCAT2 (f, _value) ()); \ - \ - return octave_value (); \ +#define DEFNDASSIGNOP_FNOP(name, t1, t2, f, fnop) \ + static octave_value \ + CONCAT2 (oct_assignop_, name) (octave_base_value& a1, \ + const octave_value_list& idx, \ + const octave_base_value& a2) \ + { \ + OCTAVE_CAST_BASE_VALUE (CONCAT2 (octave_, t1)&, v1, a1); \ + OCTAVE_CAST_BASE_VALUE (const CONCAT2 (octave_, t2)&, v2, a2); \ + \ + if (! idx.empty ()) \ + error ("unexpected: index is not empty in oct_assignop_ " #name " - please report this bug"); \ + fnop (v1.matrix_ref (), v2.CONCAT2 (f, _value) ()); \ + \ + return octave_value (); \ } #define DEFASSIGNANYOP_FN(name, t1, f) \ diff -r 3606817b9994 -r 56d234504c01 libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll Sat Apr 06 14:38:17 2024 -0400 +++ b/libinterp/parse-tree/lex.ll Sat Apr 06 17:11:35 2024 -0400 @@ -3104,14 +3104,10 @@ *p = '\0'; double value = 0.0; - int nread = 0; - - nread = sscanf (tmptxt, "%lf", &value); - - // Panic instead of error because if yytext doesn't contain a valid - // number, we are in deep doo doo. - - panic_unless (nread == 1); + int nread = sscanf (tmptxt, "%lf", &value); + + if (nread != 1) + error ("unexpected: nread != 1 in base_lexer::handle_number<10> - please report this bug"); octave_value ov_value; @@ -3221,7 +3217,9 @@ uintmax_t long_int_val; int status = sscanf (yytxt.c_str (), "%jx", &long_int_val); - panic_unless (status); + + if (status == 0) + error ("unexpected: sscanf failed in base_lexer::handle_number<16> - please report this bug"); octave_value ov_value = make_integer_value (long_int_val, unsigned_val, bytes); diff -r 3606817b9994 -r 56d234504c01 libinterp/parse-tree/oct-lvalue.cc --- a/libinterp/parse-tree/oct-lvalue.cc Sat Apr 06 14:38:17 2024 -0400 +++ b/libinterp/parse-tree/oct-lvalue.cc Sat Apr 06 17:11:35 2024 -0400 @@ -168,7 +168,7 @@ break; default: - panic_impossible (); + error ("unexpected: index not '(', '{', or '.' in octave_lvalue::numel - please report this bug"); } } diff -r 3606817b9994 -r 56d234504c01 libinterp/parse-tree/pt-idx.cc --- a/libinterp/parse-tree/pt-idx.cc Sat Apr 06 14:38:17 2024 -0400 +++ b/libinterp/parse-tree/pt-idx.cc Sat Apr 06 17:11:35 2024 -0400 @@ -141,21 +141,26 @@ if (n == 0) return m_expr->end_pos (); - char idx_type = m_type[n-1]; - - if (idx_type == '(' || idx_type == '{') + switch (m_type[n-1]) { - tree_argument_list *args = m_args.back (); - return args->end_pos (); - } + case '(': + case '{': + { + tree_argument_list *args = m_args.back (); + return args->end_pos (); + } + break; - if (idx_type == '.') - { - tree_expression *dyn_field = m_dyn_field.back (); - return dyn_field->end_pos (); + case '.': + { + tree_expression *dyn_field = m_dyn_field.back (); + return dyn_field->end_pos (); + } + + default: + error ("unexpected: index not '(', '{', or '.' in tree_index_expression::end_pos - please report this bug"); + break; } - - panic_impossible (); } std::string diff -r 3606817b9994 -r 56d234504c01 liboctave/array/Array-util.cc --- a/liboctave/array/Array-util.cc Sat Apr 06 14:38:17 2024 -0400 +++ b/liboctave/array/Array-util.cc Sat Apr 06 17:11:35 2024 -0400 @@ -337,7 +337,9 @@ int n = frozen_lengths.ndims (); - liboctave_panic_unless (idx_n == n); + if (idx_n != n) + (*current_liboctave_error_handler) + ("unexpected: idx_n != n in all_colon_equiv - please report this bug"); for (octave_idx_type i = 0; i < n; i++) {