# HG changeset patch # User John W. Eaton # Date 1328561650 18000 # Node ID 3e4350f09a554979307a5bd5925ec830956c204e # Parent 1ecfba4427ff208b4793a4ebd879e950ae581c70 close temporary files opened for Qhull * __delaunay__.cc (close_fcn): New static function. (F__delaunay__): Add close_fcn and outfile to unwind protect stack. * __voronoi__.cc (close_fcn): New static function. (F__voronoi__): Add close_fcn and outfile to unwind protect stack. * convhull.cc (close_fcn): New static function. (Fconvhull): Add close_fcn and outfile to unwind protect stack. diff --git a/src/DLD-FUNCTIONS/__delaunayn__.cc b/src/DLD-FUNCTIONS/__delaunayn__.cc --- a/src/DLD-FUNCTIONS/__delaunayn__.cc +++ b/src/DLD-FUNCTIONS/__delaunayn__.cc @@ -49,6 +49,7 @@ #include "defun-dld.h" #include "error.h" #include "oct-obj.h" +#include "unwind-prot.h" #if defined (HAVE_QHULL) # include "oct-qhull.h" @@ -57,6 +58,12 @@ # endif #endif +static void +close_fcn (FILE *f) +{ + gnulib::fclose (f); +} + DEFUN_DLD (__delaunayn__, args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{T} =} __delaunayn__ (@var{pts})\n\ @@ -121,6 +128,8 @@ sprintf (flags, "qhull d %s", options.c_str ()); + unwind_protect frame; + // Replace the outfile pointer with stdout for debugging information. #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM) FILE *outfile = gnulib::fopen ("NUL", "w"); @@ -128,10 +137,12 @@ FILE *outfile = gnulib::fopen ("/dev/null", "w"); #endif FILE *errfile = stderr; - - if (! outfile) + + if (outfile) + frame.add_fcn (close_fcn, outfile); + else { - error ("__delaunayn__: Unable to create temporary file for output."); + error ("__delaunayn__: unable to create temporary file for output"); return retval; } diff --git a/src/DLD-FUNCTIONS/__voronoi__.cc b/src/DLD-FUNCTIONS/__voronoi__.cc --- a/src/DLD-FUNCTIONS/__voronoi__.cc +++ b/src/DLD-FUNCTIONS/__voronoi__.cc @@ -44,6 +44,7 @@ #include "defun-dld.h" #include "error.h" #include "oct-obj.h" +#include "unwind-prot.h" #if defined (HAVE_QHULL) # include "oct-qhull.h" @@ -52,6 +53,12 @@ # endif #endif +static void +close_fcn (FILE *f) +{ + gnulib::fclose (f); +} + DEFUN_DLD (__voronoi__, args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{caller}, @var{pts})\n\ @@ -115,6 +122,8 @@ boolT ismalloc = false; + unwind_protect frame; + // Replace the outfile pointer with stdout for debugging information. #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM) FILE *outfile = gnulib::fopen ("NUL", "w"); @@ -122,10 +131,12 @@ FILE *outfile = gnulib::fopen ("/dev/null", "w"); #endif FILE *errfile = stderr; - - if (! outfile) + + if (outfile) + frame.add_fcn (close_fcn, outfile); + else { - error ("__voronoi__: Unable to create temporary file for output."); + error ("__voronoi__: unable to create temporary file for output"); return retval; } diff --git a/src/DLD-FUNCTIONS/convhulln.cc b/src/DLD-FUNCTIONS/convhulln.cc --- a/src/DLD-FUNCTIONS/convhulln.cc +++ b/src/DLD-FUNCTIONS/convhulln.cc @@ -40,6 +40,7 @@ #include "error.h" #include "oct-obj.h" #include "parse.h" +#include "unwind-prot.h" #if defined (HAVE_QHULL) # include "oct-qhull.h" @@ -48,6 +49,12 @@ # endif #endif +static void +close_fcn (FILE *f) +{ + gnulib::fclose (f); +} + DEFUN_DLD (convhulln, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{h} =} convhulln (@var{pts})\n\ @@ -128,6 +135,8 @@ boolT ismalloc = false; + unwind_protect frame; + // Replace the outfile pointer with stdout for debugging information. #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM) FILE *outfile = gnulib::fopen ("NUL", "w"); @@ -135,10 +144,12 @@ FILE *outfile = gnulib::fopen ("/dev/null", "w"); #endif FILE *errfile = stderr; - - if (! outfile) + + if (outfile) + frame.add_fcn (close_fcn, outfile); + else { - error ("convhulln: Unable to create temporary file for output."); + error ("convhulln: unable to create temporary file for output"); return retval; }