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

 
 

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

Submitted by:  Dmitry Messerman <mdmitry>
Submitted on:  Sat 21 Jan 2017 12:18:59 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: NoneAssigned to: None
Originator Name: Dmitry MessermanOpen/Closed: Open
Release: 4.2.0Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    No Changes Have Been Made to This Item

    Back to the top


    Powered by Savane 3.1-cleanup1