[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: signals hanling in octave
From: |
Paul Kienzle |
Subject: |
Re: signals hanling in octave |
Date: |
Thu, 19 Oct 2006 23:30:25 -0400 |
On Oct 19, 2006, at 4:21 PM, Miroslaw Dach wrote:
Dear All,
I am using mex program under octave. The only missing function in
octave 2.9.9 implementation (which I need to use) is mexAtExit.
This function registers the handler function which is call before
exiting from Matlab. As the replacement of that function on octave I
have tried to use atexit but my function is not call as the first one
before closing the octave and octave simply stalls. John has
suggested to me to add the pointer in the octave_mex_function class
but i am not so familiar with octave code. I was just playing with the
standard c signal function to register my handler but I do not know
which signal is sent when octave quits.
I would appreciate very much is somebody could help me on that.
The functions you are interested in are in the src directory.
ov-fcn.h - base octave function class
ov-mex-fcn.{cc,h} - mex function class
mex.h, mex.cc - mex function definitions
One thing you could do is hook into the destructor in ov-mex-fcn.cc.
Just before removing the function, you can call the 'exit_fcn_ptr'
handle if it is not 0. This handle would be stored in the
octave_mex_function class along with mex_fcn_ptr. Don't forget to
initialize it to 0. Add an at_exit(fcn) method to octave_mex_function
which sets exit_fcn_ptr.
In class mex defined in mex.cc you will need to define an at_exit(fcn)
method which sets the exit_fcn_handle of the octave_mex_function
object. mexAtExit(fcn) is then a call to mex_context->at_exit(fcn).
Writing mex::at_exit(fcn) will be a bit tricky.
The clean way would be to pass a pointer to the octave_function handle
'this' through C_mex or Fortran_mex. Store this handle in class mex
when it is created. It can then be used directly by function_name and
at_exit to access octave_mex_function.
The hackish way is to use the same trick I used when mex was not part
of Octave, and grab the handle to the currently executing function from
the octave_call_stack.
I've implemented the hackish way in the attached patch. I haven't
tried compiling it or running it so you will have some work ahead of
you, but this should get you most of the way there.
- Paul
mexAtExit.patch
Description: Binary data