bugGNU Octave - Bugs: bug #50111, In embedded mode Octave parser not...

 
 

bug #50111: In embedded mode Octave parser not always reports parse error

Submitter:  Dmitry Messerman <mdmitry>
Submitted:  Sat 21 Jan 2017 12:18:59 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Dmitry Messerman Open/Closed:  * Open
Release:  * 4.2.0 Release: 
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 21 Jan 2017 12:18:59 PM UTC, original submission:  

The following code reports parse error only when at least one command line argument is supplied.
This happens because with command line arguments, source_file is called
twice.
First call loads binary file, second - tries to print value of undefined variable.
Without command line arguments, first call is skipped.
In this case, parse error is correctly reported.

#include <string>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>

// Workaround for bug http://savannah.gnu.org/bugs/?50068
// Recommended by John W. Eaton

bool _octave_init() {
  string_vector octave_argv (2);
  octave_argv(0) = "embedded";
  octave_argv(1) = "-q";
  static octave::embedded_application app (2, octave_argv.c_str_vec ());
  if (! app.execute ()) {
     std::cerr << "ERROR: Creating embedded Octave interpreter failed!" << std::endl;
     return false;
  }
  return true;
}

int main (int argc, char** argv) {

    if( !_octave_init() ) return 1;

    try {
        int parse_status;
        eval_string (std::string ("who"), 0, parse_status);
        system("echo a=5 >my_octave_file.m");
        system("octave -q --eval 'a=5; save(\"-binary\",\"my_octave_file.obm\",\"a\");'");
        system("echo load my_octave_file.obm >my_octave_file.m");
        system("cat my_octave_file.m");
        system("octave -q --eval 'load my_octave_file.obm; a'");
        if(argc < 2) {
            source_file("my_octave_file.m");
        }
        eval_string (std::string ("who"), 0, parse_status);
        system("echo junk >my_octave_file.m");
        system("cat my_octave_file.m");
        source_file("my_octave_file.m");
        eval_string (std::string ("who"), 0, parse_status);
    }
    catch (const octave::exit_exception& ex) {
        exit (ex.exit_status ());
    }
    catch (const octave::execution_exception&) {
        std::cerr << "error evaluating Octave code!" << std::endl;
    }
    std::cout << "Finished" << std::endl;
    // Workaround for another bug, discussion - see http://savannah.gnu.org/bugs/?50068
    try {
        clean_up_and_exit (0);
    } catch(...) { }
    std::_Exit(0); // Probably not needed in 4.2.0. Without sometimes main application crashed in previous versions
    return 0;
}

Dmitry Messerman <mdmitry>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mdmitry (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.15-e6e5.
    Corresponding source code