Mercurial > hg > octave-avbm
changeset 10257:cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 03 Feb 2010 06:34:29 -0500 |
parents | c84186ad78f3 |
children | e317791645c4 |
files | ChangeLog acinclude.m4 bootstrap.conf configure.ac src/ChangeLog src/DLD-FUNCTIONS/convhulln.cc src/utils.cc |
diffstat | 7 files changed, 43 insertions(+), 106 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-02-03 John W. Eaton <jwe@octave.org> + + * acinclude.m4 (OCTAVE_HAVE_C99_VSNPRINTF): Delete. + * configure.ac: Don't call OCTAVE_HAVE_C99_VSNPRINTF. + Don't check for snprintf, vfprintf, vsprintf, vsnprintf, or _snprintf. + * bootstrap.conf (gnulib_modules): Include vsprintf in the list. + 2010-02-03 John W. Eaton <jwe@octave.org> * configure.ac: Don't check for strerror.
--- a/acinclude.m4 +++ b/acinclude.m4 @@ -1360,44 +1360,6 @@ [$5] fi ]) -dnl -dnl Do we have a working c99 vsnprintf function? -dnl -dnl OCTAVE_HAVE_C99_VSNPRINTF -AC_DEFUN([OCTAVE_HAVE_C99_VSNPRINTF], [ - AC_CACHE_CHECK([for c99 vsnprintf], [oct_cv_c99_vsnprintf], - [AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h> -#include <stdarg.h> -#include <stdlib.h> - -int -doit(char * s, ...) -{ - char buffer[32]; - va_list args; - int r; - - va_start(args, s); - r = vsnprintf(buffer, 5, s, args); - va_end(args); - - if (r != 7) - exit(1); - - exit(0); -} - ]],[ -doit("1234567");])], - [oct_cv_c99_vsnprintf=yes], - [oct_cv_c99_vsnprintf=no], - [oct_cv_c99_vsnprintf="guessing no"])]) - -case $oct_cv_c99_vsnprintf in -yes) - AC_DEFINE([HAVE_C99_VSNPRINTF], [1], [Define if you have a c99 vsnprintf]) - ;; -esac -]) ############################################################################## ##############################################################################
--- a/configure.ac +++ b/configure.ac @@ -1496,9 +1496,9 @@ mkstemp pipe putenv \ realpath resolvepath rindex roundl select setgrent setlocale \ setpwent setvbuf siglongjmp \ - snprintf strsignal tempnam tgammaf trunc umask \ - uname utime vfprintf vsprintf vsnprintf waitpid \ - _chmod _snprintf x_utime _utime32) + strsignal tempnam tgammaf trunc umask \ + uname utime waitpid \ + _chmod x_utime _utime32) AC_LANG_PUSH(C++) AC_CHECK_DECLS([exp2, round, tgamma], [], [], [[#include <cmath>]]) @@ -1544,7 +1544,6 @@ ;; esac -OCTAVE_HAVE_C99_VSNPRINTF OCTAVE_SMART_PUTENV case "$canonical_host_type" in
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2010-02-03 John W. Eaton <jwe@octave.org> + + * utils.cc (octave_vsnprintf): Assume we have vsnprintf with + semantics that match the version provided by gnulib. + + * DLD-FUNCTIONS/convhulln.cc (Fconvhulln): + Use std::sstream instead of fixed-length buffer and snprintf. + 2010-02-03 John W. Eaton <jwe@octave.org> * cutils.c (octave_usleep): Implement using nanosleep.
--- a/src/DLD-FUNCTIONS/convhulln.cc +++ b/src/DLD-FUNCTIONS/convhulln.cc @@ -41,19 +41,13 @@ #include "oct-obj.h" #include "parse.h" -#ifdef HAVE_QHULL -#if defined(HAVE__SNPRINTF) && !defined(HAVE_SNPRINTF) -#define snprintf _snprintf -#endif - extern "C" { #include <qhull/qhull_a.h> } -#ifdef NEED_QHULL_VERSION +#if defined (HAVE_QHULL) && defined (NEED_QHULL_VERSION) char qh_version[] = "convhulln.oct 2007-07-24"; #endif -#endif DEFUN_DLD (convhulln, args, nargout, "-*- texinfo -*-\n\ @@ -122,11 +116,20 @@ boolT ismalloc = False; - OCTAVE_LOCAL_BUFFER (char, flags, 250); + std::ostringstream buf; + + buf << "qhull QJ " << options; + + std::string buf_string = buf.str (); - // hmm, lots of options for qhull here - // QJ guarantees that the output will be triangles - snprintf (flags, 250, "qhull QJ %s", options.c_str ()); + // FIXME -- we can't just pass buf_string.c_str () to qh_new_qhull + // because the argument is not declared const. Ugh. Unless + // qh_new_qhull really needs to modify this argument, someone should + // fix QHULL. + + OCTAVE_LOCAL_BUFFER (char, flags, buf_string.length () + 1); + + strcpy (flags, buf_string.c_str ()); if (! qh_new_qhull (dim, n, pt_array, ismalloc, flags, 0, stderr)) {
--- a/src/utils.cc +++ b/src/utils.cc @@ -1225,11 +1225,7 @@ static char *buf = 0; -#if defined (HAVE_C99_VSNPRINTF) - size_t nchars = 0; -#else int nchars = 0; -#endif if (! buf) buf = new char [size]; @@ -1237,43 +1233,6 @@ if (! buf) return 0; -#if defined (HAVE_C99_VSNPRINTF) - - // Note that the caller is responsible for calling va_end on args. - // We will do it for saved_args. - - va_list saved_args; - - SAVE_ARGS (saved_args, args); - - BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF; - - nchars = octave_raw_vsnprintf (buf, size, fmt, args); - - END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; - - if (nchars >= size) - { - size = nchars + 1; - - delete [] buf; - - buf = new char [size]; - - if (buf) - { - BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF; - - octave_raw_vsnprintf (buf, size, fmt, saved_args); - - END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; - } - } - - va_end (saved_args); - -#else - while (1) { va_list saved_args; @@ -1288,23 +1247,21 @@ END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; - if (nchars > -1 && nchars < size-1) - return buf; + if (nchars > -1 && nchars < size) + break; else - { - delete [] buf; - - size *= 2; + { + delete [] buf; - buf = new char [size]; + size = nchars + 1;; + + buf = new char [size]; - if (! buf) - return 0; - } + if (! buf) + return 0; + } } -#endif - return buf; }