bugGNU Octave - Bugs: bug #42432, Error with octave when using from...

 
 

bug #42432: Error with octave when using from Perl via Inline::Octave

Submitted by:  None
Submitted on:  Mon 26 May 2014 05:53:17 PM UTC  
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Other
Status:  Wont Fix Assigned to:  None
Originator Name:  Andreas Krause Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  dev
Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

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

 

( Jump to the original submission)

Tue 05 Feb 2019 07:49:39 PM UTC, comment #9: 

Good enough for me.  Closing report.

Rik <rik5>
Project Administrator
Tue 05 Feb 2019 07:09:17 PM UTC, comment #8: 

I just noticed that a viable workaround is to use the hack of prepending a statement so that Octave knows that stdin is a script, not a function file:

$ echo "function x = myfunc (u) x = u + 1; endfunction; myfunc(3)" | octave
warning: function name 'myfunc' does not agree with function filename ''
error: 'myfunc' undefined near line 1 column 42
$ echo "1; function x = myfunc (u) x = u + 1; endfunction; myfunc(3)" | octave
ans =  4

This seems eminently simple and consistent with the way that Octave already handles function files and script files. Can we just close this with the wisdom that inline scripts passed to stdin should start with a non-function-declaration statement?

Mike Miller <mtmiller>
Project Administrator
Tue 05 Feb 2019 06:52:07 PM UTC, comment #7: 

This bug is quite old.  Do we want to fix it, or just move on?

This sample code still produces a warning:

echo "function x=myfunc(u) x=u+1; endfunction; myfunc(3)" | octave -qfH

Rik <rik5>
Project Administrator
Mon 21 Nov 2016 07:50:59 PM UTC, comment #6: 

This issue is still present with the development code.  I tested using the example in comment #3.

Rik <rik5>
Project Administrator
Fri 26 Sep 2014 04:37:01 AM UTC, comment #5: 
Mike Miller <mtmiller>
Project Administrator
Fri 26 Sep 2014 01:41:25 AM UTC, comment #4: 

Thanks Andy, that shows the cited error for me too. No error with 3.6.4.

If octave runs with -i (--interactive), there is no error, of course the prompt is also shown, and the result is shown correctly.

So it looks like it used to allow functions to be defined as if they were entered at the command prompt even if stdin is not an interactive terminal. In 3.8 this causes the error shown.

Mike Miller <mtmiller>
Project Administrator
Thu 25 Sep 2014 06:00:56 PM UTC, comment #3: 

I think a minimalistic example for this is

$ echo "function x=myfunc(u) x=u+1; endfunction; myfunc(3)" | octave -qfH
warning: function name 'myfunc' does not agree with function file name ''
error: 'myfunc' undefined near line 1 column 42

Andreas Weber <andy1978>
Project Member
Thu 25 Sep 2014 04:31:06 PM UTC, comment #2: 

Octave is called from Perl by spawning a new process and following communication via pipes. Therefore I can't give you an independent m-file script.

I attached a minimal Perl script to show the error. It should run with any standard Perl installation (e.g. Linux).

By changing the used octave version in line 8 you can switch between the working and non working behaviour. This is probably also the entry point to call octave with a debugger.

If you need to execute other code in octave just replace the code between the CODE marks.

Please let me know if you need any more infos.

(file #32183)

Anonymous
Wed 24 Sep 2014 11:00:21 PM UTC, comment #1: 

Thanks for your bug report. I'm not sure that there's much actionable on this report without some more information from your side. What you are reporting is that an external interface to Octave doesn't work with 3.8. That may be true, and it may be something that Octave changed either intentionally or accidentally, but there's not much here that an Octave developer can start working from. I don't know that any of us know how this interface works.

Can you give more information on how Octave is being loaded or called? Is it being linked to or called via a pipe? Can you give a more minimal example that doesn't depend on Perl, with an m-file script or snippet that can be run in the interpreter that shows the same error?

Mike Miller <mtmiller>
Project Administrator
Mon 26 May 2014 05:53:17 PM UTC, original submission:  

I'm currently trying to get up and running the octave interface for perl again

  http://search.cpan.org/~aadler/Inline-Octave-0.31/Octave.pm

with the current octave 3.8.1. Until the previous version 3.6.4 all worked fine. The sample program

#!/usr/bin/perl
use Inline Octave => DATA;

$f = myfunc(3);
print "jnk1=",$f->disp(),"\n";

__DATA__
__Octave__
function x=myfunc(u)
  x=u+1
endfunction

 

gave with 3.6.4 the correct output

  jnk1= 4

When using octave 3.8.1, I get the following error:

  sample.pm
  Warning: function name 'myfunc' does not agree with function file name '';  (in octave code) at ./sample.pm line 0.
  Undefined subroutine &main::myfunc called at ./sample.pm line 5.

Debugging, I found octave-3.8.1/libinterp/parse-tree/oct-parse.in.yy line 2819ff

    octave_user_function *
    octave_base_parser::frob_function (const std::string& fname,
                                       octave_user_function *fcn)
    {
      std::string id_name = fname;
      // If input is coming from a file, issue a warning if the name of
      // the file does not match the name of the function stated in the
      // file.  Matlab doesn't provide a diagnostic (it ignores the stated
      // name).
  ->  if (! autoloading && lexer.reading_fcn_file
  ->      && curr_fcn_depth == 1 && ! parsing_subfunctions)
      {
        // FIXME -- should lexer.fcn_file_name already be
        // preprocessed when we get here?  It seems to only be a
        // problem with relative file names.
        std::string nm = lexer.fcn_file_name;
        size_t pos = nm.find_last_of (file_ops::dir_sep_chars ());
        if (pos != std::string::npos)
          nm = lexer.fcn_file_name.substr (pos+1);
        if (nm != id_name)

          {
            warning_with_id
              ("Octave:function-name-clash",
               "function name '%s' does not agree with function file name '%s'",
               id_name.c_str (), lexer.fcn_file_full_name.c_str ());
            id_name = nm;
          }
      }

with the if-condition lexer.reading_fcn_file as true -> warning. The "Undefined subroutine" error above seems like a follow-up error as id_name is overwritten with the empty variable nm.

The corresponding if-condition in octave-3.6.4/src/oct-parse.yy line 2826ff looks like

    if (! autoloading && reading_fcn_file
        && (current_function_depth == 1
            && ! (parsing_subfunctions || lexer_flags.parsing_class_method)))

but with reading_fcn_file as false -> no warning. The reason for the different value of this flag might be an additional if-clause in octave-3.8.1/libinterp/parse-tree/lex.ll line 2411ff

        case function_kw:
          decrement_promptflag ();
          defining_func++;
          parsed_function_name.push (false);
  ->      if (! force_script && token_count == 0 && input_from_file ())
  ->        {
  ->          reading_fcn_file = true;
  ->          reading_script_file = false;
  ->        }
          if (! (reading_fcn_file || reading_script_file
                 || reading_classdef_file))
            input_line_number = 1;
          break;

which sets reading_fcn_file to true but is missing in 3.6.4. But this is too deep in the octave internals for me to be sure.

Inline::Octave starts an octave instance and communicates with it via
   use IPC::Open3;
   use IO::File;

So can anybody help me with this issue? An empty function file name seems to be strange.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #32183:  perl2octave added by None (2KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by andy1978 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

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

    Only project members can vote.

     

     

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-05 rik5 StatusConfirmed => Wont Fix
        Open/ClosedOpen => Closed
    2019-02-05 mtmiller Carbon-CopyRemoved 80942 => -
    2019-02-05 rik5 Carbon-Copy- => Added jwe
    2016-11-21 rik5 Release3.8.1 => dev
    2014-09-26 mtmiller StatusNeed Info => Confirmed
    2014-09-25 None Attached File- => Added perl2octave, #32183
    2014-09-24 mtmiller StatusNone => Need Info

    Back to the top


    Powered by Savane 3.5