Calling Octave from C++

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Calling Octave from C++

andrea.delbravo
Hello to evrybody, I have e real big issue which jeopardize a 6 months work!!
I have a very big application in C++ related to air traffic control
simulation for testing Sense & avoid susyem for unmanned aircraft.
To define the trajectories of 2 Encounter AC I used an utility developed by
MIT (Lincoln Lab) written in MATLA that I execute in Octave from C++.
All wirked very fine until Octave 4.0.0. Now I updated to Octave 4.2.1 and
the SW crashes (Segmentation failt) inside the interpreter.
I try all the suggestion inside this forum and almost in all around the WEB.
I'm really desperate.
I minimize the code to try to find the solution, and I suppose the problem
is in the feval call
If I use id with an Octave function (like gcd) it works fine, while if I
substitute it with a very simple Octave code written by me that capture and
show the 2 parameters I passed to gcd, it crashes. It is like it didn't find
the script, but the OCTAVE_PATH env var is correctly set.
Any idea?
Thanks a lot
Andrea



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant
--- andrea.delbravo

> Hello to evrybody, I have e real big issue which jeopardize a 6 months work!!
> I have a very big application in C++ related to air traffic control
> simulation for testing Sense & avoid susyem for unmanned aircraft.
> To define the trajectories of 2 Encounter AC I used an utility developed by
> MIT (Lincoln Lab) written in MATLA that I execute in Octave from C++.
> All wirked very fine until Octave 4.0.0. Now I updated to Octave 4.2.1 and
> the SW crashes (Segmentation failt) inside the interpreter.
> I try all the suggestion inside this forum and almost in all around the WEB.
> I'm really desperate.
> I minimize the code to try to find the solution, and I suppose the problem
> is in the feval call
> If I use id with an Octave function (like gcd) it works fine, while if I
> substitute it with a very simple Octave code written by me that capture and
> show the 2 parameters I passed to gcd, it crashes. It is like it didn't find
> the script, but the OCTAVE_PATH env var is correctly set.
> Any idea?
> Thanks a lot
> Andrea
>
 Please show us short code to reproduce the fault.

In addition, show us your platform (e.g.
windows 10, ubuntu 16.04).

segmentation fault sometimes relates with platform.

Tatsuro


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

Ian McCallion
In reply to this post by andrea.delbravo
What do you mean by OCTAVE_PATH? The path to .m files is not in an
environment variable but is added to by addpath and revealed by path()

   which functionname

will show which (if any) version of the specified function will be called.


Cheers... Ian

On 22 March 2018 at 16:04, andrea.delbravo
<[hidden email]> wrote:

> Hello to evrybody, I have e real big issue which jeopardize a 6 months work!!
> I have a very big application in C++ related to air traffic control
> simulation for testing Sense & avoid susyem for unmanned aircraft.
> To define the trajectories of 2 Encounter AC I used an utility developed by
> MIT (Lincoln Lab) written in MATLA that I execute in Octave from C++.
> All wirked very fine until Octave 4.0.0. Now I updated to Octave 4.2.1 and
> the SW crashes (Segmentation failt) inside the interpreter.
> I try all the suggestion inside this forum and almost in all around the WEB.
> I'm really desperate.
> I minimize the code to try to find the solution, and I suppose the problem
> is in the feval call
> If I use id with an Octave function (like gcd) it works fine, while if I
> substitute it with a very simple Octave code written by me that capture and
> show the 2 parameters I passed to gcd, it crashes. It is like it didn't find
> the script, but the OCTAVE_PATH env var is correctly set.
> Any idea?
> Thanks a lot
> Andrea
>
>
>
> --
> Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

andrea.delbravo
Well, sorry for the nmissing infos.
I wirk with Fedora 26 Ocatve 4.2.1. I tried also with Fedora 27 Octave 4.2.2
but the problem persist.
The application run perfectly under fedora 25 Octave 4.0.3.
I minimize the application in order to focalize the problem:
After several initialization the core of the problem is:

// THIS CODE IS WORKING
int qq =10;
int rr =15;
in(0) = octave_value(qq);
in(1) = octave_value(rr);
octave_value_list out = feval ("gcd", in, 1);
std::cout << out(0).int_value ()
and it prints the correct result = 5 the Greatest common disisor between 10
and 15

but if I run
// THIS CODE IN NOT WORKING
octave_value_list out = feval ("pp", in, 1);
where pp.m is a stupid Octave script which shuld disply the two numbers
(tested and working in the Octave environment)

Application crashes with Segmentation Fault insiede the interpreter, and I
cannot debug it inside because the interpreter is not compiled with debug
information

The OCTAVE_PATH environment variable define the path where the .m files are
saved (see Octave manual for example version 4.4. March 2018 pag 17, but
valid since a long time in all the Octave Version. I've been using it for at
least 7 years

The OCTAVE_PATH variable is correctly seen inside the C++ cose. Ifact if I
run the program with:

// THIS CODE IS WORKING
in(0) = octave_value(a); // where a is a char[] = OCTAVE_PATH
octave_value_list out = feval ("getenv", in, 1);   //getenv return the
Evironmental Variable (see Octave manual)
std::cout << out(0).string_value ()   // print the correct OCTAVE_PATH value

It seems that is I use an embedded function i worke, but if I use  my own
script it crashes

Thanks a lot in advance








--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant
----- Original Message -----

> From: andrea.delbravo
> To: help-octave
> Cc:
> Date: 2018/3/23, Fri 19:28
> Subject: Re: Calling Octave from C++
>
> Well, sorry for the nmissing infos.
> I wirk with Fedora 26 Ocatve 4.2.1. I tried also with Fedora 27 Octave 4.2.2
> but the problem persist.
> The application run perfectly under fedora 25 Octave 4.0.3.
> I minimize the application in order to focalize the problem:
> After several initialization the core of the problem is:
>
> // THIS CODE IS WORKING
> int qq =10;
> int rr =15;
> in(0) = octave_value(qq);
> in(1) = octave_value(rr);
> octave_value_list out = feval ("gcd", in, 1);
> std::cout << out(0).int_value ()
> and it prints the correct result = 5 the Greatest common disisor between 10
> and 15

I execute the code on Octave-4.2.2 build myself on Ubuntu 16.04.
Octave hangs with Segmentation fault.
Segmentation fault

Thread 1 "test_01" received signal SIGSEGV, Segmentation fault.
0x00007ffff6e2996a in octave::application::interactive() ()
   from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4

bt

#0  0x00007ffff6e2996a in octave::application::interactive() ()
   from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
#1  0x00007ffff78147a6 in octave_pager_buf::sync() ()
   from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
#2  0x00007ffff571ce3e in std::ostream::flush() ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff78151a6 in flush_octave_stdout() ()
   from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
#4  0x00007ffff7550e2d in ?? ()
   from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
#5  0x00007ffff75508c5 in ?? ()
   from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
#6  0x00007ffff75509fe in ?? ()
   from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
#7  0x00007ffff7550a57 in verror(char const*, __va_list_tag*) ()
   from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
#8  0x00007ffff7550af9 in error(char const*, ...) ()
   from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
#9  0x00007ffff73b4fb2 in feval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, octave_value_list const&, int) ()
   from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
#10 0x0000000000401920 in main () at test_01.cc:16

Perhaps bug.

However, new version octave 4.4 is coming soon.
I will test it on release candidate source afterwards.

BTW.
Can you build octave by yourself?
I only use ubuntu as linux disro.
But on Fedora, octave can be built in similar way.

https://www.scivision.co/compiling-octave-4-on-ubuntu/

The above is guide of build octave on ubuntu, but is perhaps helpful build it on Fedora.
I also install portaudio in addition to the above instruction.  

Tatsuro





>
> but if I run
> // THIS CODE IN NOT WORKING
> octave_value_list out = feval ("pp", in, 1);
> where pp.m is a stupid Octave script which shuld disply the two numbers
> (tested and working in the Octave environment)
>
> Application crashes with Segmentation Fault insiede the interpreter, and I
> cannot debug it inside because the interpreter is not compiled with debug
> information
>
> The OCTAVE_PATH environment variable define the path where the .m files are
> saved (see Octave manual for example version 4.4. March 2018 pag 17, but
> valid since a long time in all the Octave Version. I've been using it for at
> least 7 years
>
> The OCTAVE_PATH variable is correctly seen inside the C++ cose. Ifact if I
> run the program with:
>
> // THIS CODE IS WORKING
> in(0) = octave_value(a); // where a is a char[] = OCTAVE_PATH
> octave_value_list out = feval ("getenv", in, 1);   //getenv return the
> Evironmental Variable (see Octave manual)
> std::cout << out(0).string_value ()   // print the correct OCTAVE_PATH
> value
>
> It seems that is I use an embedded function i worke, but if I use  my own
> script it crashes
>
> Thanks a lot in advance
>
>
>
>
>
>
>
>
> --
> Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
>


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant
----- Original Message -----

> From: Tatsuro MATSUOKA
> To: andrea.delbravo "help-octave Cc:
> Date: 2018/3/24, Sat 07:47
> Subject: Re: Calling Octave from C++
>
> ----- Original Message -----
>
>>  From: andrea.delbravo
>>  To: help-octave
>>  Cc:
>>  Date: 2018/3/23, Fri 19:28
>>  Subject: Re: Calling Octave from C++
>>
>>  Well, sorry for the nmissing infos.
>>  I wirk with Fedora 26 Ocatve 4.2.1. I tried also with Fedora 27 Octave
> 4.2.2
>>  but the problem persist.
>>  The application run perfectly under fedora 25 Octave 4.0.3.
>>  I minimize the application in order to focalize the problem:
>>  After several initialization the core of the problem is:
>>
>>  // THIS CODE IS WORKING
>>  int qq =10;
>>  int rr =15;
>>  in(0) = octave_value(qq);
>>  in(1) = octave_value(rr);
>>  octave_value_list out = feval ("gcd", in, 1);
>>  std::cout << out(0).int_value ()
>>  and it prints the correct result = 5 the Greatest common disisor between 10
>>  and 15
>
> I execute the code on Octave-4.2.2 build myself on Ubuntu 16.04.
> Octave hangs with Segmentation fault.
> Segmentation fault
>
> Thread 1 "test_01" received signal SIGSEGV, Segmentation fault.
> 0x00007ffff6e2996a in octave::application::interactive() ()
>    from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>
> bt
>
> #0  0x00007ffff6e2996a in octave::application::interactive() ()
>    from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
> #1  0x00007ffff78147a6 in octave_pager_buf::sync() ()
>    from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
> #2  0x00007ffff571ce3e in std::ostream::flush() ()
>    from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
> #3  0x00007ffff78151a6 in flush_octave_stdout() ()
>    from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
> #4  0x00007ffff7550e2d in ?? ()
>    from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
> #5  0x00007ffff75508c5 in ?? ()
>    from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
> #6  0x00007ffff75509fe in ?? ()
>    from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
> #7  0x00007ffff7550a57 in verror(char const*, __va_list_tag*) ()
>    from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
> #8  0x00007ffff7550af9 in error(char const*, ...) ()
>    from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
> #9  0x00007ffff73b4fb2 in feval(std::__cxx11::basic_string<char,
> std::char_traits<char>, std::allocator<char> > const&,
> octave_value_list const&, int) ()
>    from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
> #10 0x0000000000401920 in main () at test_01.cc:16
>
> Perhaps bug.

Ah!

I have forgotten to set LD_LIBRARY_PATH to self build octave directory.Thread 1 "test_01" received signal SIGSEGV, Segmentation fault.
0x00007ffff6e2202a in octave::application::interactive ()
    at ../libinterp/octave.cc:362
362        interpreter *interp = instance->m_interpreter;
(gdb) bt
#0  0x00007ffff6e2202a in octave::application::interactive ()
    at ../libinterp/octave.cc:362
#1  0x00007ffff780a436 in octave_pager_buf::sync (this=0x66a120)
    at ../libinterp/corefcn/pager.cc:236
#2  0x00007ffff5682e3e in std::ostream::flush() ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff780ae36 in flush_octave_stdout ()
    at ../libinterp/corefcn/pager.cc:466
#4  0x00007ffff754742d in verror(bool, std::ostream &, const char *, const char *, const char *, typedef __va_list_tag __va_list_tag *, bool) (
    save_last_error=save_last_error@entry=true, os=...,
    name=name@entry=0x7ffff7945fb1 "error", id=id@entry=0x7ffff793b504 "",
    fmt=fmt@entry=0x7ffff792db10 "feval: function '%s' not found",
    args=0x7fffffffdcd0, with_cfn=false) at ../libinterp/corefcn/error.cc:157
#5  0x00007ffff7546ec5 in error_1(octave::execution_exception &, std::ostream &, const char *, const char *, const char *, typedef __va_list_tag __va_list_tag *, bool) (e=..., os=..., name=name@entry=0x7ffff7945fb1 "error",
    id=id@entry=0x7ffff793b504 "", fmt=<optimised out>,
    fmt@entry=0x7ffff792db10 "feval: function '%s' not found",
    args=args@entry=0x7fffffffdcd0, with_cfn=false)
    at ../libinterp/corefcn/error.cc:535
#6  0x00007ffff7546ffe in error_1(std::ostream &, const char *, const char *, const char *, typedef __va_list_tag __va_list_tag *, bool) (os=...,
---Type <return> to continue, or q <return> to quit---
    name=name@entry=0x7ffff7945fb1 "error", id=id@entry=0x7ffff793b504 "",
    fmt=0x7ffff792db10 "feval: function '%s' not found",
    args=args@entry=0x7fffffffdcd0, with_cfn=with_cfn@entry=false)
    at ../libinterp/corefcn/error.cc:560
#7  0x00007ffff7547057 in verror (fmt=<optimised out>,
    args=args@entry=0x7fffffffdcd0) at ../libinterp/corefcn/error.cc:566
#8  0x00007ffff75470f9 in error (
    fmt=fmt@entry=0x7ffff792db10 "feval: function '%s' not found")
    at ../libinterp/corefcn/error.cc:574
#9  0x00007ffff73aa712 in feval (name="gcd", args=..., nargout=nargout@entry=1)
    at libinterp/parse-tree/oct-parse.yy:4809
#10 0x0000000000401920 in main () at test_01.cc:16


Tatsuro


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant
----- Original Message -----

> From: Tatsuro MATSUOKA
> To: tmacchant; andrea.delbravo  "help-octave
> Cc:
> Date: 2018/3/24, Sat 08:09
> Subject: Re: Calling Octave from C++
>
> ----- Original Message -----
>
>>  From: Tatsuro MATSUOKA
>>  To: andrea.delbravo "help-octave Cc:
>>  Date: 2018/3/24, Sat 07:47
>>  Subject: Re: Calling Octave from C++
>>
>>  ----- Original Message -----
>>
>>>   From: andrea.delbravo
>>>   To: help-octave
>>>   Cc:
>>>   Date: 2018/3/23, Fri 19:28
>>>   Subject: Re: Calling Octave from C++
>>>
>>>   Well, sorry for the nmissing infos.
>>>   I wirk with Fedora 26 Ocatve 4.2.1. I tried also with Fedora 27 Octave
>
>>  4.2.2
>>>   but the problem persist.
>>>   The application run perfectly under fedora 25 Octave 4.0.3.
>>>   I minimize the application in order to focalize the problem:
>>>   After several initialization the core of the problem is:
>>>
>>>   // THIS CODE IS WORKING
>>>   int qq =10;
>>>   int rr =15;
>>>   in(0) = octave_value(qq);
>>>   in(1) = octave_value(rr);
>>>   octave_value_list out = feval ("gcd", in, 1);
>>>   std::cout << out(0).int_value ()
>>>   and it prints the correct result = 5 the Greatest common disisor
> between 10
>>>   and 15
>>
>>  I execute the code on Octave-4.2.2 build myself on Ubuntu 16.04.
>>  Octave hangs with Segmentation fault.
>>  Segmentation fault
>>
>>  Thread 1 "test_01" received signal SIGSEGV, Segmentation fault.
>>  0x00007ffff6e2996a in octave::application::interactive() ()
>>     from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>
>>  bt
>>
>>  #0  0x00007ffff6e2996a in octave::application::interactive() ()
>>     from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>  #1  0x00007ffff78147a6 in octave_pager_buf::sync() ()
>>     from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>  #2  0x00007ffff571ce3e in std::ostream::flush() ()
>>     from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
>>  #3  0x00007ffff78151a6 in flush_octave_stdout() ()
>>     from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>  #4  0x00007ffff7550e2d in ?? ()
>>     from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>  #5  0x00007ffff75508c5 in ?? ()
>>     from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>  #6  0x00007ffff75509fe in ?? ()
>>     from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>  #7  0x00007ffff7550a57 in verror(char const*, __va_list_tag*) ()
>>     from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>  #8  0x00007ffff7550af9 in error(char const*, ...) ()
>>     from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>  #9  0x00007ffff73b4fb2 in feval(std::__cxx11::basic_string<char,
>>  std::char_traits<char>, std::allocator<char> > const&,
>>  octave_value_list const&, int) ()
>>     from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>  #10 0x0000000000401920 in main () at test_01.cc:16
>>
>>  Perhaps bug.
>
> Ah!
>
> I have forgotten to set LD_LIBRARY_PATH to self build octave directory.Thread 1
> "test_01" received signal SIGSEGV, Segmentation fault.
> 0x00007ffff6e2202a in octave::application::interactive ()
>     at ../libinterp/octave.cc:362
> 362        interpreter *interp = instance->m_interpreter;
> (gdb) bt
> #0  0x00007ffff6e2202a in octave::application::interactive ()
>     at ../libinterp/octave.cc:362
> #1  0x00007ffff780a436 in octave_pager_buf::sync (this=0x66a120)
>     at ../libinterp/corefcn/pager.cc:236
> #2  0x00007ffff5682e3e in std::ostream::flush() ()
>    from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
> #3  0x00007ffff780ae36 in flush_octave_stdout ()
>     at ../libinterp/corefcn/pager.cc:466
> #4  0x00007ffff754742d in verror(bool, std::ostream &, const char *, const
> char *, const char *, typedef __va_list_tag __va_list_tag *, bool) (
>     save_last_error=save_last_error@entry=true, os=...,
>     name=name@entry=0x7ffff7945fb1 "error", id=id@entry=0x7ffff793b504
> "",
>     fmt=fmt@entry=0x7ffff792db10 "feval: function '%s' not
> found",
>     args=0x7fffffffdcd0, with_cfn=false) at ../libinterp/corefcn/error.cc:157
> #5  0x00007ffff7546ec5 in error_1(octave::execution_exception &,
> std::ostream &, const char *, const char *, const char *, typedef
> __va_list_tag __va_list_tag *, bool) (e=..., os=...,
> name=name@entry=0x7ffff7945fb1 "error",
>     id=id@entry=0x7ffff793b504 "", fmt=<optimised out>,
>     fmt@entry=0x7ffff792db10 "feval: function '%s' not found",
>
>     args=args@entry=0x7fffffffdcd0, with_cfn=false)
>     at ../libinterp/corefcn/error.cc:535
> #6  0x00007ffff7546ffe in error_1(std::ostream &, const char *, const char
> *, const char *, typedef __va_list_tag __va_list_tag *, bool) (os=...,
> ---Type <return> to continue, or q <return> to quit---
>     name=name@entry=0x7ffff7945fb1 "error", id=id@entry=0x7ffff793b504
> "",
>     fmt=0x7ffff792db10 "feval: function '%s' not found",
>     args=args@entry=0x7fffffffdcd0, with_cfn=with_cfn@entry=false)
>     at ../libinterp/corefcn/error.cc:560
> #7  0x00007ffff7547057 in verror (fmt=<optimised out>,
>     args=args@entry=0x7fffffffdcd0) at ../libinterp/corefcn/error.cc:566
> #8  0x00007ffff75470f9 in error (
>     fmt=fmt@entry=0x7ffff792db10 "feval: function '%s' not
> found")
>     at ../libinterp/corefcn/error.cc:574
> #9  0x00007ffff73aa712 in feval (name="gcd", args=...,
> nargout=nargout@entry=1)
>     at libinterp/parse-tree/oct-parse.yy:4809
> #10 0x0000000000401920 in main () at test_01.cc:16
>
>
> Tatsuro

I have executed the recent stable snapshot (5f4550b5d31b).

Thread 1 "test_01" received signal SIGABRT, Aborted.
0x00007ffff4ef0428 in __GI_raise (sig=sig@entry=6)
    at ../sysdeps/unix/sysv/linux/raise.c:54
54    ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007ffff4ef0428 in __GI_raise (sig=sig@entry=6)
    at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007ffff4ef202a in __GI_abort () at abort.c:89
#2  0x00007ffff76f7aa7 in octave::__get_interpreter__ (who="feval")
    at libinterp/corefcn/interpreter-private.cc:49
#3  0x00007ffff76f7b39 in octave::__get_symbol_table__ (who="feval")
    at libinterp/corefcn/interpreter-private.cc:86
#4  0x00007ffff7394c31 in octave::feval (name="gcd", args=...,
    nargout=nargout@entry=1) at libinterp/parse-tree/oct-parse.yy:5197
#5  0x000000000040338e in feval (nargout=1, args=..., name="gcd")
    at /opt/octave-stable/include/octave-4.3.0+/octave/../octave/parse.h:647
#6  main () at test_01.cc:16

Octave aborted by  SIGABRT

Tatsuro



Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant
----- Original Message -----

> From: Tatsuro MATSUOKA
> To: tmacchant; andrea.delbravo  "help-octav
> Cc:
> Date: 2018/3/24, Sat 11:05
> Subject: Re: Calling Octave from C++
>
> ----- Original Message -----
>>  From: Tatsuro MATSUOKA
>>  To: tmacchant; andrea.delbravo  "help-octave
>>  Cc:
>>  Date: 2018/3/24, Sat 08:09
>>  Subject: Re: Calling Octave from C++
>>
>>  ----- Original Message -----
>>
>>>   From: Tatsuro MATSUOKA
>>>   To: andrea.delbravo "help-octave Cc:
>>>   Date: 2018/3/24, Sat 07:47
>>>   Subject: Re: Calling Octave from C++
>>>
>>>   ----- Original Message -----
>>>
>>>>    From: andrea.delbravo
>>>>    To: help-octave
>>>>    Cc:
>>>>    Date: 2018/3/23, Fri 19:28
>>>>    Subject: Re: Calling Octave from C++
>>>>
>>>>    Well, sorry for the nmissing infos.
>>>>    I wirk with Fedora 26 Ocatve 4.2.1. I tried also with Fedora 27
> Octave
>>
>>>   4.2.2
>>>>    but the problem persist.
>>>>    The application run perfectly under fedora 25 Octave 4.0.3.
>>>>    I minimize the application in order to focalize the problem:
>>>>    After several initialization the core of the problem is:
>>>>
>>>>    // THIS CODE IS WORKING
>>>>    int qq =10;
>>>>    int rr =15;
>>>>    in(0) = octave_value(qq);
>>>>    in(1) = octave_value(rr);
>>>>    octave_value_list out = feval ("gcd", in, 1);
>>>>    std::cout << out(0).int_value ()
>>>>    and it prints the correct result = 5 the Greatest common disisor
>>  between 10
>>>>    and 15
>>>
>>>   I execute the code on Octave-4.2.2 build myself on Ubuntu 16.04.
>>>   Octave hangs with Segmentation fault.
>>>   Segmentation fault
>>>
>>>   Thread 1 "test_01" received signal SIGSEGV, Segmentation
> fault.
>>>   0x00007ffff6e2996a in octave::application::interactive() ()
>>>      from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>>
>>>   bt
>>>
>>>   #0  0x00007ffff6e2996a in octave::application::interactive() ()
>>>      from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>>   #1  0x00007ffff78147a6 in octave_pager_buf::sync() ()
>>>      from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>>   #2  0x00007ffff571ce3e in std::ostream::flush() ()
>>>      from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
>>>   #3  0x00007ffff78151a6 in flush_octave_stdout() ()
>>>      from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>>   #4  0x00007ffff7550e2d in ?? ()
>>>      from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>>   #5  0x00007ffff75508c5 in ?? ()
>>>      from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>>   #6  0x00007ffff75509fe in ?? ()
>>>      from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>>   #7  0x00007ffff7550a57 in verror(char const*, __va_list_tag*) ()
>>>      from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>>   #8  0x00007ffff7550af9 in error(char const*, ...) ()
>>>      from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>>   #9  0x00007ffff73b4fb2 in feval(std::__cxx11::basic_string<char,
>>>   std::char_traits<char>, std::allocator<char> >
> const&,
>>>   octave_value_list const&, int) ()
>>>      from /usr/lib/x86_64-linux-gnu/liboctinterp.so.4
>>>   #10 0x0000000000401920 in main () at test_01.cc:16
>>>
>>>   Perhaps bug.
>>
>>  Ah!
>>
>>  I have forgotten to set LD_LIBRARY_PATH to self build octave
> directory.Thread 1
>>  "test_01" received signal SIGSEGV, Segmentation fault.
>>  0x00007ffff6e2202a in octave::application::interactive ()
>>      at ../libinterp/octave.cc:362
>>  362        interpreter *interp = instance->m_interpreter;
>>  (gdb) bt
>>  #0  0x00007ffff6e2202a in octave::application::interactive ()
>>      at ../libinterp/octave.cc:362
>>  #1  0x00007ffff780a436 in octave_pager_buf::sync (this=0x66a120)
>>      at ../libinterp/corefcn/pager.cc:236
>>  #2  0x00007ffff5682e3e in std::ostream::flush() ()
>>     from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
>>  #3  0x00007ffff780ae36 in flush_octave_stdout ()
>>      at ../libinterp/corefcn/pager.cc:466
>>  #4  0x00007ffff754742d in verror(bool, std::ostream &, const char *,
> const
>>  char *, const char *, typedef __va_list_tag __va_list_tag *, bool) (
>>      save_last_error=save_last_error@entry=true, os=...,
>>      name=name@entry=0x7ffff7945fb1 "error",
> id=id@entry=0x7ffff793b504
>>  "",
>>      fmt=fmt@entry=0x7ffff792db10 "feval: function '%s' not
>>  found",
>>      args=0x7fffffffdcd0, with_cfn=false) at
> ../libinterp/corefcn/error.cc:157
>>  #5  0x00007ffff7546ec5 in error_1(octave::execution_exception &,
>>  std::ostream &, const char *, const char *, const char *, typedef
>>  __va_list_tag __va_list_tag *, bool) (e=..., os=...,
>>  name=name@entry=0x7ffff7945fb1 "error",
>>      id=id@entry=0x7ffff793b504 "", fmt=<optimised out>,
>>      fmt@entry=0x7ffff792db10 "feval: function '%s' not
> found",
>>
>>      args=args@entry=0x7fffffffdcd0, with_cfn=false)
>>      at ../libinterp/corefcn/error.cc:535
>>  #6  0x00007ffff7546ffe in error_1(std::ostream &, const char *, const
> char
>>  *, const char *, typedef __va_list_tag __va_list_tag *, bool) (os=...,
>>  ---Type <return> to continue, or q <return> to quit---
>>      name=name@entry=0x7ffff7945fb1 "error",
> id=id@entry=0x7ffff793b504
>>  "",
>>      fmt=0x7ffff792db10 "feval: function '%s' not found",
>>      args=args@entry=0x7fffffffdcd0, with_cfn=with_cfn@entry=false)
>>      at ../libinterp/corefcn/error.cc:560
>>  #7  0x00007ffff7547057 in verror (fmt=<optimised out>,
>>      args=args@entry=0x7fffffffdcd0) at ../libinterp/corefcn/error.cc:566
>>  #8  0x00007ffff75470f9 in error (
>>      fmt=fmt@entry=0x7ffff792db10 "feval: function '%s' not
>>  found")
>>      at ../libinterp/corefcn/error.cc:574
>>  #9  0x00007ffff73aa712 in feval (name="gcd", args=...,
>>  nargout=nargout@entry=1)
>>      at libinterp/parse-tree/oct-parse.yy:4809
>>  #10 0x0000000000401920 in main () at test_01.cc:16
>>
>>
>>  Tatsuro
>
> I have executed the recent stable snapshot (5f4550b5d31b).
>
> Thread 1 "test_01" received signal SIGABRT, Aborted.
> 0x00007ffff4ef0428 in __GI_raise (sig=sig@entry=6)
>     at ../sysdeps/unix/sysv/linux/raise.c:54
> 54    ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
> (gdb) bt
> #0  0x00007ffff4ef0428 in __GI_raise (sig=sig@entry=6)
>     at ../sysdeps/unix/sysv/linux/raise.c:54
> #1  0x00007ffff4ef202a in __GI_abort () at abort.c:89
> #2  0x00007ffff76f7aa7 in octave::__get_interpreter__ (who="feval")
>     at libinterp/corefcn/interpreter-private.cc:49
> #3  0x00007ffff76f7b39 in octave::__get_symbol_table__ (who="feval")
>     at libinterp/corefcn/interpreter-private.cc:86
> #4  0x00007ffff7394c31 in octave::feval (name="gcd", args=...,
>     nargout=nargout@entry=1) at libinterp/parse-tree/oct-parse.yy:5197
> #5  0x000000000040338e in feval (nargout=1, args=..., name="gcd")
>     at /opt/octave-stable/include/octave-4.3.0+/octave/../octave/parse.h:647
> #6  main () at test_01.cc:16
>
> Octave aborted by  SIGABRT
>
> Tatsuro

Seem to be bug.

I filed in
https://savannah.gnu.org/bugs/?func=detailitem&item_id=53446

I make CC. to andrea.delbravo.



Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

andrea.delbravo
In reply to this post by tmacchant
I've already downloaded the source code of 4.2.2 relese. The configure
command  finished correctly. Tomorrow I'l complile it with debug info in
prder to perform some more investigation. I'll keep you informed



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant
In reply to this post by andrea.delbravo




----- Original Message -----

> From: andrea.delbravo
> To: help-octave
> Cc:
> Date: 2018/3/23, Fri 19:28
> Subject: Re: Calling Octave from C++
>
> Well, sorry for the nmissing infos.
> I wirk with Fedora 26 Ocatve 4.2.1. I tried also with Fedora 27 Octave 4.2.2
> but the problem persist.
> The application run perfectly under fedora 25 Octave 4.0.3.
> I minimize the application in order to focalize the problem:
> After several initialization the core of the problem is:
>
> // THIS CODE IS WORKING
> int qq =10;
> int rr =15;
> in(0) = octave_value(qq);
> in(1) = octave_value(rr);
> octave_value_list out = feval ("gcd", in, 1);
> std::cout << out(0).int_value ()
> and it prints the correct result = 5 the Greatest common disisor between 10
> and 15

I have tested the above code on octave 4.2.2 for windows.
The program ended with segmentation fault.
Something might be wrong with standalone program on octave-4.2.2.
I will build windows binary current stable (to octave 4.4 in near future)
and test it and see platform dependence.
Tatsuro

> but if I run
> // THIS CODE IN NOT WORKING
> octave_value_list out = feval ("pp", in, 1);
> where pp.m is a stupid Octave script which shuld disply the two numbers
> (tested and working in the Octave environment)
>
> Application crashes with Segmentation Fault insiede the interpreter, and I
> cannot debug it inside because the interpreter is not compiled with debug
> information
>
> The OCTAVE_PATH environment variable define the path where the .m files are
> saved (see Octave manual for example version 4.4. March 2018 pag 17, but
> valid since a long time in all the Octave Version. I've been using it for at
> least 7 years
>
> The OCTAVE_PATH variable is correctly seen inside the C++ cose. Ifact if I
> run the program with:
>
> // THIS CODE IS WORKING
> in(0) = octave_value(a); // where a is a char[] = OCTAVE_PATH
> octave_value_list out = feval ("getenv", in, 1);   //getenv return the
> Evironmental Variable (see Octave manual)
> std::cout << out(0).string_value ()   // print the correct OCTAVE_PATH
> value
>
> It seems that is I use an embedded function i worke, but if I use  my own
> script it crashes
>
> Thanks a lot in advance
>
>
>
>
>
>
>
>
> --
> Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
>


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant
----- Original Message -----

> From: Tatsuro MATSUOKA
> To: andrea.delbravo"help-octave
> Cc:
> Date: 2018/3/26, Mon 03:05
> Subject: Re: Calling Octave from C++
> ----- Original Message -----
>>  From: andrea.delbravo
>>  To: help-octave
>>  Cc:
>>  Date: 2018/3/23, Fri 19:28
>>  Subject: Re: Calling Octave from C++
>>
>>  Well, sorry for the nmissing infos.
>>  I wirk with Fedora 26 Ocatve 4.2.1. I tried also with Fedora 27 Octave
> 4.2.2
>>  but the problem persist.
>>  The application run perfectly under fedora 25 Octave 4.0.3.
>>  I minimize the application in order to focalize the problem:
>>  After several initialization the core of the problem is:
>>
>>  // THIS CODE IS WORKING
>>  int qq =10;
>>  int rr =15;
>>  in(0) = octave_value(qq);
>>  in(1) = octave_value(rr);
>>  octave_value_list out = feval ("gcd", in, 1);
>>  std::cout << out(0).int_value ()
>>  and it prints the correct result = 5 the Greatest common disisor between 10
>>  and 15
>
> I have tested the above code on octave 4.2.2 for windows.
> The program ended with segmentation fault.
> Something might be wrong with standalone program on octave-4.2.2.
> I will build windows binary current stable (to octave 4.4 in near future)
> and test it and see platform dependence.
> Tatsuro
>
>>  but if I run
>>  // THIS CODE IN NOT WORKING
>>  octave_value_list out = feval ("pp", in, 1);
>>  where pp.m is a stupid Octave script which shuld disply the two numbers
>>  (tested and working in the Octave environment)
>>
>>  Application crashes with Segmentation Fault insiede the interpreter, and I
>>  cannot debug it inside because the interpreter is not compiled with debug
>>  information
>>
>>  The OCTAVE_PATH environment variable define the path where the .m files are
>>  saved (see Octave manual for example version 4.4. March 2018 pag 17, but
>>  valid since a long time in all the Octave Version. I've been using it
> for at
>>  least 7 years
>>
>>  The OCTAVE_PATH variable is correctly seen inside the C++ cose. Ifact if I
>>  run the program with:
>>
>>  // THIS CODE IS WORKING
>>  in(0) = octave_value(a); // where a is a char[] = OCTAVE_PATH
>>  octave_value_list out = feval ("getenv", in, 1);   //getenv
> return the
>>  Evironmental Variable (see Octave manual)
>>  std::cout << out(0).string_value ()   // print the correct
> OCTAVE_PATH
>>  value
>>
>>  It seems that is I use an embedded function i worke, but if I use  my own
>>  script it crashes
>>
>>  Thanks a lot in advance


After fixing the my fault of LD_LIBRARY_PATH
(see https://savannah.gnu.org/bugs/?53446#comment5)

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

int
main (void)
{
  octave_value_list in;
  // THIS CODE IS WORKING
  int qq =10;
  int rr =15;
  in(0) = octave_value(qq);
  in(1) = octave_value(rr);
  octave_value_list out = feval ("gcd", in, 1);
  std::cout << out(0).int_value ();
  clean_up_and_exit(0);
}

Still hang for me on current stable source (HG-ID 231847364696 upcoming 4.4).

gdb results are:

Thread 1 "test_01" received signal SIGABRT, Aborted.
0x00007ffff4ef0428 in __GI_raise (sig=sig@entry=6)
    at ../sysdeps/unix/sysv/linux/raise.c:54
54    ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007ffff4ef0428 in __GI_raise (sig=sig@entry=6)
    at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007ffff4ef202a in __GI_abort () at abort.c:89
#2  0x00007ffff76f7dc7 in octave::__get_interpreter__ (who="feval")
    at libinterp/corefcn/interpreter-private.cc:49
#3  0x00007ffff76f7e59 in octave::__get_symbol_table__ (who="feval")
    at libinterp/corefcn/interpreter-private.cc:86
#4  0x00007ffff73951a1 in octave::feval (name="gcd", args=...,
    nargout=nargout@entry=1) at libinterp/parse-tree/oct-parse.yy:5197
#5  0x000000000040338e in feval (nargout=1, args=..., name="gcd")
    at /opt/octave-stable/include/octave-4.3.0+/octave/../octave/parse.h:647

Tatsuro
#6  main () at test_01.cc:16


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

Mike Miller-4
On Tue, Mar 27, 2018 at 09:16:41 +0900, Tatsuro MATSUOKA wrote:

> #include <iostream>
> #include <octave/oct.h>
> #include <octave/octave.h>
> #include <octave/parse.h>
> #include <octave/interpreter.h>
>
> int
> main (void)
> {
>   octave_value_list in;
>   // THIS CODE IS WORKING
>   int qq =10;
>   int rr =15;
>   in(0) = octave_value(qq);
>   in(1) = octave_value(rr);
>   octave_value_list out = feval ("gcd", in, 1);
>   std::cout << out(0).int_value ();
>   clean_up_and_exit(0);
> }
>
> Still hang for me on current stable source (HG-ID 231847364696 upcoming 4.4).
This is not surprising at all because you haven't initialized the Octave
interpreter. This is not a complete example.

Please compare this code with examples/code/embedded.cc

  https://hg.savannah.gnu.org/hgweb/octave/file/baa7e37453b1/examples/code/embedded.cc

And compare the equivalent example for Octave 4.2

  https://hg.savannah.gnu.org/hgweb/octave/file/ea09770fb556/examples/code/embedded.cc

--
mike



signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant
----- Original Message -----

> From: Mike Miller
> To: help-octave
> Cc:
> Date: 2018/3/27, Tue 09:57
> Subject: Re: Calling Octave from C++
>
> On Tue, Mar 27, 2018 at 09:16:41 +0900, Tatsuro MATSUOKA wrote:
>>  #include <iostream>
>>  #include <octave/oct.h>
>>  #include <octave/octave.h>
>>  #include <octave/parse.h>
>>  #include <octave/interpreter.h>
>>
>>  int
>>  main (void)
>>  {
>>    octave_value_list in;
>>    // THIS CODE IS WORKING
>>    int qq =10;
>>    int rr =15;
>>    in(0) = octave_value(qq);
>>    in(1) = octave_value(rr);
>>    octave_value_list out = feval ("gcd", in, 1);
>>    std::cout << out(0).int_value ();
>>    clean_up_and_exit(0);
>>  }
>>
>>  Still hang for me on current stable source (HG-ID 231847364696 upcoming
> 4.4).
>
> This is not surprising at all because you haven't initialized the Octave
> interpreter. This is not a complete example.
>
> Please compare this code with examples/code/embedded.cc
>
>  
> https://hg.savannah.gnu.org/hgweb/octave/file/baa7e37453b1/examples/code/embedded.cc
>
> And compare the equivalent example for Octave 4.2
>
>  
> https://hg.savannah.gnu.org/hgweb/octave/file/ea09770fb556/examples/code/embedded.cc
>
> --
> mike

Thanks! Worked as expected.

Tatsuro

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

int
main (void)
{
  // Create interpreter.

  octave::interpreter interpreter;

  try
    {
      int status = interpreter.execute ();

      if (status != 0)
        {
          std::cerr << "creating embedded Octave interpreter failed!"
                    << std::endl;
          return status;
        }

        octave_value_list in;

        // THIS CODE IS WORKING
        int qq =10;
        int rr =15;
        in(0) = octave_value(qq);
        in(1) = octave_value(rr);
        octave_value_list out = octave::feval ("gcd", in, 1);
        std::cout << out(0).int_value ()
                  << std::endl;
        //clean_up_and_exit(0);
     
    }
  catch (const octave::exit_exception& ex)
    {
      std::cerr << "Octave interpreter exited with status = "
                << ex.exit_status () << std::endl;
    }
  catch (const octave::execution_exception&)
    {
      std::cerr << "error encountered in Octave evaluator!" << std::endl;
    }

  return 0;
}


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant
********************
// THIS CODE IS WORKING
int qq =10;
int rr =15;
in(0) = octave_value(qq);
in(1) = octave_value(rr);
octave_value_list out = feval ("gcd", in, 1);
std::cout << out(0).int_value ()
and it prints the correct result = 5 the Greatest common disisor between 10
and 15

but if I run
// THIS CODE IN NOT WORKING
octave_value_list out = feval ("pp", in, 1);
where pp.m is a stupid Octave script which shuld disply the two numbers
(tested and working in the Octave environment)
*****************************
 
%pp.m
function y = pp()
    disp(5)
    disp(6)
end

main (void)
{
  // Create interpreter.

  octave::interpreter interpreter;

  try
    {
      int status = interpreter.execute ();

      if (status != 0)
        {
          std::cerr << "creating embedded Octave interpreter failed!"
                    << std::endl;
          return status;
        }

        octave_value_list in;

        // THIS CODE IS WORKING
        int qq =10;
        int rr =15;
        in(0) = octave_value(qq);
        in(1) = octave_value(rr);
        octave_value_list out = octave::feval ("pp", in, 1);
        std::cout << out(0).int_value ()
                  << std::endl;
        //clean_up_and_exit(0);
     
    }
  catch (const octave::exit_exception& ex)
    {
      std::cerr << "Octave interpreter exited with status = "
                << ex.exit_status () << std::endl;
    }
  catch (const octave::execution_exception&)
    {
      std::cerr << "error encountered in Octave evaluator!" << std::endl;
    }

  return 0;
}

$ ./test_02
 5
 6
error: octave_base_value::double_value (): wrong type argument '<unknown type>'
error: octave_base_value::int_value (): wrong type argument '<unknown type>'
error encountered in Octave evaluator!

Perhaps I have make mistakes but does not hang.

Tatsuro


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant
----- Original Message -----

> From: Tatsuro MATSUOKA
> To: tmacchan; Mike Miller  "help-octave andrea.delbravo
> Cc:
> Date: 2018/3/27, Tue 13:19
> Subject: Re: Calling Octave from C++

Try on octave 4.2.2
cd /home/mousei7/work/Octave/octave-ML/Calling_Octave_from_Cpp/octave-4.2.2

export LD_LIBRARY_PATH=/opt/octave-4.2.2/lib/octave/4.2.2:$LD_LIBRARY_PATH
export PATH=/opt/octave-4.2.2/bin:$PATH
echo $LD_LIBRARY_PATH
echo $PATH
octave --version

$ echo $LD_LIBRARY_PATH
/opt/octave-4.2.2/lib/octave/4.2.2:/usr/local/lib
$ echo $PATH
/opt/octave-4.2.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ octave --version
GNU Octave, version 4.2.2

$ LC_ALL=C ./test_01_02
Segmentation fault (core dump)

compiled with -g

$ LC_ALL=C gdb ./test_01_02

Thread 1 "test_01_02" received signal SIGSEGV, Segmentation fault.
octave::cmdline_options::cmdline_options (this=0x7fffffffdcb0, opts=...)
    at ../libinterp/octave.cc:249
249        : m_force_gui (opts.m_force_gui),
(gdb) bt
#0  octave::cmdline_options::cmdline_options (this=0x7fffffffdcb0, opts=...)
    at ../libinterp/octave.cc:249
#1  0x00007ffff770e2f4 in octave::application::options (this=<optimized out>)
    at ../libinterp/octave.h:197
#2  octave::interpreter::interpreter (this=0x7fffffffddf0, app_context=0x0,
    embedded=<optimized out>) at ../libinterp/corefcn/interpreter.cc:533
#3  0x0000000000401c85 in main () at test_01_02.cc:12
(gdb) s
Couldn't get registers: No such process.
Couldn't get registers: No such process.
Couldn't get registers: No such process.
(gdb) [Thread 0x7fffd4ca8700 (LWP 3558) exited]
[Thread 0x7fffd74a9700 (LWP 3557) exited]
[Thread 0x7fffdbcaa700 (LWP 3556) exited]
[Thread 0x7fffe0cac700 (LWP 3554) exited]
[Thread 0x7fffe14ad700 (LWP 3553) exited]
[Thread 0x7fffe3cae700 (LWP 3552) exited]
[Thread 0x7ffff7fa77c0 (LWP 3548) exited]
Couldn't get registers: No such process.
(gdb) [Thread 0x7ffff7fa77c0 (LWP 3548) exited]
Couldn't get registers: No such process.
(gdb) [Thread 0x7fffde4ab700 (LWP 3555) exited]

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.

For me something seems wrong with octave-4.2.2.
Upcoming 4.4 (now still 4.3.0+), code rewrite as indicated by Mike,
problem seems to be solved.

Tatsuro

// C++ code used
#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>

int
main (void)
{
  // Create interpreter.

  octave::interpreter interpreter;

  try
    {
      int status = interpreter.execute ();

      if (status != 0)
        {
          std::cerr << "creating embedded Octave interpreter failed!"
                    << std::endl;
          return status;
        }

        octave_value_list in;

        // THIS CODE IS WORKING
        int qq =10;
        int rr =15;
        in(0) = octave_value(qq);
        in(1) = octave_value(rr);
        octave_value_list out = feval ("gcd", in, 1);
        std::cout << out(0).int_value ()
                  << std::endl;
        //clean_up_and_exit(0);
     
    }
  catch (const octave::exit_exception& ex)
    {
      std::cerr << "Octave interpreter exited with status = "
                << ex.exit_status () << std::endl;
    }
  catch (const octave::execution_exception&)
    {
      std::cerr << "error encountered in Octave evaluator!" << std::endl;
    }

  return 0;
}

>
> $ ./test_02
>  5
>  6
> error: octave_base_value::double_value (): wrong type argument '<unknown
> type>'
> error: octave_base_value::int_value (): wrong type argument '<unknown
> type>'
> error encountered in Octave evaluator!
>
> Perhaps I have make mistakes but does not hang.
>
> Tatsuro


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

Mike Miller-4
On Tue, Mar 27, 2018 at 13:39:26 +0900, Tatsuro MATSUOKA wrote:
> For me something seems wrong with octave-4.2.2.
> Upcoming 4.4 (now still 4.3.0+), code rewrite as indicated by Mike,
> problem seems to be solved.

As I tried to show in my last message, the example is different for
Octave 4.2 vs 4.4.

In Octave 4.2, you need to initialize the interpreter with

    string_vector argv (2);
    argv(0) = "embedded";
    argv(1) = "-q";
    octave_main (2, argv.c_str_vec (), 1);

In Octave 4.4, you need to initialize the interpreter with

    octave::interpreter interpreter;
    int status = interpreter.execute ();

--
mike



signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant




----- Original Message -----

> From: Mike Miller <[hidden email]>
> To: [hidden email]
> Cc:
> Date: 2018/3/27, Tue 13:51
> Subject: Re: Calling Octave from C++
>
> On Tue, Mar 27, 2018 at 13:39:26 +0900, Tatsuro MATSUOKA wrote:
>>  For me something seems wrong with octave-4.2.2.
>>  Upcoming 4.4 (now still 4.3.0+), code rewrite as indicated by Mike,
>>  problem seems to be solved.
>
> As I tried to show in my last message, the example is different for
> Octave 4.2 vs 4.4.
>
> In Octave 4.2, you need to initialize the interpreter with
>
>     string_vector argv (2);
>     argv(0) = "embedded";
>     argv(1) = "-q";
>     octave_main (2, argv.c_str_vec (), 1);
>
> In Octave 4.4, you need to initialize the interpreter with
>
>     octave::interpreter interpreter;
>     int status = interpreter.execute ();
>
> --
> mike

Thanks Mike. That worked.

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

int
main (void)
{
    string_vector argv (2);
    argv(0) = "test_01_03";
    argv(1) = "-q";
    octave_main (2, argv.c_str_vec (), 1);

    octave_value_list in;

    // THIS CODE IS WORKING
    int qq =10;
    int rr =15;
    in(0) = octave_value(qq);
    in(1) = octave_value(rr);
    octave_value_list out = feval ("gcd", in, 1);
    std::cout << out(0).int_value ()
              << std::endl;
  return 0;
}

the above worked

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

int
main (void)
{
    string_vector argv (2);
    argv(0) = "test_02";
    argv(1) = "-q";
    octave_main (2, argv.c_str_vec (), 1);

    octave_value_list in;

    // THIS CODE IS WORKING
    int qq =10;
    int rr =15;
    in(0) = octave_value(qq);
    in(1) = octave_value(rr);
    octave_value_list out = feval ("pp", in, 1);
    std::cout << out(0).int_value ()
              << std::endl;
  return 0;
}

the above hanged as original author (Andrea) told,

$ LC_ALL=C gdb ./test_02

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffe3cae700 (LWP 4060)]
[New Thread 0x7fffe14ad700 (LWP 4061)]
[New Thread 0x7fffdecac700 (LWP 4062)]
[New Thread 0x7fffdc4ab700 (LWP 4063)]
[New Thread 0x7fffd9caa700 (LWP 4064)]
[New Thread 0x7fffd94a9700 (LWP 4065)]
[New Thread 0x7fffd4ca8700 (LWP 4066)]

Thread 1 "test_02" received signal SIGSEGV, Segmentation fault.
tree_statement_list::accept (this=0xa4dc30, tw=...)
    at ../libinterp/parse-tree/pt-stmt.cc:326
326      tw.visit_statement_list (*this);
(gdb) bt
#0  tree_statement_list::accept (this=0xa4dc30, tw=...)
    at ../libinterp/parse-tree/pt-stmt.cc:326
#1  0x00007ffff731e106 in octave_user_function::do_multi_index_op (
    this=0x7c1d80, nargout=1, _args=..., lvalue_list=0x0)
    at ../libinterp/octave-value/ov-usr-fcn.cc:610
#2  0x00007ffff7317b84 in octave_user_function::do_multi_index_op (
    this=<optimized out>, nargout=<optimized out>, args=...)
    at ../libinterp/octave-value/ov-usr-fcn.cc:461
#3  0x00007ffff73218e5 in octave_value::do_multi_index_op (
    this=this@entry=0x7fffffffdd40, nargout=nargout@entry=1, idx=...)
    at ../libinterp/octave-value/ov.cc:1529
#4  0x00007ffff73aa69b in feval (name="pp", args=..., nargout=nargout@entry=1)
    at libinterp/parse-tree/oct-parse.yy:4807
#5  0x0000000000401d72 in main () at test_02.cc:22
(gdb) s
Couldn't get registers: No such process.
Couldn't get registers: No such process.
Couldn't get registers: No such process.
(gdb) [Thread 0x7fffd4ca8700 (LWP 4066) exited]
[Thread 0x7fffd94a9700 (LWP 4065) exited]
[Thread 0x7fffd9caa700 (LWP 4064) exited]
[Thread 0x7fffdc4ab700 (LWP 4063) exited]
[Thread 0x7fffdecac700 (LWP 4062) exited]
[Thread 0x7fffe14ad700 (LWP 4061) exited]
[Thread 0x7fffe3cae700 (LWP 4060) exited]

Tatsuro



Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant
 ----- Original Message -----

>>  From: Mike Miller
>>  To: help-octave
>>  Cc:
>>  Date: 2018/3/27, Tue 13:51
>>  Subject: Re: Calling Octave from C++
>>
>>  On Tue, Mar 27, 2018 at 13:39:26 +0900, Tatsuro MATSUOKA wrote:
>>>   For me something seems wrong with octave-4.2.2.
>>>   Upcoming 4.4 (now still 4.3.0+), code rewrite as indicated by Mike,
>>>   problem seems to be solved.
>>
>>  As I tried to show in my last message, the example is different for
>>  Octave 4.2 vs 4.4.
>>
>>  In Octave 4.2, you need to initialize the interpreter with
>>
>>      string_vector argv (2);
>>      argv(0) = "embedded";
>>      argv(1) = "-q";
>>      octave_main (2, argv.c_str_vec (), 1);
>>
>>  In Octave 4.4, you need to initialize the interpreter with
>>
>>      octave::interpreter interpreter;
>>      int status = interpreter.execute ();
>>
>>  --
>>  mike
>
> Thanks Mike. That worked.
>
> #include <iostream>
> #include <octave/oct.h>
> #include <octave/octave.h>
> #include <octave/parse.h>
> #include <octave/interpreter.h>
>
> int
> main (void)
> {
>     string_vector argv (2);
>     argv(0) = "test_01_03";
>     argv(1) = "-q";
>     octave_main (2, argv.c_str_vec (), 1);
>
>     octave_value_list in;
>
>     // THIS CODE IS WORKING
>     int qq =10;
>     int rr =15;
>     in(0) = octave_value(qq);
>     in(1) = octave_value(rr);
>     octave_value_list out = feval ("gcd", in, 1);
>     std::cout << out(0).int_value ()
>               << std::endl;
>   return 0;
> }
>
> the above worked
>
> #include <iostream>
> #include <octave/oct.h>
> #include <octave/octave.h>
> #include <octave/parse.h>
> #include <octave/interpreter.h>
>
> int
> main (void)
> {
>     string_vector argv (2);
>     argv(0) = "test_02";
>     argv(1) = "-q";
>     octave_main (2, argv.c_str_vec (), 1);
>
>     octave_value_list in;
>
>     // THIS CODE IS NOT WORKING
>     int qq =10;
>     int rr =15;
>     in(0) = octave_value(qq);
>     in(1) = octave_value(rr);
>     octave_value_list out = feval ("pp", in, 1);
>     std::cout << out(0).int_value ()
>               << std::endl;
>   return 0;
> }
>
> the above hanged as original author (Andrea) told,
>
> $ LC_ALL=C gdb ./test_02
>
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library
> "/lib/x86_64-linux-gnu/libthread_db.so.1".
> [New Thread 0x7fffe3cae700 (LWP 4060)]
> [New Thread 0x7fffe14ad700 (LWP 4061)]
> [New Thread 0x7fffdecac700 (LWP 4062)]
> [New Thread 0x7fffdc4ab700 (LWP 4063)]
> [New Thread 0x7fffd9caa700 (LWP 4064)]
> [New Thread 0x7fffd94a9700 (LWP 4065)]
> [New Thread 0x7fffd4ca8700 (LWP 4066)]
>
> Thread 1 "test_02" received signal SIGSEGV, Segmentation fault.
> tree_statement_list::accept (this=0xa4dc30, tw=...)
>     at ../libinterp/parse-tree/pt-stmt.cc:326
> 326      tw.visit_statement_list (*this);
> (gdb) bt
> #0  tree_statement_list::accept (this=0xa4dc30, tw=...)
>     at ../libinterp/parse-tree/pt-stmt.cc:326
> #1  0x00007ffff731e106 in octave_user_function::do_multi_index_op (
>     this=0x7c1d80, nargout=1, _args=..., lvalue_list=0x0)
>     at ../libinterp/octave-value/ov-usr-fcn.cc:610
> #2  0x00007ffff7317b84 in octave_user_function::do_multi_index_op (
>     this=<optimized out>, nargout=<optimized out>, args=...)
>     at ../libinterp/octave-value/ov-usr-fcn.cc:461
> #3  0x00007ffff73218e5 in octave_value::do_multi_index_op (
>     this=this@entry=0x7fffffffdd40, nargout=nargout@entry=1, idx=...)
>     at ../libinterp/octave-value/ov.cc:1529
> #4  0x00007ffff73aa69b in feval (name="pp", args=...,
> nargout=nargout@entry=1)
>     at libinterp/parse-tree/oct-parse.yy:4807
> #5  0x0000000000401d72 in main () at test_02.cc:22
> (gdb) s
> Couldn't get registers: No such process.
> Couldn't get registers: No such process.
> Couldn't get registers: No such process.
> (gdb) [Thread 0x7fffd4ca8700 (LWP 4066) exited]
> [Thread 0x7fffd94a9700 (LWP 4065) exited]
> [Thread 0x7fffd9caa700 (LWP 4064) exited]
> [Thread 0x7fffdc4ab700 (LWP 4063) exited]
> [Thread 0x7fffdecac700 (LWP 4062) exited]
> [Thread 0x7fffe14ad700 (LWP 4061) exited]
> [Thread 0x7fffe3cae700 (LWP 4060) exited]
>
> Tatsuro
Andrea

With Mike's helps, I could reproduce what you met.

Perhaps 4.2.2 is the last release for octave 4.2.
Realistic solutions are: (just my idea)
 1. Wait until octave 4.4 will be released.
 2. Build current stable (now 4.3.0+).

 For 2., you need to install mercurial and (autotools (autoconf, automake)).
 $ hg clone https://www.octave.org/hg/octave 
 $ cd octave
 $ hg update stable
 (Once you clone, you need hg pull && hg update stable)
 $ ./bootstrap
 Then configure script is generated and you can build in the same way as release version.

HTH

Tatsuro



Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

andrea.delbravo
Thanks a lot, I'll try to build stable versione 4.3.0. Are we sure this
version will work with the "pp" function? ok, I'll try and I'll keep you
informed



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Calling Octave from C++

tmacchant




----- Original Message -----

> From: andrea.delbravo
> To: help-octave
> Cc:
> Date: 2018/3/27, Tue 19:23
> Subject: Re: Calling Octave from C++
>
>T hanks a lot, I'll try to build stable versione 4.3.0. Are we sure this
> version will work with the "pp" function? ok, I'll try and
> I'll keep you
> informed
>
See:
 
http://octave.1599824.n4.nabble.com/Calling-Octave-from-C-td4687200.html#a4687298

Spurious errors appears after pp.m execution but program did not hang.
But perhaps my code C++ code for new syntax is wrong.


Coding style for embedded program is changed after 4.3.

See
https://hg.savannah.gnu.org/hgweb/octave/file/baa7e37453b1/examples/code/embedded.cc

Tatsuro


12