From bug-request at octave dot org Fri Jan 13 12:35:55 2006 Subject: Re: Segfault running this script (related to the subplots?) running against Octave 2.9.3 (CVS) From: "John W. Eaton" To: "Dmitri A. Sergatskov" Cc: Brendan Drew , bug@octave.org Date: Fri, 13 Jan 2006 13:35:42 -0500 On 12-Jan-2006, Dmitri A. Sergatskov wrote: | Brendan Drew wrote: | > Sorry -- I missed part of the equation. It works fine so long as you | > don't do a clear all first. | | OK this is a known problem though it still should not segfault... | | http://www.octave.org/mailing-lists/bug-octave/2005/416 | | Somehow it showed up again... | | > | > e.g: | > octave> kernel | > | > works just fine. | > | > octave> clear all | | That clears some internal variables which are essential | for communication with gnuplot. | | > octave> kernel | > | > segfaults. | | Mine does not segfault, but does not work either: | | | octave:1> clear all | octave:2> kernel | | multiplot> '/tmp/oct-1siyQt' "Chi^2 distance" lines set origin 0.5, 0.5; | ^ | line 0: invalid command | | | multiplot> '/tmp/oct-fVJwd8' "D(KDE | PDF)" lines set origin 0, 0; | ^ | line 0: invalid command | | | multiplot> '/tmp/oct-1WDjVM' "Original" lines , '/tmp/oct-Xj6mDr' "KDE" lines set origin 0.5, 0; | ^ | line 0: invalid command Please try the following patch. It is relative to the current CVS. jwe src/ChangeLog: 2006-01-13 John W. Eaton * DLD-FUNCTIONS/__gnuplot_raw__.l (F__gnuplot_init__): Delete function and PKG_ADD directive. (gnuplot::gnuplot): Call do_init here. (gnuplot::init): Delete static function. (gnuplot::close_all): New static function. (class gnuplot_X): New class. (gnpulot_X::X): New static instance. Index: src/DLD-FUNCTIONS/__gnuplot_raw__.l =================================================================== RCS file: /cvs/octave/src/DLD-FUNCTIONS/__gnuplot_raw__.l,v retrieving revision 1.1 diff -u -r1.1 __gnuplot_raw__.l --- src/DLD-FUNCTIONS/__gnuplot_raw__.l 13 Dec 2005 19:05:55 -0000 1.1 +++ src/DLD-FUNCTIONS/__gnuplot_raw__.l 13 Jan 2006 18:33:39 -0000 at @ -32,8 +32,6 @@ // PKG_ADD: mark_as_command ("__gnuplot_show__"); -// PKG_ADD: __gnuplot_init__ (); - // PKG_ADD: atexit ("closeplot"); #ifdef HAVE_CONFIG_H at @ -696,7 +694,7 @@ use_title_option (Vgnuplot_use_title_option), gnuplot_exe (Vgnuplot_binary), gnuplot_terminal_type (), plot_stream () - { } + { do_init (); } public: at @ -712,13 +710,9 @@ static void close (void); - static bool plot_stream_event_handler (pid_t pid, int status); + static void close_all (void); - static void init (void) - { - if (ensure_instance ()) - instance->do_init (); - } + static bool plot_stream_event_handler (pid_t pid, int status); static void send (const std::string& cmd) { at @ -895,6 +889,19 @@ } } +void +gnuplot::close_all (void) +{ + for (std::map::const_iterator p = instance_map.begin (); + p != instance_map.end (); + p++) + { + gnuplot *elt = p->second; + + elt->do_close (); + } +} + pid_t gnuplot::pid (void) const { at @ -1454,6 +1461,19 @@ return retstr; } +// The static instance of this class is here so that +// gnuplot::close_all will be called when the .oct file is unloaded. + +class +gnuplot_X +{ +public: + gnuplot_X (void) { } + ~gnuplot_X (void) { gnuplot::close_all (); } +}; + +static gnuplot_X X; + static int automatic_replot (void) { at @ -1662,16 +1682,6 @@ // User-callable functions // ----------------------- -DEFUN_DLD (__gnuplot_init__, , , - "-*- texinfo -*-\n\ - at deftypefn {Loadable Function} __gnuplot_init__ ()\n\ - at end deftypefn") -{ - gnuplot::init (); - - return octave_value_list (); -} - DEFUN_DLD (clearplot, , , "-*- texinfo -*-\n\ at deftypefn {Built-in Function} {} clearplot\n\ ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------