Mercurial > hg > octave-avbm
changeset 4302:ebc2d8e4968b
[project @ 2003-01-22 22:02:23 by jwe]
author | jwe |
---|---|
date | Wed, 22 Jan 2003 22:02:23 +0000 |
parents | 309ef552d7c6 |
children | e15a96673976 |
files | ChangeLog Makeconf.in libcruft/ChangeLog libcruft/misc/quit.h src/ChangeLog src/cutils.c src/utils.cc src/utils.h |
diffstat | 8 files changed, 169 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2003-01-22 John W. Eaton <jwe@bevo.che.wisc.edu> + + * Makeconf.in: Fix typo in previous change. + 2003-01-21 John W. Eaton <jwe@bevo.che.wisc.edu> * Makeconf.in (MKOCTFILE_INCFLAGS): Skip -I$(includedir) if
--- a/Makeconf.in +++ b/Makeconf.in @@ -282,7 +282,7 @@ canonical_host_type = @canonical_host_type@ # The -I flags to use for the mkoctfile script. -ifeq ($(includedir,/usr/include) +ifeq ($(includedir),/usr/include) MKOCTFILE_INCFLAGS = \ -I$(octincludedir) -I$(octincludedir)/octave else
--- a/libcruft/ChangeLog +++ b/libcruft/ChangeLog @@ -1,3 +1,8 @@ +2003-01-22 John W. Eaton <jwe@bevo.che.wisc.edu> + + * misc/quit.h (BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1, + BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2): New macros. + 2003-01-03 John W. Eaton <jwe@bevo.che.wisc.edu> * odessa/odessa_rscom.f (ODESSA_RSCOM): Fix apparent typo (LODE2
--- a/libcruft/misc/quit.h +++ b/libcruft/misc/quit.h @@ -87,7 +87,28 @@ } \ while (0) +/* Normally, you just want to use + + BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; + ... some code that calls a "foreign" function ... + END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; + + but sometimes it is useful to do something like + + BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1; + ... custom code here, normally ending in a call to + octave_throw_interrupt_exception ... + BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2; + + so that you can perform extra clean up operations before throwing + the interrupt exception. */ + #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \ + BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1; \ + octave_throw_interrupt_exception (); \ + BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2 + +#define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1 \ do \ { \ octave_jmp_buf saved_context; \ @@ -96,8 +117,9 @@ \ if (octave_set_current_context) \ { \ - octave_restore_current_context ((char *) saved_context); \ - octave_throw_interrupt_exception (); \ + octave_restore_current_context ((char *) saved_context) + +#define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2 \ } \ else \ { \
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-01-22 John W. Eaton <jwe@bevo.che.wisc.edu> + + * cutils.c (octave_raw_vsnprintf): New function. + * utils.cc (octave_snprintf): Move here from cutils.c. + (octave_Vsnprintf): Likewise. Allow octave_raw_vsnprintf to be + interrupted. + * utils.h (octave_vsnprintf, octave_snprintf): No longer extern "C". + 2003-01-21 John W. Eaton <jwe@bevo.che.wisc.edu> * pt-loop.cc (tree_complex_for_command::eval): Fix typo.
--- a/src/cutils.c +++ b/src/cutils.c @@ -119,80 +119,10 @@ return strncasecmp (s1, s2, n); } -/* XXX FIXME XXX -- we really need a configure test for this. */ - -#if defined __GNUC__ && __GNUC__ >= 3 -#define HAVE_C99_VSNPRINTF 1 -#endif - -/* We manage storage. User should not free it, and its contents are - only valid until next call to vsnprintf. */ - -char * -octave_vsnprintf (const char *fmt, va_list args) +int +octave_raw_vsnprintf (char *buf, size_t n, const char *fmt, va_list args) { - static size_t size = 100; - - static char *buf = 0; - - int nchars; - - if (! buf) - buf = malloc (size); - - if (! buf) - return 0; - -#if defined (HAVE_C99_VSNPRINTF) - - nchars = vsnprintf (buf, size, fmt, args); - - if (nchars >= size) - { - size = nchars + 1; - buf = realloc (buf, size); - - if (buf) - vsnprintf (buf, size, fmt, args); - } - -#else - - while (1) - { - nchars = vsnprintf (buf, size, fmt, args); - - if (nchars > -1) - return buf; - else - { - size *= 2; - - buf = realloc (buf, size); - - if (! buf) - return 0; - } - } - -#endif - - return buf; -} - -char * -octave_snprintf (const char *fmt, ...) -{ - char *retval = 0; - - va_list args; - va_start (args, fmt); - - retval = octave_vsnprintf (fmt, args); - - va_end (args); - - return retval; + return vsnprintf (buf, n, fmt, args); } /*
--- a/src/utils.cc +++ b/src/utils.cc @@ -44,6 +44,8 @@ #include <setjmp.h> +#include "quit.h" + #include "dir-ops.h" #include "file-ops.h" #include "file-stat.h" @@ -858,7 +860,13 @@ std::streambuf *sb = os.rdbuf (); if (sb) - retval = sb->vform (fmt, args); + { + BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; + + retval = sb->vform (fmt, args); + + END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; + } #else @@ -876,6 +884,115 @@ return retval; } +/* XXX FIXME XXX -- we really need a configure test for this. */ + +#if defined __GNUC__ && __GNUC__ >= 3 +#define HAVE_C99_VSNPRINTF 1 +#endif + +// We manage storage. User should not free it, and its contents are +// only valid until next call to vsnprintf. + +// Interrupts might happen if someone makes a call with something that +// will require a very large buffer. If we are interrupted in that +// case, we should make the buffer size smaller for the next call. + +#define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF \ + BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1; \ + delete [] buf; \ + buf = 0; \ + size = initial_size; \ + octave_throw_interrupt_exception (); \ + BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2 + +char * +octave_vsnprintf (const char *fmt, va_list args) +{ + static const size_t initial_size = 100; + + static size_t size = initial_size; + + static char *buf = 0; + + size_t nchars; + + if (! buf) + buf = new char [size]; + + if (! buf) + return 0; + +#if defined (HAVE_C99_VSNPRINTF) + + 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; + + vsnprintf (buf, size, fmt, args); + + END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; + } + } + +#else + + while (1) + { + BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_FOR_VSNPRINTF; + + nchars = octave_raw_vsnprintf (buf, size, fmt, args); + + END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; + + if (nchars > -1) + return buf; + else + { + delete [] buf; + + size *= 2; + + buf = new char [size]; + + if (! buf) + return 0; + } + } + +#endif + + return buf; +} + +char * +octave_snprintf (const char *fmt, ...) +{ + char *retval = 0; + + va_list args; + va_start (args, fmt); + + retval = octave_vsnprintf (fmt, args); + + va_end (args); + + return retval; +} + void octave_sleep (double seconds) {
--- a/src/utils.h +++ b/src/utils.h @@ -79,6 +79,10 @@ extern int octave_vformat (std::ostream& os, const char *fmt, va_list args); +extern char *octave_vsnprintf (const char *fmt, va_list args); + +extern char *octave_snprintf (const char *fmt, ...); + extern void octave_sleep (double seconds); extern "C" void octave_sleep (unsigned int seconds); @@ -89,9 +93,8 @@ extern "C" int octave_strncasecmp (const char *s1, const char *s2, size_t n); -extern "C" char *octave_snprintf (const char *fmt, ...); - -extern "C" char *octave_vsnprintf (const char *fmt, va_list args); +extern "C" int octave_raw_vsnprintf (char *buf, size_t n, const char *fmt, + va_list args); #endif