Mercurial > octave
changeset 33358:09f32949dcb7 bytecode-interpreter
maint: Merge default to bytecode-interpreter
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Mon, 08 Apr 2024 17:07:57 -0400 |
parents | 1941a21c23b9 (current diff) c7bd12648bc2 (diff) |
children | 9108c5b24626 |
files | |
diffstat | 7 files changed, 150 insertions(+), 208 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/dialog.cc Sun Apr 07 13:40:32 2024 -0400 +++ b/libgui/src/dialog.cc Mon Apr 08 17:07:57 2024 -0400 @@ -631,6 +631,12 @@ const QString& dirname, const QString& multimode) : QFileDialog () { + gui_settings settings; + + // This should be set before any other dialog properties + if (! settings.bool_value (global_use_native_dialogs)) + setOption (QFileDialog::DontUseNativeDialog); + // Create a NonModal message. setWindowModality (Qt::NonModal); @@ -639,11 +645,6 @@ // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. - gui_settings settings; - - if (! settings.bool_value (global_use_native_dialogs)) - setOption(QFileDialog::DontUseNativeDialog); - if (multimode == "on") // uigetfile multiselect=on { setFileMode (QFileDialog::ExistingFiles);
--- a/libgui/src/m-editor/file-editor-tab.cc Sun Apr 07 13:40:32 2024 -0400 +++ b/libgui/src/m-editor/file-editor-tab.cc Mon Apr 08 17:07:57 2024 -0400 @@ -2579,109 +2579,119 @@ // reset m_new_encoding m_new_encoding = m_encoding; - // If the tab is removed in response to a QFileDialog signal, the tab - // can't be a parent. - QFileDialog *fileDialog; - if (remove_on_success) - { - // If tab is closed, "this" cannot be parent in which case modality - // has no effect. Disable editing instead. - m_edit_area->setReadOnly (true); - fileDialog = new QFileDialog (); - } - else - fileDialog = new QFileDialog (this); + QFileDialog fileDialog (this); gui_settings settings; if (! settings.bool_value (global_use_native_dialogs)) { // Qt file dialogs - fileDialog->setOption(QFileDialog::DontUseNativeDialog); + fileDialog.setOption(QFileDialog::DontUseNativeDialog); } else { // Native file dialogs: Test for already existing files is done manually // since native file dialogs might not consider the automatically // appended default extension when checking if the file already exists - fileDialog->setOption(QFileDialog::DontConfirmOverwrite); + fileDialog.setOption(QFileDialog::DontConfirmOverwrite); } // add the possible filters and the default suffix QStringList filters; filters << tr ("Octave Files (*.m)") << tr ("All Files (*)"); - fileDialog->setNameFilters (filters); - fileDialog->setDefaultSuffix ("m"); + fileDialog.setNameFilters (filters); if (valid_file_name ()) { - fileDialog->selectFile (m_file_name); + fileDialog.selectFile (m_file_name); QFileInfo file_info (m_file_name); if (file_info.suffix () != "m") - { - // it is not an octave file - fileDialog->selectNameFilter (filters.at (1)); // "All Files" - fileDialog->setDefaultSuffix (""); // no default suffix - } + fileDialog.selectNameFilter (filters.at (1)); // "All Files" } else { - fileDialog->selectFile (""); - fileDialog->setDirectory (m_ced); + fileDialog.selectFile (""); + fileDialog.setDirectory (m_ced); // propose a name corresponding to the function name // if the new file contains a function QString fname = get_function_name (); if (! fname.isEmpty ()) - fileDialog->selectFile (fname + ".m"); + fileDialog.selectFile (fname + ".m"); } - fileDialog->setAcceptMode (QFileDialog::AcceptSave); - fileDialog->setViewMode (QFileDialog::Detail); - fileDialog->setOption (QFileDialog::HideNameFilterDetails, false); - - // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. - - connect (fileDialog, &QFileDialog::filterSelected, - this, &file_editor_tab::handle_save_as_filter_selected); - - if (remove_on_success) - { - connect (fileDialog, &QFileDialog::fileSelected, - this, &file_editor_tab::handle_save_file_as_answer_close); - - connect (fileDialog, &QFileDialog::rejected, - this, &file_editor_tab::handle_save_file_as_answer_cancel); - } - else + fileDialog.setAcceptMode (QFileDialog::AcceptSave); + fileDialog.setViewMode (QFileDialog::Detail); + fileDialog.setOption (QFileDialog::HideNameFilterDetails, false); + + if (fileDialog.exec ()) // Modal dialog { - connect (fileDialog, &QFileDialog::fileSelected, - this, &file_editor_tab::handle_save_file_as_answer); + // Accepted file dialog, no actions required if rejected + + QString save_file_name = fileDialog.selectedFiles ().at (0); + + if (remove_on_success) + { + // Remove the tab after save + if (check_valid_identifier (save_file_name)) + save_file_as (true); + else + emit editor_check_conflict_save (save_file_name, true); + } + else + { + // Save the file under the selected name + + QFileInfo file (save_file_name); + + // Make sure that the file has the desire suffix + QString filter = fileDialog.selectedNameFilter (); + QRegularExpression rx {"\\*\\.([^ ^\\)]*)[ \\)]"}; // regexp for suffix in filter + QRegularExpressionMatch match = rx.match (filter); + + bool file_name_changed = false; + if (match.hasMatch () && file.suffix ().isEmpty ()) + { + save_file_name = save_file_name + "." + match.captured (1); + file_name_changed = true; + } + + // Use final file name + file.setFile (save_file_name); + + // Check if overwrite has to checked again + if ((file_name_changed || fileDialog.testOption (QFileDialog::DontConfirmOverwrite)) + && file.exists ()) + { + int ans = QMessageBox::question (this, + tr ("Octave Editor"), + tr ("%1\n already exists\n" + "Do you want to overwrite it?").arg (save_file_name), + QMessageBox::Yes | QMessageBox::No); + if (ans != QMessageBox::Yes) + { + // Try again, if edit area is read only, remove on success + save_file_as (remove_on_success); + return; + } + } + + if (save_file_name == m_file_name) + { + save_file (save_file_name); + } + else + { + // Have editor check for conflict, do not delete tab after save. + if (check_valid_identifier (save_file_name)) + save_file_as (false); + else + emit editor_check_conflict_save (save_file_name, false); + } + + } } - - show_dialog (fileDialog, ! valid_file_name ()); -} - -void -file_editor_tab::handle_save_as_filter_selected (const QString& filter) -{ - // On some systems, the filterSelected signal is emitted without user - // action and with an empty filter string when the file dialog is shown. - // Just return in this case and do not remove the current default suffix. - if (filter.isEmpty ()) - return; - - QFileDialog *file_dialog = qobject_cast<QFileDialog *> (sender ()); - - // regexp for suffix in filter - QRegularExpression rx {"\\*\\.([^ ^\\)]*)[ \\)]"}; - QRegularExpressionMatch match = rx.match (filter); - - if (match.hasMatch ()) - file_dialog->setDefaultSuffix (match.captured (1)); // found a suffix, set default - else - file_dialog->setDefaultSuffix (""); // not found, clear default } bool @@ -2769,74 +2779,6 @@ } void -file_editor_tab::handle_save_file_as_answer (const QString& save_file_name) -{ - QString saveFileName = save_file_name; - QFileInfo file (saveFileName); - QFileDialog *file_dialog = qobject_cast<QFileDialog *> (sender ()); - - // Test if the file dialog should have added a default file - // suffix, but the selected file still has no suffix (see Qt bug - // https://bugreports.qt.io/browse/QTBUG-59401) - if ((! file_dialog->defaultSuffix ().isEmpty ()) && file.suffix ().isEmpty ()) - { - saveFileName = saveFileName + "." + file_dialog->defaultSuffix (); - } - - file.setFile (saveFileName); - - // If overwrite confirmation was not done by the file dialog (in case - // of native file dialogs, see above), do it here - if (file_dialog->testOption (QFileDialog::DontConfirmOverwrite) && file.exists ()) - { - int ans = QMessageBox::question (file_dialog, - tr ("Octave Editor"), - tr ("%1\n already exists\n" - "Do you want to overwrite it?").arg (saveFileName), - QMessageBox::Yes | QMessageBox::No); - if (ans != QMessageBox::Yes) - { - // Try again, if edit area is read only, remove on success - save_file_as (m_edit_area->isReadOnly ()); - return; - } - } - - if (saveFileName == m_file_name) - { - save_file (saveFileName); - } - else - { - // Have editor check for conflict, do not delete tab after save. - if (check_valid_identifier (saveFileName)) - save_file_as (false); - else - emit editor_check_conflict_save (saveFileName, false); - } -} - -void -file_editor_tab::handle_save_file_as_answer_close (const QString& saveFileName) -{ - // saveFileName == m_file_name can not happen, because we only can get here - // when we close a tab and m_file_name is not a valid filename yet - - // Have editor check for conflict, delete tab after save. - if (check_valid_identifier (saveFileName)) - save_file_as (true); - else - emit editor_check_conflict_save (saveFileName, true); -} - -void -file_editor_tab::handle_save_file_as_answer_cancel () -{ - // User canceled, allow editing again. - m_edit_area->setReadOnly (false); -} - -void file_editor_tab::file_has_changed (const QString&, bool do_close) { bool file_exists = QFile::exists (m_file_name);
--- a/libgui/src/m-editor/file-editor-tab.h Sun Apr 07 13:40:32 2024 -0400 +++ b/libgui/src/m-editor/file-editor-tab.h Mon Apr 08 17:07:57 2024 -0400 @@ -218,12 +218,6 @@ // When user closes message box for resave question. void handle_file_resave_answer (int decision); - // When user closes QFileDialog box. - void handle_save_file_as_answer (const QString& fileName); - void handle_save_file_as_answer_close (const QString& fileName); - void handle_save_file_as_answer_cancel (); - void handle_save_as_filter_selected (const QString& filter); - // When user changes encoding after decoding errors were found void handle_current_enc_changed (const QString& enc);
--- a/libgui/src/main-window.cc Sun Apr 07 13:40:32 2024 -0400 +++ b/libgui/src/main-window.cc Mon Apr 08 17:07:57 2024 -0400 @@ -1381,25 +1381,25 @@ if (is_internal) p = m_editor_window; - QFileDialog *fileDialog = new QFileDialog (p); + QFileDialog fileDialog (p); // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. if (! settings.bool_value (global_use_native_dialogs)) - fileDialog->setOption(QFileDialog::DontUseNativeDialog); - - fileDialog->setNameFilter (tr ("Octave Files (*.m);;All Files (*)")); - - fileDialog->setAcceptMode (QFileDialog::AcceptOpen); - fileDialog->setViewMode (QFileDialog::Detail); - fileDialog->setFileMode (QFileDialog::ExistingFiles); - fileDialog->setDirectory (m_current_directory_combo_box->itemText (0)); - - connect (fileDialog, &QFileDialog::filesSelected, - this, &main_window::request_open_files); - - fileDialog->setWindowModality (Qt::NonModal); - fileDialog->setAttribute (Qt::WA_DeleteOnClose); - fileDialog->show (); + fileDialog.setOption(QFileDialog::DontUseNativeDialog); + + fileDialog.setNameFilter (tr ("Octave Files (*.m);;All Files (*)")); + + fileDialog.setAcceptMode (QFileDialog::AcceptOpen); + fileDialog.setViewMode (QFileDialog::Detail); + fileDialog.setFileMode (QFileDialog::ExistingFiles); + fileDialog.setDirectory (m_current_directory_combo_box->itemText (0)); + + if (fileDialog.exec ()) + { + QStringList open_file_names = fileDialog.selectedFiles(); + for (int i = 0; i < open_file_names.count (); i++) + emit open_file_signal (open_file_names.at (i), m_file_encoding, -1); + } } // Create a new script @@ -2013,16 +2013,6 @@ m_file_encoding = new_encoding; } -// The following slot is called after files have been selected in the -// open file dialog, possibly with a new selected encoding stored in -// m_file_encoding -void -main_window::request_open_files (const QStringList& open_file_names) -{ - for (int i = 0; i < open_file_names.count (); i++) - emit open_file_signal (open_file_names.at (i), m_file_encoding, -1); -} - void main_window::profiler_session () {
--- a/libgui/src/main-window.h Sun Apr 07 13:40:32 2024 -0400 +++ b/libgui/src/main-window.h Mon Apr 08 17:07:57 2024 -0400 @@ -247,7 +247,7 @@ void disable_menu_shortcuts (bool disable); void restore_create_file_setting (); void set_file_encoding (const QString& new_encoding); - void request_open_files (const QStringList& open_file_names); +// void request_open_files (const QStringList& open_file_names); void warning_function_not_found (const QString& message);
--- a/libinterp/octave-value/ov-java.cc Sun Apr 07 13:40:32 2024 -0400 +++ b/libinterp/octave-value/ov-java.cc Mon Apr 08 17:07:57 2024 -0400 @@ -641,6 +641,7 @@ return jvm_lib_path; } + #endif //! Initialize the java virtual machine (jvm) and field #jvm if necessary. @@ -905,6 +906,12 @@ #endif +OCTAVE_NORETURN static void +error_unexpected (const char *name) +{ + error ("unexpected call to %s when HAVE_JAVA is not defined - please report this bug", name); +} + bool octave_java::is_java_string () const { @@ -925,7 +932,7 @@ // This shouldn't happen because construction of octave_java objects is // supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::is_java_string"); #endif } @@ -957,7 +964,7 @@ // This shouldn't happen because construction of octave_java objects is // supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::is_instance_of"); #endif } @@ -2183,7 +2190,7 @@ // This shouldn't happen because construction of octave_java objects is // supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::dims"); #endif } @@ -2248,7 +2255,7 @@ // This shouldn't happen because construction of octave_java objects is // supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::subsref"); #endif } @@ -2338,7 +2345,7 @@ // This shouldn't happen because construction of octave_java objects is // supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::subsasgn"); #endif } @@ -2360,7 +2367,7 @@ // This shouldn't happen because construction of octave_java objects is // supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::map_keys"); #endif } @@ -2386,7 +2393,7 @@ // This shouldn't happen because construction of octave_java objects is // supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::convert_to_str_internal"); #endif } @@ -2496,7 +2503,7 @@ // This shouldn't happen because construction of octave_java objects is // supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_javaMethod"); #endif } @@ -2517,7 +2524,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_javaMethod"); #endif } @@ -2577,7 +2584,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_javaMethod"); #endif } @@ -2600,7 +2607,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_javaMethod"); #endif } @@ -2656,7 +2663,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_javaObject"); #endif } @@ -2677,7 +2684,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_javaObject"); #endif } @@ -2723,7 +2730,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_java_get"); #endif } @@ -2742,7 +2749,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_java_get"); #endif } @@ -2790,7 +2797,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_java_get"); #endif } @@ -2811,7 +2818,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_java_get"); #endif } @@ -2858,7 +2865,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_java_set"); #endif } @@ -2878,7 +2885,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_java_set"); #endif } @@ -2929,7 +2936,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_java_set"); #endif } @@ -2952,7 +2959,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::do_java_set"); #endif } @@ -3002,7 +3009,7 @@ // This shouldn't happen because construction of octave_java // objects is supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::init"); #endif } @@ -3031,7 +3038,7 @@ // This shouldn't happen because construction of octave_java objects is // supposed to be impossible if Java is not available. - panic_impossible (); + error_unexpected ("octave_java::release"); #endif }
--- a/libinterp/parse-tree/lex.ll Sun Apr 07 13:40:32 2024 -0400 +++ b/libinterp/parse-tree/lex.ll Mon Apr 08 17:07:57 2024 -0400 @@ -2108,7 +2108,7 @@ lexical_feedback::symbol_table_context::pop () { if (empty ()) - panic_impossible (); + error ("unexpected: empty stack in lexical_feedback::symbol_table_context::pop - please report this bug"); m_frame_stack.pop_front (); } @@ -2358,7 +2358,9 @@ else len = max_size > m_chars_left ? m_chars_left : max_size; - panic_unless (len > 0); + if (len <= 0) + error ("unexpected: buffer underflow in base_lexer::input_buffer::copy_chunk - please report this bug"); + memcpy (buf, m_buffer.c_str () + m_offset, len); m_chars_left -= len; @@ -2912,6 +2914,12 @@ return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); } +OCTAVE_NORETURN static void +error_unexpected_bytes (int bytes) +{ + error ("unexpected: bytes (= %d) not 1, 2, 4, or 8 in make_integer_value - please report this bug", bytes); +} + static inline octave_value make_integer_value (uintmax_t long_int_val, bool unsigned_val, int bytes) { @@ -2932,7 +2940,7 @@ return octave_value (octave_uint64 (long_int_val)); default: - panic_impossible (); + error_unexpected_bytes (bytes); }; } else @@ -2955,7 +2963,7 @@ return octave_value (octave_int64 (int64_t (long_int_val))); default: - panic_impossible (); + error_unexpected_bytes (bytes); }; } @@ -3025,10 +3033,10 @@ else if (sizeof (uintmax_t) == sizeof (unsigned long)) long_int_val = strtoul (yytxt.c_str (), &end, 2); else - panic_impossible (); + error ("unexpected: size mismatch: uintmax_t vs unsigned long or unsigned long long in base_lexer::handle_number<2> - please report this bug"); if (errno == ERANGE) - panic_impossible (); + error ("unexpected: ERANGE error in base_lexer::handle_number<2> - please report this bug"); octave_value ov_value = make_integer_value (long_int_val, unsigned_val, bytes); @@ -3130,7 +3138,7 @@ else if (sizeof (uintmax_t) == sizeof (unsigned long)) long_int_val = strtoul (tmptxt, &end, 10); else - panic_impossible (); + error ("unexpected: size mismatch: uintmax_t vs unsigned long or unsigned long long in base_lexer::handle_number<10> - please report this bug"); if (errno != ERANGE) { @@ -3212,8 +3220,7 @@ return syntax_error (msg); } - // Panic instead of error here because if yytext doesn't contain a - // valid number, we are in deep doo doo. + // If yytext doesn't contain a valid number, we are in deep doo doo. uintmax_t long_int_val; int status = sscanf (yytxt.c_str (), "%jx", &long_int_val); @@ -3331,7 +3338,7 @@ else if (bracket_type == '}') m_braceflag--; else - panic_impossible (); + error ("unexpected: bracket_type not ']' or '}' in base_lexer::handle_close_bracket - please report this bug"); } pop_start_state (); @@ -4053,7 +4060,8 @@ // input_buffer::copy_chunk, simply insert the marker directly // in BUF. - panic_unless (max_size > 0); + if (max_size <= 0) + error ("unexpected: max_size <= 0 in push_lexer::fill_flex_buffer - please report this bug"); buf[0] = static_cast<char> (1); status = 1;