octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #50111] In embedded mode Octave parser not alw


From: Dmitry Messerman
Subject: [Octave-bug-tracker] [bug #50111] In embedded mode Octave parser not always reports parse error
Date: Sat, 21 Jan 2017 12:19:00 +0000 (UTC)
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0

URL:
  <http://savannah.gnu.org/bugs/?50111>

                 Summary: In embedded mode Octave parser not always reports
parse error
                 Project: GNU Octave
            Submitted by: mdmitry
            Submitted on: Sat 21 Jan 2017 02:18:59 PM IST
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: Dmitry Messerman
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.2.0
        Operating System: GNU/Linux

    _______________________________________________________

Details:

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;
}





    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50111>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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