octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Octave 2.1.37 available for ftp


From: John W. Eaton
Subject: Re: Octave 2.1.37 available for ftp
Date: Thu, 24 Oct 2002 16:46:51 -0500

On 24-Oct-2002, Paul Kienzle <address@hidden> wrote:

| For the cygwin build I'm getting the following:
| 
|       octave> tic; x=rand(100); toc
|       ans = 0.032001
|       octave> tic; sprintf("%15g ", x); toc
|       ans = 108.51
|             ^^^^^^
| 
| My slightly faster linux box gives the following:
| 
|       octave:4> tic; x=rand(100); toc
|       ans = 0.020411
|       octave:5> tic; sprintf("%15g ", x); toc
|       ans = 0.37612
| 
| I can avoid using sprintf for now, but when I get to
| it, do you think the problem is more likely in cygwin
| itself, or somewhere in the octave layer above cygwin.

I think the problem is partially with stringstreams and gcc-2.95.x.
The good news is that it appears to be fixed with g++ 3.2.  But to
make things better for Octave with 2.95.x, I think the following patch
will help.

If you want details, ask.  For now, I'm too tired of looking at this
problem to write up the details.

jwe

liboctave/ChangeLog:

2002-10-24  John W. Eaton  <address@hidden>

        * lo-sstream.h: Undef HAVE_SSTREAM if using a version of g++
        earlier than 3.0.

src/ChangeLog:

2002-10-24  John W. Eaton  <address@hidden>

        * cutils.c (octave_vsnprintf): Buffer and buffer size now static.
        * utils.cc (octave_vformat): Don't free buffer returned from
        octave_vsnprintf here.
 

Index: liboctave/lo-sstream.h
===================================================================
RCS file: /usr/local/cvsroot/octave/liboctave/lo-sstream.h,v
retrieving revision 1.1
diff -u -r1.1 lo-sstream.h
--- liboctave/lo-sstream.h      17 Aug 2002 19:38:32 -0000      1.1
+++ liboctave/lo-sstream.h      24 Oct 2002 21:43:56 -0000
@@ -23,6 +23,10 @@
 #if !defined (octave_liboctave_sstream_h)
 #define octave_liboctave_sstream_h 1
 
+#if defined (__GNUG__) && __GNUC__ < 3
+#undef HAVE_SSTREAM
+#endif
+
 #ifdef HAVE_SSTREAM
 
 #include <sstream>
Index: src/cutils.c
===================================================================
RCS file: /usr/local/cvsroot/octave/src/cutils.c,v
retrieving revision 1.10
diff -u -r1.10 cutils.c
--- src/cutils.c        3 Oct 2002 19:08:45 -0000       1.10
+++ src/cutils.c        24 Oct 2002 21:44:03 -0000
@@ -119,13 +119,19 @@
   return strncasecmp (s1, s2, n);
 }
 
+// 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)
 {
 #if defined (HAVE_VSNPRINTF)
-  size_t size = 100;
+  static size_t size = 100;
+
+  static char *buf = 0;
 
-  char *buf = malloc (size);
+  if (! buf)
+    buf = malloc (size);
 
   while (1)
     {
Index: src/utils.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/utils.cc,v
retrieving revision 1.145
diff -u -r1.145 utils.cc
--- src/utils.cc        8 Oct 2002 23:48:46 -0000       1.145
+++ src/utils.cc        24 Oct 2002 21:44:05 -0000
@@ -717,19 +717,7 @@
 
 #if defined (__GNUG__) && !CXX_ISO_COMPLIANT_LIBRARY
 
-  OSSTREAM buf;
-
-  buf.vform (fmt, args);
-
-  buf << OSSTREAM_ENDS;
-
-  std::string s = OSSTREAM_STR (buf);
-
-  OSSTREAM_FREEZE (buf);
-
-  os << s;
-
-  retval = s.length ();
+  os.vform (fmt, args);
 
 #else
 
@@ -740,8 +728,6 @@
       os << s;
 
       retval = strlen (s);
-
-      free (s);
     }
 
 #endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]