Mercurial > hg > octave-lojdl
changeset 14339:3e4350f09a55 stable
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Feb 2012 15:54:10 -0500 |
parents | 1ecfba4427ff |
children | de99dde50ee1 |
files | src/DLD-FUNCTIONS/__delaunayn__.cc src/DLD-FUNCTIONS/__voronoi__.cc src/DLD-FUNCTIONS/convhulln.cc |
diffstat | 3 files changed, 42 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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; }
--- 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; }
--- 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; }