[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
help with a DLD function that segfaults after its execution.
From: |
Guillem Borrell Nogueras |
Subject: |
help with a DLD function that segfaults after its execution. |
Date: |
Thu, 18 May 2006 20:57:56 +0200 |
User-agent: |
KMail/1.9.1 |
Hi.
I'm writing a wrapper to some ODE routines. This function tests how a
function from octave can be called as a C++ function, all into a DLD
function.
Here's the code
// test_function_call.cpp
#include <octave/oct.h>
#include <iostream>
using namespace std;
const int NDIM=3;
octave_function *input_fcn=0;
void f(double t,double *y,double *yp)
{
octave_value_list inval;
octave_value_list outval;
ColumnVector y_oct(NDIM);
inval.append(octave_value(t));
register int i;
for(i=0;i < NDIM;i++)
{
y_oct(i)=y[i];
}
inval.append(octave_value(y_oct));
outval=input_fcn->do_multi_index_op(1,inval);//first argument is nargout
ColumnVector yp_oct(outval(0).vector_value());
for(i=0;i < NDIM;i++)
{
yp[i]=yp_oct(i);
}
}
DEFUN_DLD(test_function_call,args, ,
"testing how to interface functions between octave and C++")
{
if (args(0).is_function_handle() || args(0).is_inline_function())
input_fcn=args(0).function_value();
else
{
error("this is not a function handle nor an inline function");
return octave_value(-1);
}
double t=1;
double y[NDIM];
double yp[NDIM];
y[0]=1;
y[1]=1;
y[2]=1;
f(t,y,yp);
register int j;
for(j=0;j < NDIM;j++)
{
cout << yp[j] << "\n";
}
cout << "segfaults" << endl;
}
This function just calls a function of the form:
[yp]=f(t,x) / x in R**3
and returns its result to cout
The function I call is the usual Lorentz attractor:
function xdot=lorentz(t,x)
a=10;b=28;c=8/3;
xdot(1,1)=a*(x(2)-x(1));
xdot(2,1)=x(1)*(b-x(3))-x(2);
xdot(3,1)=x(1)*x(2)-c*x(3);
Compilation goes fine but the function segfaults at the end of the execution
and I cant' find the reason.
>> test_function_call(@lorentz) # calls lorentz at [1,1,1]
0
26
-1.66667 <--the result is right
segfaults
panic: Segmentation fault -- stopping myself...
In fact I know the reason: I'm a C++ newbie.
GNU Octave, version 2.1.72 (i686-pc-linux-gnu)
gentoo, compiled with gcc 3.4.6
Thanks
guillem
--
Guillem Borrell Nogueras
WEBSITE
http://torroja.dmt.upm.es:9673/Guillem_Site/
BLOG
http://torroja.dmt.upm.es:9673/Guillem_Borrell/
EMAIL
guillemborrell_at_gmail.com (personal)
guillem_at_torroja.dmt.upm.es (CFD Lab. ETSIA)
- help with a DLD function that segfaults after its execution.,
Guillem Borrell Nogueras <=