bugGNU Octave - Bugs: bug #42064, executing empty m-file as a...

 
 

bug #42064: executing empty m-file as a command fails

Submitter:  Michael Godfrey <godfrey>
Submitted:  Mon 07 Apr 2014 12:01:56 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  jwe
Originator Name:  Godfrey Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 23 May 2014 04:23:13 PM UTC, comment #9: 

I checked in the following change.  It seems to fix the problem for me, though maybe we should also do something about dealing with the possibility of load_fcn_from file returning 0.

http://hg.savannah.gnu.org/hgweb/octave/rev/4293f49795d9

John W. Eaton <jwe>
Group administrator
Mon 14 Apr 2014 03:11:40 PM UTC, comment #8: 

Sounds right, but not simple to fix.
An obvious workaround is:

if exist("cd_data.m", "file")
   if(fileread("cd_data.m") > 0)
     cd_data;
   endif
endif

So that the file is not read if it exists but is
empty.

Still not Matlab compatible, and misleading error
message.

Michael Godfrey <godfrey>
Group Member
Mon 14 Apr 2014 02:35:20 PM UTC, comment #7: 

I assigned this to bug to myself, but if someone else wants to look at it, just let me know.

John W. Eaton <jwe>
Group administrator
Mon 14 Apr 2014 02:24:51 PM UTC, comment #6: 

The issue is that parse_fcn_file returns a null pointer when the file is completely empty.  I can see how this makes sense from a parsing perspective, since there isn't anything in the file, but it does lead to this bug.  Here is the backtrace:


#0  parse_fcn_file (full_file=..., file=..., dispatch_type=..., package_name=...,
    require_file=true, force_script=false, autoload=false, relative_lookup=true,
    warn_for=...) at oct-parse.yy:3880
#1  0x00007ffff6e69e04 in load_fcn_from_file (file_name=..., dir_name=...,
    dispatch_type=..., package_name=..., fcn_name=..., autoload=false)
    at oct-parse.yy:4101
#2  0x00007ffff72115ab in symbol_table::fcn_info::fcn_info_rep::find_user_function (
    this=0x7fffd846efa0) at corefcn/symtab.cc:1086
#3  0x00007ffff7210740 in symbol_table::fcn_info::fcn_info_rep::xfind (
    this=0x7fffd846efa0, args=..., local_funcs=true) at corefcn/symtab.cc:857
#4  0x00007ffff720fdec in symbol_table::fcn_info::fcn_info_rep::find (
    this=0x7fffd846efa0, args=..., local_funcs=true) at corefcn/symtab.cc:694
#5  0x00007ffff72151f8 in symbol_table::fcn_info::find (this=0x7fffdd427690, args=...,
    local_funcs=true) at corefcn/symtab.h:1020
#6  0x00007ffff7213207 in symbol_table::do_find (this=0x7fffd81574d0, name=..., args=...,
    skip_variables=true, local_funcs=true) at corefcn/symtab.cc:1457
#7  0x00007ffff7212412 in symbol_table::find (name=..., args=..., skip_variables=true,
    local_funcs=true) at corefcn/symtab.cc:1257
#8  0x00007ffff7212666 in symbol_table::find_function (name=..., args=...,
    local_funcs=true) at corefcn/symtab.cc:1292
#9  0x00007ffff720db7e in symbol_table::symbol_record::find (this=0x7fffd846eeb8,
    args=...) at corefcn/symtab.cc:142
#10 0x00007ffff6e231b0 in tree_identifier::rvalue (this=0x7fffd846ee90, nargout=0,
    lvalue_list=0x0) at parse-tree/pt-id.cc:70
#11 0x00007ffff6e23cc7 in tree_identifier::rvalue (this=0x7fffd846ee90, nargout=0)
    at parse-tree/pt-id.h:109
#12 0x00007ffff6e234f2 in tree_identifier::rvalue1 (this=0x7fffd846ee90, nargout=0)
    at parse-tree/pt-id.cc:121
#13 0x00007ffff6e1ec2a in tree_evaluator::visit_statement (this=0x7ffff78fd038, stmt=...)
    at parse-tree/pt-eval.cc:753
#14 0x00007ffff6e3fb7c in tree_statement::accept (this=0x7fffd846ef60, tw=...)
    at parse-tree/pt-stmt.cc:178
#15 0x00007ffff6e1ee96 in tree_evaluator::visit_statement_list (this=0x7ffff78fd038,
    lst=...) at parse-tree/pt-eval.cc:803
#16 0x00007ffff6e4019c in tree_statement_list::accept (this=0x7fffd81749a0, tw=...)
    at parse-tree/pt-stmt.cc:291
#17 0x00007ffff7248d3d in main_loop () at corefcn/toplev.cc:593


I'm not going to go any further because the parser is not something I understand.

Rik <rik5>
Group administrator
Mon 07 Apr 2014 03:28:36 PM UTC, comment #5: 

@Rik: My guess is that Octave is not expecting to see
EOF as the first value in a file.  Anything besides EOF seems to work.

Looks right to me. Should be easy to fix.

Michael Godfrey <godfrey>
Group Member
Mon 07 Apr 2014 03:22:49 PM UTC, comment #4: 

The character doesn't even need to be something important like '#'.  A single space character also works.  My guess is that Octave is not expecting to see EOF as the first value in a file.  Anything besides EOF seems to work.

Rik <rik5>
Group administrator
Mon 07 Apr 2014 02:32:46 PM UTC, comment #3: 

Mike,

All that is true, but this is still a regression
and Matlab incompatibility. And, the error message
is incorrect: the file exists, but is empty.

Michael Godfrey <godfrey>
Group Member
Mon 07 Apr 2014 12:27:38 PM UTC, comment #2: 

Confirmed, executing an empty m-file did work in 3.6.4 but fails in 3.8.x and later. Using either source or run work as a workaround. Or adding a single '#' character to the file makes it a valid file for executing.


octave:1> system ("> cd_data.m");
octave:2> cd_data
error: 'cd_data' undefined near line 1 column 1
octave:2> source cd_data.m  ## no error
octave:3> run cd_data  ## no error
octave:4> system ("echo # > cd_data.m");
octave:5> cd_data  ## no error now


Mike Miller <mtmiller>
Group Member
Mon 07 Apr 2014 12:13:41 PM UTC, comment #1: 

Important note:

This only happens if the file is empty!!

Still, a regression.
And, incompatible with Matlab.

Michael Godfrey <godfrey>
Group Member
Mon 07 Apr 2014 12:01:56 PM UTC, original submission:  

The following example code
if exist("cd_data.m", "file")
   cd_data;
endif 

fails with error: 'cd_data' undefined

for cd_data.m in the current directory, and the
path starting with
.

Note that exist("cd_data.m", "file")
returns 2 as it should.

This just happened as a result of updates in the
last few days.


Michael Godfrey <godfrey>
Group Member

 

(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 jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by godfrey (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.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-05-23 jwe StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2014-04-14 jwe Assigned toNone jwe
    2014-04-07 mtmiller StatusNone Confirmed
        Summaryfile search fails for . executing empty m-file as a command fails

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code