octave-maintainers
[Top][All Lists]
Advanced

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

Patch [Re: ISO C++ and Octave]


From: Mumit Khan
Subject: Patch [Re: ISO C++ and Octave]
Date: Wed, 31 Jan 2001 22:27:03 -0600 (CST)

Here's the set of changes to make octave-2.1.33 work with both the old
and new GNU compilers -- using egcs-1.1.2 as the "old" and gcc-2.97
dev as the "new" one, on i686-pc-linux-gnu (RedHat 6.2 + all the
updates).  Octave built with egcs-1.1.2 shows no regressions. There 
are 15 failures with the development compiler, and I'm not surprised 
there aren't more. Listed at the end.

Generated files -- configure and config.h.in -- not included. Also
not included are the trivial changes to liboctave/*.{cc,h}, which
JWE may have fixed already.

Few changes worth mentioning:

1. Always compile with exceptions and rtti. RTTI is needed for the way
we extract the file descriptor from a stream, and I didn't want to use
the old code. Exceptions will be needed in all future versions of the
runtime (in theory you shouldn't, but various bugs pop up when you
try it, especially with the streams).

2. It's just too hard to maintain the explicit instantiations between
releases. Once libstdc++-v3 stabilizes, it's doable, but I would not
bother with it now. Only adds -fno-implicit templates for older
compilers. FYI, gcc-2.95.2+ potentially produces leaner code on ELF and
a few other systems if you let it instantiate the templates instead
of doing it explicitly. Has a lot to do with just what needs to be 
instantiated in each template.

3. The file descriptor for a filebuf is kept in c_file_ptr_buf now, and
portable between old and new library. Now that I've changed the order
of the base classes to avoid having to add -Wno-reorder ...

4. I've been able to tweak things so that we don't need macros to
distinguish old vs compliant library (CXX_ISO_COMPLIANT_LIBRARY), but
a few places remain: c_file_ptr_buf implementation is notable in that
respect. Also, I didn't feel like messing with chmod/umask etc to
work the 0664 issue in the old library (oct-fstrm.cc).

5. The change: 

  -  octave_base_scalar (ST s)
  +  octave_base_scalar (const ST& s)
       : octave_base_value (), scalar (s) { }
  
ov-scalar-base.{h,cc} is to work around a ICE in gcc-2.97. Ah, the
troubles with gcc and complex numbers. If it breaks on Linux, sure
to break with a much louder bang on Alphas.

6. I may have confused ::real vs std::real in a few places. Worth
a quick look.

7. I half-expected the math failures, but don't like the rest such as
sscanf and fopen one. Will double check.

exp(1+1i) fails for example. Haven't had a chance to look at the
reason yet. 

Native configuration is i686-pc-linux-gnu

                === octave tests ===

Schedule of variations:
    unix

FAIL: octave.test/arith/exp-2.m
FAIL: octave.test/arith/sqrt-1.m
FAIL: octave.test/arith/sqrt-2.m
FAIL: octave.test/arith/abs-1.m
FAIL: octave.test/arith/abs-2.m
FAIL: octave.test/arith/arg-1.m
FAIL: octave.test/arith/arg-2.m
FAIL: octave.test/arith/cosh-1.m
FAIL: octave.test/arith/tanh-1.m
FAIL: octave.test/arith/sech-1.m
FAIL: octave.test/arith/coth-1.m
FAIL: octave.test/arith/acoth-1.m
FAIL: octave.test/io/sscanf-1.m
FAIL: octave.test/io/fopen-1.m
FAIL: octave.test/string/hex2dec-1.m

                === octave Summary ===

# of expected passes            1237
# of unexpected failures        15
../src/octave version 2.1.33 (i686-pc-linux-gnu)

Oh, and just so you know -- gcc-2.97 is slow enough to make my 1 GHz
Linux box feel like one of those old SPARC 2's.

The aclocal.m4, part of configure.in and Makeconf.in changes may have
already been applied.

2001-01-31  Mumit Khan  <address@hidden>

        * aclocal.m4 (OCTAVE_CXX_ISO_COMPLIANT_LIBRARY): New macro.
        * configure.in: Use. 
        (XTRA_CXXFLAGS): Don't add -fno-rtti and -fno-exceptions.
        Conditionalize -fno-implicit-templates.
        * acconfig.h.in (CXX_ISO_COMPLIANT_LIBRARY): Add.
        * Makeconf.in: Strip directory portion from target when building
        dependencies.

Index: aclocal.m4
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/aclocal.m4,v
retrieving revision 1.1.1.2
diff -u -3 -p -r1.1.1.2 aclocal.m4
--- aclocal.m4  2001/01/30 04:41:41     1.1.1.2
+++ aclocal.m4  2001/01/31 16:53:10
@@ -931,3 +931,40 @@ EOF
     AC_DEFINE(CXX_PREPENDS_UNDERSCORE)
   fi
 ])
+dnl
+dnl See if the C++ library is ISO compliant.
+dnl FIXME: This is obviously very simplistic, and trivially fooled.
+dnl
+dnl OCTAVE_CXX_ISO_COMPLIANT_LIBRARY
+AC_DEFUN(OCTAVE_CXX_ISO_COMPLIANT_LIBRARY, [
+  AC_REQUIRE([AC_PROG_CXX])
+  AC_MSG_CHECKING([if C++ library is ISO compliant])
+  AC_CACHE_VAL(octave_cv_cxx_iso_compliant_library, [
+    AC_LANG_SAVE
+    AC_LANG_CPLUSPLUS
+    rm -f conftest.h
+    for inc in algorithm bitset cassert cctype cerrno cfloat ciso646 \
+       climits clocale cmath complex csetjmp csignal cstdarg cstddef \
+       cstdio cstdlib cstring ctime cwchar cwctype deque exception \
+       fstream functional iomanip ios iosfwd iostream istream iterator \
+       limits list locale map memory new numeric ostream queue set \
+       sstream stack stdexcept streambuf string strstream typeinfo \
+       utility valarray vector; do
+      echo "#include <$inc>" >> conftest.h
+    done
+    AC_TRY_LINK([#include "conftest.h"], [
+        std::bitset<50> flags;
+        flags.set();
+        int digits = std::numeric_limits<unsigned long>::digits;
+        digits = 0;
+      ],
+      octave_cv_cxx_iso_compliant_library=yes,
+      octave_cv_cxx_iso_compliant_library=no
+    )
+    AC_LANG_RESTORE
+  ])
+  AC_MSG_RESULT($octave_cv_cxx_iso_compliant_library)
+  if test $octave_cv_cxx_iso_compliant_library = yes; then
+    AC_DEFINE(CXX_ISO_COMPLIANT_LIBRARY)
+  fi
+])
Index: configure.in
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/configure.in,v
retrieving revision 1.1.1.2
diff -u -3 -p -r1.1.1.2 configure.in
--- configure.in        2001/01/30 04:41:41     1.1.1.2
+++ configure.in        2001/02/01 03:25:09
@@ -184,12 +184,21 @@ AC_PROG_CXXCPP
 gxx_version=`$CXX -v 2>&1 | grep "^.*g.. version" | \
   sed -e 's/^.*g.. version *//' -e 's/cygnus-//' -e 's/egcs-//'`
 
+cxx_auto_instantiate_templates=no
 case "$gxx_version" in
 changequote(,)dnl
   1.* | 2.[0123456].* | 2.7.[01]*)
 changequote([,])dnl
     AC_MSG_ERROR([g++ version $gxx_version will not work to compile Octave])
   ;;
+changequote(,)dnl
+  2.8* | 2.9[1-6]*)
+changequote([,])dnl
+    cxx_auto_instantiate_templates=no
+  ;;
+  *)
+    cxx_auto_instantiate_templates=yes
+  ;;
 esac
 
 CXX_VERSION=
@@ -199,6 +208,7 @@ fi
 AC_SUBST(CXX_VERSION)
 
 OCTAVE_CXX_NEW_FRIEND_TEMPLATE_DECL
+OCTAVE_CXX_ISO_COMPLIANT_LIBRARY
 
 ### See which C compiler to use (we expect to find gcc).
 
@@ -274,19 +284,21 @@ esac
 ### Octave doesn't use run-time type identification or exceptions yet,
 ### so disable them for somewhat faster and smaller code.
 
-OCTAVE_CXX_FLAG(-fno-rtti, [
-  XTRA_CXXFLAGS="$XTRA_CXXFLAGS -fno-rtti"
-  AC_MSG_RESULT([adding -fno-rtti to XTRA_CXXFLAGS])])
-
-OCTAVE_CXX_FLAG(-fno-exceptions, [
-  XTRA_CXXFLAGS="$XTRA_CXXFLAGS -fno-exceptions"
-  AC_MSG_RESULT([adding -fno-exceptions to XTRA_CXXFLAGS])])
+dnl OCTAVE_CXX_FLAG(-fno-rtti, [
+dnl   XTRA_CXXFLAGS="$XTRA_CXXFLAGS -fno-rtti"
+dnl   AC_MSG_RESULT([adding -fno-rtti to XTRA_CXXFLAGS])])
+dnl 
+dnl OCTAVE_CXX_FLAG(-fno-exceptions, [
+dnl   XTRA_CXXFLAGS="$XTRA_CXXFLAGS -fno-exceptions"
+dnl   AC_MSG_RESULT([adding -fno-exceptions to XTRA_CXXFLAGS])])
 
 ### We do our own template instantiation.
 
-OCTAVE_CXX_FLAG(-fno-implicit-templates, [
-  XTRA_CXXFLAGS="$XTRA_CXXFLAGS -fno-implicit-templates"
-  AC_MSG_RESULT([adding -fno-implicit-templates to XTRA_CXXFLAGS])])
+if test "$cxx_auto_instantiate_templates" = "no"; then
+  OCTAVE_CXX_FLAG(-fno-implicit-templates, [
+    XTRA_CXXFLAGS="$XTRA_CXXFLAGS -fno-implicit-templates"
+    AC_MSG_RESULT([adding -fno-implicit-templates to XTRA_CXXFLAGS])])
+fi
 
 AC_SUBST(XTRA_CFLAGS)
 AC_SUBST(XTRA_CXXFLAGS)
Index: acconfig.h
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/acconfig.h,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 acconfig.h
--- acconfig.h  2000/12/27 17:39:58     1.1.1.1
+++ acconfig.h  2001/01/31 20:16:49
@@ -14,6 +14,9 @@
    internal array and matrix classes. */
 #undef BOUNDS_CHECKING
 
+/* Define if your C++ runtime library is ISO compliant. */
+#undef CXX_ISO_COMPLIANT_LIBRARY
+
 /* Define if your compiler supports `<>' stuff for template friends. */
 #undef CXX_NEW_FRIEND_TEMPLATE_DECL
 
Index: Makeconf.in
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/Makeconf.in,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 Makeconf.in
--- Makeconf.in 2000/12/27 17:39:58     1.1.1.1
+++ Makeconf.in 2001/01/31 17:28:39
@@ -301,7 +301,8 @@ pic/%.o : %.cc
        @echo making $@ from $<
        @rm -f $@
        @$(CXX) -M $(CPPFLAGS) $(ALL_CXXFLAGS) $< | \
-         sed -e 's,$*\.o,pic/& & $@,g' > address@hidden
+         sed -e 's,^[^:]*/\(.*\.o\):,\1:,' \
+             -e 's,$*\.o,pic/& & $@,g' > address@hidden
        @mv address@hidden $@
 
 # And one for .c files.too:
@@ -310,7 +311,8 @@ pic/%.o : %.cc
        @echo making $@ from $<
        @rm -f $@
        @$(CC) -M $(CPPFLAGS) $(ALL_CFLAGS) $< | \
-         sed -e 's,$*\.o,pic/& & $@,g' > address@hidden
+         sed -e 's,^[^:]*/\(.*\.o\):,\1:,' \
+             -e 's,$*\.o,pic/& & $@,g' > address@hidden
        @mv address@hidden $@
 
 define do-subdir-for-command
Apologies for the the incomplete changelog, but I need to get some real
work done. Hopefully I'll a chance to submit a real one in the next
few days.

2001-01-31  Mumit Khan  <address@hidden>

        * c-file-ptr-stream.h: Add ISO C++ conformance.
        * c-file-ptr-stream.cc: Likewise.
        * error.cc: Likewise.
        * file-io.cc: Likewise.
        * help.cc: Likewise.
        * load-save.cc: Likewise.
        * oct-fstrm.cc: Likewise.
        * oct-fstrm.h: Likewise.
        * oct-iostrm.cc: Likewise.
        * oct-iostrm.h: Likewise.
        * oct-stdstrm.cc: Likewise.
        * oct-stdstrm.h: Likewise.
        * oct-stream.cc: Likewise.
        * oct-stream.h: Likewise.
        * oct-strstrm.cc: Likewise.
        * oct-strstrm.h: Likewise.
        * ov-base-scalar.h: Likewise.
        * ov-complex.cc: Likewise.
        * ov-cx-mat.cc: Likewise.
        * pager.cc: Likewise.
        * pr-output.cc: Likewise.
        * procstream.h: Likewise.
        * pt-pr-code.cc: Likewise.
        * utils.cc: Likewise.


Index: src/c-file-ptr-stream.h
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/c-file-ptr-stream.h,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 c-file-ptr-stream.h
--- src/c-file-ptr-stream.h     2000/12/27 17:40:00     1.1.1.1
+++ src/c-file-ptr-stream.h     2001/02/01 00:10:09
@@ -28,29 +28,38 @@ Software Foundation, 59 Temple Place - S
 #endif
 
 #include <iostream>
-#include <stdio.h>
+#include <fstream>
+#include <cstdio>
 
 class
 c_file_ptr_buf : public std::filebuf
 {
 public:
 
+#if !CXX_ISO_COMPLIANT_LIBRARY
+  typedef int int_type;
+#endif
+
   typedef int (*close_fcn) (FILE *);
 
   FILE* stdiofile (void) const { return f; }
 
   c_file_ptr_buf (FILE *f_arg, close_fcn cf_arg = ::fclose)
-    : std::filebuf (f_arg ? fileno (f_arg) : -1), f (f_arg), cf (cf_arg) { }
+    : std::filebuf (f_arg ? fileno (f_arg) : -1,
+                    0, std::ios::in | std::ios::out),
+    f (f_arg), cf (cf_arg),
+    fd (f_arg ? fileno (f_arg) : -1)
+    { }
 
   ~c_file_ptr_buf (void);
 
-  int overflow (int);
+  int_type overflow (int_type);
 
-  int underflow (void);
+  int_type underflow (void);
 
-  int uflow (void);
+  int_type uflow (void);
 
-  int pbackfail (int);
+  int_type pbackfail (int_type);
 
   std::streamsize xsputn (const char*, std::streamsize);
 
@@ -68,11 +77,17 @@ public:
 
   int close (void);
 
+  int file_number () const { return fd; }
+
 protected:
 
   FILE *f;
 
   close_fcn cf;
+
+private:
+
+  int fd;
 };
 
 class
@@ -81,7 +96,7 @@ i_c_file_ptr_stream : public std::istrea
 public:
 
   i_c_file_ptr_stream (FILE* f, c_file_ptr_buf::close_fcn cf = ::fclose)
-    : std::istream (), buf (new c_file_ptr_buf (f, cf)) { init (buf); }
+    : std::istream (0), buf (new c_file_ptr_buf (f, cf)) { init (buf); }
 
   ~i_c_file_ptr_stream (void) { delete buf; buf = 0; }
 
@@ -100,7 +115,7 @@ o_c_file_ptr_stream : public std::ostrea
 public:
 
   o_c_file_ptr_stream (FILE* f, c_file_ptr_buf::close_fcn cf = ::fclose)
-    : std::ostream (), buf (new c_file_ptr_buf (f, cf)) { init (buf); }
+    : std::ostream (0), buf (new c_file_ptr_buf (f, cf)) { init (buf); }
 
   ~o_c_file_ptr_stream (void) { delete buf; buf = 0; }
 
Index: src/c-file-ptr-stream.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/c-file-ptr-stream.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 c-file-ptr-stream.cc
--- src/c-file-ptr-stream.cc    2000/12/27 17:40:00     1.1.1.1
+++ src/c-file-ptr-stream.cc    2001/01/31 19:03:40
@@ -49,34 +49,50 @@ c_file_ptr_buf::~c_file_ptr_buf (void)
 
 // XXX FIXME XXX -- I'm sure there is room for improvement here...
 
-int
-c_file_ptr_buf::overflow (int c)
+c_file_ptr_buf::int_type
+c_file_ptr_buf::overflow (int_type c)
 {
+#if CXX_ISO_COMPLIANT_LIBRARY
   if (f)
+    return (c != traits_type::eof ()) ? fputc (c, f) : flush ();
+  else
+    return traits_type::not_eof (c);
+#else /* CXX_ISO_COMPLIANT_LIBRARY */
+  if (f)
     return (c != EOF) ? fputc (c, f) : flush ();
   else
     return EOF;
+#endif /* CXX_ISO_COMPLIANT_LIBRARY */
 }
 
-int
+c_file_ptr_buf::int_type
 c_file_ptr_buf::underflow (void)
 {
   if (f)
     return fgetc (f);
   else
+#if CXX_ISO_COMPLIANT_LIBRARY
+    return traits_type::eof ();
+#else /* CXX_ISO_COMPLIANT_LIBRARY */
     return EOF;
+#endif /* CXX_ISO_COMPLIANT_LIBRARY */
 }
 
-int
+c_file_ptr_buf::int_type
 c_file_ptr_buf::uflow (void)
 {
   return underflow ();
 }
 
-int
-c_file_ptr_buf::pbackfail (int c)
+c_file_ptr_buf::int_type
+c_file_ptr_buf::pbackfail (int_type c)
 {
+#if CXX_ISO_COMPLIANT_LIBRARY
+  return (c != traits_type::eof () && f) ? ungetc (c, f) : 
+    traits_type::not_eof (c);
+#else /* CXX_ISO_COMPLIANT_LIBRARY */
   return (c != EOF && f) ? ungetc (c, f) : EOF;
+#endif /* CXX_ISO_COMPLIANT_LIBRARY */
 }
 
 std::streamsize
Index: src/error.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/error.cc,v
retrieving revision 1.1.1.2
diff -u -3 -p -r1.1.1.2 error.cc
--- src/error.cc        2001/01/30 04:41:48     1.1.1.2
+++ src/error.cc        2001/01/30 18:08:58
@@ -284,7 +284,7 @@ pr_where (const char *name)
 
       curr_statement->accept (tpc);
 
-      output_buf << "\n" << ends;
+      output_buf << "\n" << std::ends;
 
       char *msg = output_buf.str ();
 
Index: src/file-io.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/file-io.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 file-io.cc
--- src/file-io.cc      2000/12/27 17:40:00     1.1.1.1
+++ src/file-io.cc      2001/01/31 04:56:13
@@ -318,7 +318,9 @@ do_stream_open (const std::string& name,
        oct_mach_info::string_to_float_format (arch);
 
       if (! error_state)
-       retval = octave_fstream::create (name, md, flt_fmt);
+       retval = octave_fstream::create (name,
+                                        static_cast<std::ios::openmode> (md), 
+                                        flt_fmt);
     }
 
   return retval;
Index: src/help.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/help.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 help.cc
--- src/help.cc 2000/12/27 17:40:00     1.1.1.1
+++ src/help.cc 2001/01/30 18:10:40
@@ -639,7 +639,7 @@ display_help_text (std::ostream& os, con
                 << "See also: \\args\\.\n"
                  << "@end macro\n";
 
-         filter << msg.substr (pos+1) << endl;
+         filter << msg.substr (pos+1) << std::endl;
 
          int status = filter.close ();
 
Index: src/load-save.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/load-save.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 load-save.cc
--- src/load-save.cc    2000/12/27 17:40:00     1.1.1.1
+++ src/load-save.cc    2001/01/31 16:06:01
@@ -2772,7 +2772,7 @@ read_mat5_binary_file_header (std::istre
 // Return TRUE if NAME matches one of the given globbing PATTERNS.
 
 static bool
-matches_patterns (const std::string_vector& patterns, int pat_idx,
+matches_patterns (const string_vector& patterns, int pat_idx,
                  int num_pat, const std::string& name)
 {
   for (int i = pat_idx; i < num_pat; i++)
@@ -3287,7 +3287,7 @@ lists of lists of matrices, or ...).\n\
        {
          i++;
 
-         unsigned mode = std::ios::in;
+         std::ios::openmode mode = std::ios::in;
          if (format == LS_BINARY ||
              format == LS_MAT_BINARY ||
              format == LS_MAT5_BINARY)
@@ -4081,7 +4081,7 @@ save_mat5_binary_element (std::ostream& 
   FOUR_BYTE_INT junk=0;
   FOUR_BYTE_INT nr;
   FOUR_BYTE_INT nc;
-  streampos fixup, contin;
+  std::streampos fixup, contin;
 
   // element type and length
   fixup = os.tellp ();
@@ -4231,7 +4231,7 @@ save_mat5_binary_element (std::ostream& 
        for (i = m.first (); i; m.next (i))
          {
            // write the name of each element
-           string tstr = m.key (i);
+           std::string tstr = m.key (i);
            memset (buf, 0, 32);
            strncpy (buf, tstr.c_str (), 31); // only 31 char names permitted
            os.write (buf, 32);
@@ -4810,7 +4810,7 @@ write_header (std::ostream& os, load_sav
 }
 
 static void
-save_vars (const std::string_vector& argv, int argv_idx, int argc,
+save_vars (const string_vector& argv, int argv_idx, int argc,
           std::ostream& os, bool save_builtins, load_save_format fmt,
           bool save_as_floats, bool write_header_info)
 {
@@ -4846,7 +4846,7 @@ save_user_variables (void)
 
       load_save_format format = get_default_save_format ();
 
-      unsigned mode = std::ios::out|std::ios::trunc;
+      std::ios::openmode mode = std::ios::out|std::ios::trunc;
       if (format == LS_BINARY ||
          format == LS_MAT_BINARY ||
          format == LS_MAT5_BINARY)
@@ -5088,7 +5088,7 @@ the file @file{data} in Octave's binary 
 
       i++;
 
-      unsigned mode = std::ios::out;
+      std::ios::openmode mode = std::ios::out;
       if (format == LS_BINARY ||
          format == LS_MAT_BINARY ||
          format == LS_MAT5_BINARY)
@@ -5123,7 +5123,8 @@ the file @file{data} in Octave's binary 
          if (file)
            {
              bool write_header_info
-               = ( (file.rdbuf ())->seekoff (0, std::ios::cur) == 0);
+               = ( (file.rdbuf ())->pubseekoff (0, std::ios::cur) 
+                  == static_cast<std::streampos> (0));
              
              save_vars (argv, i, argc, file, save_builtins, format,
                         save_as_floats, write_header_info);
@@ -5226,7 +5227,7 @@ default_save_format (void)
   return status;
 }
 
-static string
+static std::string
 default_save_header_format (void)
 {
   return
Index: src/oct-fstrm.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/oct-fstrm.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 oct-fstrm.cc
--- src/oct-fstrm.cc    2000/12/27 17:40:00     1.1.1.1
+++ src/oct-fstrm.cc    2001/02/01 03:17:53
@@ -42,11 +42,19 @@ octave_fstream::octave_fstream (const st
                                oct_mach_info::float_format flt_fmt)
   : octave_base_stream (arg_md, flt_fmt), nm (nm_arg)
 {
+
+#if CXX_ISO_COMPLIANT_LIBRARY
+
+  fs.open (nm.c_str (), arg_md);
+
+#else
   // Override default protection of 0664 so that umask will appear to
   // do the right thing.
 
   fs.open (nm.c_str (), arg_md, 0666);
 
+#endif
+
   if (! fs)
     {
       using namespace std;
@@ -58,7 +66,7 @@ octave_fstream::octave_fstream (const st
 // Position a stream at OFFSET relative to ORIGIN.
 
 int
-octave_fstream::seek (std::streamoff offset, std::ios::seek_dir origin)
+octave_fstream::seek (std::streamoff offset, std::ios::seekdir origin)
 {
   int retval = -1;
 
Index: src/oct-fstrm.h
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/oct-fstrm.h,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 oct-fstrm.h
--- src/oct-fstrm.h     2000/12/27 17:40:00     1.1.1.1
+++ src/oct-fstrm.h     2001/01/31 04:52:20
@@ -24,6 +24,7 @@ Software Foundation, 59 Temple Place - S
 #define octave_octave_fstream_h 1
 
 #include <fstream>
+#include <string>
 
 #include "oct-stream.h"
 
@@ -44,7 +45,7 @@ public:
 
   // Position a stream at OFFSET relative to ORIGIN.
 
-  int seek (std::streamoff offset, std::ios::seek_dir origin);
+  int seek (std::streamoff offset, std::ios::seekdir origin);
 
   // Return current stream position.
 
Index: src/oct-iostrm.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/oct-iostrm.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 oct-iostrm.cc
--- src/oct-iostrm.cc   2000/12/27 17:40:00     1.1.1.1
+++ src/oct-iostrm.cc   2001/01/31 15:28:02
@@ -30,7 +30,7 @@ Software Foundation, 59 Temple Place - S
 // Position a stream at OFFSET relative to ORIGIN.
 
 int
-octave_base_iostream::seek (std::streamoff, std::ios::seek_dir)
+octave_base_iostream::seek (std::streamoff, std::ios::seekdir)
 {
   invalid_operation ();
   return -1;
Index: src/oct-iostrm.h
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/oct-iostrm.h,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 oct-iostrm.h
--- src/oct-iostrm.h    2000/12/27 17:40:00     1.1.1.1
+++ src/oct-iostrm.h    2001/01/31 04:52:58
@@ -40,7 +40,7 @@ public:
 
   // Position a stream at OFFSET relative to ORIGIN.
 
-  int seek (std::streamoff offset, std::ios::seek_dir origin);
+  int seek (std::streamoff offset, std::ios::seekdir origin);
 
   // Return current stream position.
 
Index: src/oct-stdstrm.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/oct-stdstrm.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 oct-stdstrm.cc
--- src/oct-stdstrm.cc  2000/12/27 17:40:00     1.1.1.1
+++ src/oct-stdstrm.cc  2001/01/31 15:28:18
@@ -31,7 +31,7 @@ Software Foundation, 59 Temple Place - S
 // Position a stream at OFFSET relative to ORIGIN.
 
 int
-octave_base_stdiostream::seek (std::streamoff offset, std::ios::seek_dir 
origin)
+octave_base_stdiostream::seek (std::streamoff offset, std::ios::seekdir origin)
 {
   int retval = -1;
 
Index: src/oct-stdstrm.h
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/oct-stdstrm.h,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 oct-stdstrm.h
--- src/oct-stdstrm.h   2000/12/27 17:40:00     1.1.1.1
+++ src/oct-stdstrm.h   2001/01/31 04:53:37
@@ -39,7 +39,7 @@ public:
 
   // Position a stream at OFFSET relative to ORIGIN.
 
-  int seek (std::streamoff offset, std::ios::seek_dir origin);
+  int seek (std::streamoff offset, std::ios::seekdir origin);
 
   // Return current stream position.
 
Index: src/oct-stream.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/oct-stream.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 oct-stream.cc
--- src/oct-stream.cc   2000/12/27 17:40:00     1.1.1.1
+++ src/oct-stream.cc   2001/02/01 03:15:23
@@ -39,6 +39,7 @@ Software Foundation, 59 Temple Place - S
 
 #include "error.h"
 #include "input.h"
+#include "oct-stdstrm.h"
 #include "oct-stream.h"
 #include "oct-obj.h"
 #include "utils.h"
@@ -894,10 +895,18 @@ octave_base_stream::file_number (void)
   std::istream *is = input_stream ();
   std::ostream *os = output_stream ();
 
-  // XXX FIXME XXX -- there must be a better way...
-  int i_fid = is ? ((std::filebuf *) (is->rdbuf ()))->fd () : -1;
-  int o_fid = os ? ((std::filebuf *) (os->rdbuf ()))->fd () : -1;
+  // There is no standard way to get the underlying file descriptor from 
+  // std::filebuf (nor in the GNU libstdc++-v3 implementation). We cache
+  // the descriptor in c_file_ptr_buf, and then extract it here.
+
+  c_file_ptr_buf *ibuf = is ?
+    dynamic_cast<c_file_ptr_buf *> (is->rdbuf ()) : 0;
+  c_file_ptr_buf *obuf = os ?
+    dynamic_cast<c_file_ptr_buf *> (os->rdbuf ()) : 0;
 
+  int i_fid = ibuf ? ibuf->file_number () : -1;
+  int o_fid = obuf ? obuf->file_number () : -1;
+
   if (i_fid >= 0)
     {
       if (o_fid >= 0)
@@ -1055,7 +1064,7 @@ octave_base_stream::read (const Matrix& 
   return retval;
 }
 
-#if defined (__GNUG__)
+#if defined (__GNUG__) && !CXX_ISO_COMPLIANT_LIBRARY
 
 #define OCTAVE_SCAN(is, fmt, arg) is.scan ((fmt).text, arg)
 
@@ -2513,7 +2522,7 @@ octave_stream::gets (const octave_value&
 }
 
 int
-octave_stream::seek (std::streamoff offset, std::ios::seek_dir origin)
+octave_stream::seek (std::streamoff offset, std::ios::seekdir origin)
 {
   int retval = -1;
 
@@ -2535,7 +2544,7 @@ octave_stream::seek (const octave_value&
 
   if (! conv_err)
     {
-      std::ios::seek_dir origin = std::ios::beg;
+      std::ios::seekdir origin = std::ios::beg;
 
       if (tc_origin.is_string ())
        {
@@ -2765,62 +2774,36 @@ std::string
 octave_stream::mode_as_string (int mode)
 {
   std::string retval = "???";
-
-  switch (mode)
-    {
-    case std::ios::in:
-      retval = "r";
-      break;
-
-    case std::ios::out:
-    case std::ios::out | std::ios::trunc:
-      retval = "w";
-      break;
-
-    case std::ios::out | std::ios::app:
-      retval = "a";
-      break;
+  std::ios::openmode in_mode = static_cast<std::ios::openmode> (mode);
 
-    case std::ios::in | std::ios::out:
-      retval = "r+";
-      break;
-
-    case std::ios::in | std::ios::out | std::ios::trunc:
-      retval = "w+";
-      break;
-
-    case std::ios::in | std::ios::out | std::ios::app:
-      retval = "a+";
-      break;
-
-    case std::ios::in | std::ios::binary:
-      retval = "rb";
-      break;
-
-    case std::ios::out | std::ios::binary:
-    case std::ios::out | std::ios::trunc | std::ios::binary:
-      retval = "wb";
-      break;
-
-    case std::ios::out | std::ios::app | std::ios::binary:
-      retval = "ab";
-      break;
-
-    case std::ios::in | std::ios::out | std::ios::binary:
-      retval = "r+b";
-      break;
-
-    case std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary:
-      retval = "w+b";
-      break;
-
-    case std::ios::in | std::ios::out | std::ios::app | std::ios::binary:
-      retval = "a+b";
-      break;
-
-    default:
-      break;
-    }
+  if (in_mode == std::ios::in)
+    retval = "r";
+  else if (in_mode == std::ios::out 
+           || in_mode == std::ios::out | std::ios::trunc)
+    retval = "w";
+  else if (in_mode == std::ios::out | std::ios::app)
+    retval = "a";
+  else if (in_mode == std::ios::in | std::ios::out)
+    retval = "r+";
+  else if (in_mode == std::ios::in | std::ios::out | std::ios::trunc)
+    retval = "w+";
+  else if (in_mode == std::ios::in | std::ios::out | std::ios::app)
+    retval = "a+";
+  else if (in_mode == std::ios::in | std::ios::binary)
+    retval = "rb";
+  else if (in_mode == std::ios::out | std::ios::binary
+           || in_mode == std::ios::out | std::ios::trunc | std::ios::binary)
+    retval = "wb";
+  else if (in_mode == std::ios::out | std::ios::app | std::ios::binary)
+    retval = "ab";
+  else if (in_mode == std::ios::in | std::ios::out | std::ios::binary)
+    retval = "r+b";
+  else if (in_mode == std::ios::in | std::ios::out | std::ios::trunc 
+           | std::ios::binary)
+    retval = "w+b";
+  else if (in_mode == std::ios::in | std::ios::out | std::ios::app
+           | std::ios::binary)
+    retval = "a+b";
 
   return retval;
 }
Index: src/oct-stream.h
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/oct-stream.h,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 oct-stream.h
--- src/oct-stream.h    2000/12/27 17:40:00     1.1.1.1
+++ src/oct-stream.h    2001/01/31 01:55:03
@@ -334,7 +334,7 @@ public:
 
   // Position a stream at OFFSET relative to ORIGIN.
 
-  virtual int seek (std::streamoff offset, std::ios::seek_dir origin) = 0;
+  virtual int seek (std::streamoff offset, std::ios::seekdir origin) = 0;
 
   // Return current stream position.
 
@@ -502,7 +502,7 @@ public:
   std::string gets (int max_len, bool& err);
   std::string gets (const octave_value& max_len, bool& err);
 
-  int seek (std::streamoff offset, std::ios::seek_dir origin);
+  int seek (std::streamoff offset, std::ios::seekdir origin);
   int seek (const octave_value& offset, const octave_value& origin);
 
   long tell (void) const;
Index: src/oct-strstrm.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/oct-strstrm.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 oct-strstrm.cc
--- src/oct-strstrm.cc  2000/12/27 17:40:00     1.1.1.1
+++ src/oct-strstrm.cc  2001/01/31 15:28:09
@@ -29,7 +29,7 @@ Software Foundation, 59 Temple Place - S
 // Position a stream at OFFSET relative to ORIGIN.
 
 int
-octave_base_strstream::seek (std::streamoff offset, std::ios::seek_dir origin)
+octave_base_strstream::seek (std::streamoff offset, std::ios::seekdir origin)
 {
   int retval = -1;
 
Index: src/oct-strstrm.h
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/oct-strstrm.h,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 oct-strstrm.h
--- src/oct-strstrm.h   2000/12/27 17:40:00     1.1.1.1
+++ src/oct-strstrm.h   2001/01/31 04:53:41
@@ -40,7 +40,7 @@ public:
 
   // Position a stream at OFFSET relative to ORIGIN.
 
-  int seek (std::streamoff offset, std::ios::seek_dir origin);
+  int seek (std::streamoff offset, std::ios::seekdir origin);
 
   // Return current stream position.
 
Index: src/ov-base-scalar.h
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/ov-base-scalar.h,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 ov-base-scalar.h
--- src/ov-base-scalar.h        2000/12/27 17:40:00     1.1.1.1
+++ src/ov-base-scalar.h        2001/01/31 16:32:43
@@ -51,7 +51,7 @@ public:
   octave_base_scalar (void)
     : octave_base_value () { }
 
-  octave_base_scalar (ST s)
+  octave_base_scalar (const ST& s)
     : octave_base_value (), scalar (s) { }
 
   octave_base_scalar (const octave_base_scalar& s)
Index: src/ov-complex.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/ov-complex.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 ov-complex.cc
--- src/ov-complex.cc   2000/12/27 17:40:00     1.1.1.1
+++ src/ov-complex.cc   2001/01/31 16:54:29
@@ -55,7 +55,7 @@ octave_complex::try_narrowing_conversion
   octave_value *retval = 0;
 
   if (imag (scalar) == 0.0)
-    retval = new octave_scalar (::real (scalar));
+    retval = new octave_scalar (real (scalar));
 
   return retval;
 }
@@ -113,7 +113,7 @@ octave_complex::double_value (bool force
     gripe_implicit_conversion ("complex scalar", "real scalar");
 
   if (flag)
-    retval = ::real (scalar);
+    retval = std::real (scalar);
   else
     gripe_invalid_conversion ("complex scalar", "real scalar");
 
@@ -134,7 +134,7 @@ octave_complex::matrix_value (bool force
     gripe_implicit_conversion ("complex scalar", "real matrix");
 
   if (flag)
-    retval = Matrix (1, 1, ::real (scalar));
+    retval = Matrix (1, 1, std::real (scalar));
   else
     gripe_invalid_conversion ("complex scalar", "real matrix");
 
Index: src/ov-cx-mat.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/ov-cx-mat.cc,v
retrieving revision 1.1.1.2
diff -u -3 -p -r1.1.1.2 ov-cx-mat.cc
--- src/ov-cx-mat.cc    2001/01/30 04:41:48     1.1.1.2
+++ src/ov-cx-mat.cc    2001/01/31 15:46:54
@@ -64,7 +64,7 @@ octave_complex_matrix::try_narrowing_con
       Complex c = matrix (0, 0);
 
       if (imag (c) == 0.0)
-       retval = new octave_scalar (::real (c));
+       retval = new octave_scalar (std::real (c));
       else
        retval = new octave_complex (c);
     }
@@ -182,7 +182,7 @@ octave_complex_matrix::double_value (boo
     {
       if ((rows () == 1 && columns () == 1)
          || (Vdo_fortran_indexing && rows () > 0 && columns () > 0))
-       retval = ::real (matrix (0, 0));
+       retval = std::real (matrix (0, 0));
       else
        gripe_invalid_conversion ("complex matrix", "real scalar");
     }
Index: src/pager.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/pager.cc,v
retrieving revision 1.1.1.2
diff -u -3 -p -r1.1.1.2 pager.cc
--- src/pager.cc        2001/01/30 04:41:48     1.1.1.2
+++ src/pager.cc        2001/01/31 15:42:08
@@ -284,7 +284,7 @@ octave_diary_buf::sync (void)
 
 octave_pager_stream *octave_pager_stream::instance = 0;
 
-octave_pager_stream::octave_pager_stream (void) : std::ostream (), pb (0)
+octave_pager_stream::octave_pager_stream (void) : std::ostream (0), pb (0)
 {
   pb = new octave_pager_buf;
   rdbuf (pb);
@@ -322,7 +322,7 @@ octave_pager_stream::set_diary_skip (voi
 
 octave_diary_stream *octave_diary_stream::instance = 0;
 
-octave_diary_stream::octave_diary_stream (void) : std::ostream (), db (0)
+octave_diary_stream::octave_diary_stream (void) : std::ostream (0), db (0)
 {
   db = new octave_diary_buf;
   rdbuf (db);
Index: src/pr-output.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/pr-output.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 pr-output.cc
--- src/pr-output.cc    2000/12/27 17:40:00     1.1.1.1
+++ src/pr-output.cc    2001/01/31 15:35:21
@@ -184,7 +184,9 @@ operator << (std::ostream& os, const pr_
   if (pff.f.prec >= 0)
     os << std::setprecision (pff.f.prec);
 
-  std::ios::fmtflags oflags = os.flags (pff.f.fmt | pff.f.up | pff.f.sp);
+  std::ios::fmtflags oflags = 
+    os.flags (static_cast<std::ios::fmtflags> 
+              (pff.f.fmt | pff.f.up | pff.f.sp));
 
   os << pff.val;
 
@@ -1828,7 +1830,7 @@ returns the formatted output in a string
 
       if (! error_state)
        {
-         ostream *osp = os.output_stream ();
+         std::ostream *osp = os.output_stream ();
 
          if (osp)
            args(1).print (*osp);
Index: src/procstream.h
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/procstream.h,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 procstream.h
--- src/procstream.h    2000/12/27 17:40:00     1.1.1.1
+++ src/procstream.h    2001/01/31 19:57:43
@@ -66,14 +66,15 @@ private:
 };
 
 class
-iprocstream : public procstreambase, public std::istream
+iprocstream : public std::istream, public procstreambase
+// iprocstream : public procstreambase, public std::istream
 {
 public:
 
-  iprocstream (void) : procstreambase () { }
+  iprocstream (void) : std::istream (0), procstreambase () { }
 
   iprocstream (const char *name, int mode = std::ios::in)
-    : procstreambase (name, mode) { }
+    : std::istream (0), procstreambase (name, mode) { }
 
   ~iprocstream (void) { }
 
@@ -88,14 +89,15 @@ private:
 };
 
 class
-oprocstream : public procstreambase, public std::ostream
+oprocstream : public std::ostream, public procstreambase
+// oprocstream : public procstreambase, public std::ostream
 {
 public:
  
-  oprocstream (void) : procstreambase () { }
+  oprocstream (void) : std::ostream (0), procstreambase () { }
 
   oprocstream (const char *name, int mode = std::ios::out)
-    : procstreambase(name, mode) { }
+    : std::ostream (0), procstreambase(name, mode) { }
 
   ~oprocstream (void) { }
 
@@ -110,14 +112,15 @@ private:
 };
 
 class
-procstream : public procstreambase, public std::iostream
+procstream : public std::iostream, public procstreambase
+// procstream : public procstreambase, public std::iostream
 {
 public:
 
-  procstream (void) : procstreambase () { }
+  procstream (void) : std::iostream (0), procstreambase () { }
 
   procstream (const char *name, int mode)
-    : procstreambase (name, mode) { }
+    : std::iostream (0), procstreambase (name, mode) { }
 
   ~procstream (void) { }
 
Index: src/pt-pr-code.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/pt-pr-code.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 pt-pr-code.cc
--- src/pt-pr-code.cc   2000/12/27 17:40:00     1.1.1.1
+++ src/pt-pr-code.cc   2001/01/31 15:36:07
@@ -1274,7 +1274,7 @@ tree_print_code::print_comment_elt (cons
 
   bool prev_char_was_newline = false;
 
-  string comment = elt.text ();
+  std::string comment = elt.text ();
 
   size_t len = comment.length ();
 
Index: src/utils.cc
===================================================================
RCS file: /homes/khan/src/math/CVSROOT/octave-test/src/utils.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 utils.cc
--- src/utils.cc        2000/12/27 17:40:00     1.1.1.1
+++ src/utils.cc        2001/01/31 19:27:56
@@ -718,13 +718,13 @@ octave_vformat (std::ostream& os, const 
 {
   int retval = -1;
 
-#if defined (__GNUG__)
+#if defined (__GNUG__) && !CXX_ISO_COMPLIANT_LIBRARY
 
-  ostrstream buf;
+  std::ostrstream buf;
 
   buf.vform (fmt, args);
 
-  buf << ends;
+  buf << std::ends;
 
   char *s = buf.str ();
 

reply via email to

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