# HG changeset patch # User jwe # Date 886668307 0 # Node ID 0d640dc625c77f89dc7fe032314dbc0fb9332731 # Parent fb9924282a3e87d0aa63527af78b43fe4b20b601 [project @ 1998-02-05 08:44:59 by jwe] diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,28 @@ +Thu Feb 5 02:12:38 1998 John W. Eaton + + * dir-ops.h (dir_entry::operator bool ()): Return bool, not void*. + * file-stat.h (file_stat::operator bool ()): Likewise. + * idx-vector.h (idx_vector::operator bool ()): Likewise. + * oct-group.h (octave_group::operator bool ()): Likewise. + * oct-passwd.h (octave_passwd::operator bool ()): Likewise. + + * data-conv.cc (IEEE_little_double_to_IEEE_big_double): + Don't cast arg in call to swap_8_bytes. + (IEEE_big_double_to_IEEE_little_double): Ditto + (IEEE_big_float_to_IEEE_little_float): Don't cast arg in call to + swap_4_bytes. + (IEEE_little_float_to_IEEE_big_float): Ditto + + * oct-alloc.cc (grow): Use X_CAST, not static_cast. + * prog-args.cc (prog_args::getopt): Likewise. + * dMatrix.cc (read_int, do_read, write_int, do_write): Likewise. + * cmd-edit.cc (gnu_readline::do_set_completion_function): Likewise. + * data-conv.cc (LS_DO_READ, LS_DO_WRITE, read_doubles, write_doubles): + Likewise. + + * byte-swap.h (swap_bytes, swap_2_bytes, swap_4_bytes, + swap_8_bytes): Declare ptr arg as void*, then use cast. + Mon Feb 2 01:42:56 1998 John W. Eaton * Makefile.in (install, uninstall): Use $(octlibdir), not $(libdir). diff --git a/liboctave/byte-swap.h b/liboctave/byte-swap.h --- a/liboctave/byte-swap.h +++ b/liboctave/byte-swap.h @@ -24,29 +24,37 @@ #define octave_byte_swap_h 1 static inline void -swap_bytes (char *t, unsigned int i, unsigned int j) +swap_bytes (void *ptr, unsigned int i, unsigned int j) { + char *t = static_cast (ptr); + char tmp = t[i]; t[i] = t[j]; t[j] = tmp; } static inline void -swap_2_bytes (char *t) +swap_2_bytes (void *ptr) { + char *t = static_cast (ptr); + swap_bytes (t, 0, 1); } static inline void -swap_4_bytes (char *t) +swap_4_bytes (void *ptr) { + char *t = static_cast (ptr); + swap_bytes (t, 0, 3); swap_bytes (t, 1, 2); } static inline void -swap_8_bytes (char *t) +swap_8_bytes (void *ptr) { + char *t = static_cast (ptr); + swap_bytes (t, 0, 7); swap_bytes (t, 1, 6); swap_bytes (t, 2, 5); @@ -54,35 +62,38 @@ } static inline void -swap_2_bytes (char *t, int len) +swap_2_bytes (void *ptr, int len) { - char *ptr = t; + char *t = static_cast (ptr); + for (int i = 0; i < len; i++) { - swap_2_bytes (ptr); - ptr += 2; + swap_2_bytes (t); + t += 2; } } static inline void -swap_4_bytes (char *t, int len) +swap_4_bytes (void *ptr, int len) { - char *ptr = t; + char *t = static_cast (ptr); + for (int i = 0; i < len; i++) { - swap_4_bytes (ptr); - ptr += 4; + swap_4_bytes (t); + t += 4; } } static inline void -swap_8_bytes (char *t, int len) +swap_8_bytes (void *ptr, int len) { - char *ptr = t; + char *t = static_cast (ptr); + for (int i = 0; i < len; i++) { - swap_8_bytes (ptr); - ptr += 8; + swap_8_bytes (t); + t += 8; } } diff --git a/liboctave/cmd-edit.cc b/liboctave/cmd-edit.cc --- a/liboctave/cmd-edit.cc +++ b/liboctave/cmd-edit.cc @@ -277,7 +277,7 @@ rl_attempted_completion_function = completion_function - ? static_cast (gnu_readline::command_completer) : 0; + ? reinterpret_cast (gnu_readline::command_completer) : 0; } gnu_readline::completion_fcn diff --git a/liboctave/dMatrix.cc b/liboctave/dMatrix.cc --- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -2377,7 +2377,7 @@ static void read_int (istream& is, bool swap_bytes, T& val) { - is.read (static_cast (&val), sizeof (T)); + is.read (X_CAST (char *, &val), sizeof (T)); if (swap_bytes) { @@ -2387,15 +2387,15 @@ break; case 2: - swap_2_bytes (static_cast (&val)); + swap_2_bytes (X_CAST (char *, &val)); break; case 4: - swap_4_bytes (static_cast (&val)); + swap_4_bytes (X_CAST (char *, &val)); break; case 8: - swap_8_bytes (static_cast (&val)); + swap_8_bytes (X_CAST (char *, &val)); break; default: @@ -2500,7 +2500,7 @@ { float f; - is.read (static_cast (&f), sizeof (float)); + is.read (X_CAST (char *, &f), sizeof (float)); if (do_float_conversion) do_float_format_conversion (&f, 1, flt_fmt); @@ -2511,7 +2511,7 @@ case oct_data_conv::dt_double: { - is.read (static_cast (&val), sizeof (double)); + is.read (X_CAST (char *, &val), sizeof (double)); if (do_float_conversion) do_double_format_conversion (&val, 1, flt_fmt); @@ -2691,15 +2691,15 @@ break; case 2: - swap_2_bytes (static_cast (&val)); + swap_2_bytes (X_CAST (char *, &val)); break; case 4: - swap_4_bytes (static_cast (&val)); + swap_4_bytes (X_CAST (char *, &val)); break; case 8: - swap_8_bytes (static_cast (&val)); + swap_8_bytes (X_CAST (char *, &val)); break; default: @@ -2708,7 +2708,7 @@ } } - os.write (static_cast (&val), sizeof (T)); + os.write (X_CAST (char *, &val), sizeof (T)); } template void write_int (ostream&, bool, char); @@ -2731,39 +2731,39 @@ switch (dt) { case oct_data_conv::dt_char: - write_int (os, swap_bytes, static_cast (d)); + write_int (os, swap_bytes, X_CAST (char, d)); break; case oct_data_conv::dt_schar: - write_int (os, swap_bytes, static_cast (d)); + write_int (os, swap_bytes, X_CAST (signed char, d)); break; case oct_data_conv::dt_uchar: - write_int (os, swap_bytes, static_cast (d)); + write_int (os, swap_bytes, X_CAST (unsigned char, d)); break; case oct_data_conv::dt_short: - write_int (os, swap_bytes, static_cast (d)); + write_int (os, swap_bytes, X_CAST (short, d)); break; case oct_data_conv::dt_ushort: - write_int (os, swap_bytes, static_cast (d)); + write_int (os, swap_bytes, X_CAST (unsigned short, d)); break; case oct_data_conv::dt_int: - write_int (os, swap_bytes, static_cast (d)); + write_int (os, swap_bytes, X_CAST (int, d)); break; case oct_data_conv::dt_uint: - write_int (os, swap_bytes, static_cast (d)); + write_int (os, swap_bytes, X_CAST (unsigned int, d)); break; case oct_data_conv::dt_long: - write_int (os, swap_bytes, static_cast (d)); + write_int (os, swap_bytes, X_CAST (long, d)); break; case oct_data_conv::dt_ulong: - write_int (os, swap_bytes, static_cast (d)); + write_int (os, swap_bytes, X_CAST (unsigned long, d)); break; case oct_data_conv::dt_float: @@ -2773,7 +2773,7 @@ if (do_float_conversion) do_float_format_conversion (&f, 1, flt_fmt); - os.write (static_cast (&f), sizeof (float)); + os.write (X_CAST (char *, &f), sizeof (float)); } break; @@ -2782,7 +2782,7 @@ if (do_float_conversion) do_double_format_conversion (&d, 1, flt_fmt); - os.write (static_cast (&d), sizeof (double)); + os.write (X_CAST (char *, &d), sizeof (double)); } break; diff --git a/liboctave/data-conv.cc b/liboctave/data-conv.cc --- a/liboctave/data-conv.cc +++ b/liboctave/data-conv.cc @@ -106,10 +106,10 @@ #define LS_DO_READ(TYPE,swap,data,size,len,stream) \ do \ { \ - volatile TYPE *ptr = (TYPE *) data; \ - stream.read ((TYPE *) ptr, size * len); \ + volatile TYPE *ptr = X_CAST (volatile TYPE *, data); \ + stream.read (X_CAST (TYPE *, ptr), size * len); \ if (swap) \ - swap_ ## size ## _bytes (static_cast (ptr), len); \ + swap_ ## size ## _bytes (ptr, len); \ TYPE tmp = ptr[0]; \ for (int i = len - 1; i > 0; i--) \ data[i] = ptr[i]; \ @@ -127,8 +127,8 @@ stream.write (&tmp_type, 1); \ TYPE *ptr = new TYPE [len]; \ for (int i = 0; i < len; i++) \ - ptr[i] = (TYPE) data[i]; \ - stream.write ((TYPE *) ptr, size * len); \ + ptr[i] = X_CAST (TYPE, data[i]); \ + stream.write (ptr, size * len); \ delete [] ptr ; \ } \ while (0) @@ -161,7 +161,7 @@ static void IEEE_big_double_to_IEEE_little_double (double *d, int len) { - swap_8_bytes (static_cast (d), len); + swap_8_bytes (d, len); } static void @@ -185,7 +185,7 @@ static void IEEE_big_float_to_IEEE_little_float (float *d, int len) { - swap_4_bytes (static_cast (d), len); + swap_4_bytes (d, len); } static void @@ -209,7 +209,7 @@ static void IEEE_little_double_to_IEEE_big_double (double *d, int len) { - swap_8_bytes (static_cast (d), len); + swap_8_bytes (d, len); } static void @@ -233,7 +233,7 @@ static void IEEE_little_float_to_IEEE_big_float (float *d, int len) { - swap_4_bytes (static_cast (d), len); + swap_4_bytes (d, len); } static void @@ -634,9 +634,9 @@ case LS_FLOAT: { - volatile float *ptr = static_cast (data); + volatile float *ptr = X_CAST (float *, data); is.read (data, 4 * len); - do_float_format_conversion (static_cast (data), len, fmt); + do_float_format_conversion (X_CAST (float *, data), len, fmt); float tmp = ptr[0]; for (int i = len - 1; i > 0; i--) data[i] = ptr[i]; @@ -690,7 +690,7 @@ case LS_DOUBLE: { - char tmp_type = static_cast (type); + char tmp_type = X_CAST (char, type); os.write (&tmp_type, 1); os.write (data, 8 * len); } diff --git a/liboctave/dir-ops.h b/liboctave/dir-ops.h --- a/liboctave/dir-ops.h +++ b/liboctave/dir-ops.h @@ -58,7 +58,7 @@ bool ok (void) const { return dir && ! fail; } - operator void* () const { return ok () ? (void *) -1 : (void *) 0; } + operator bool () const { return ok (); } string error (void) const { return ok () ? string () : errmsg; } diff --git a/liboctave/file-stat.h b/liboctave/file-stat.h --- a/liboctave/file-stat.h +++ b/liboctave/file-stat.h @@ -112,9 +112,7 @@ bool ok (void) const { return initialized && ! fail; } - operator void* () const - { return ok () - ? static_cast (-1) : static_cast (0); } + operator bool () const { return ok (); } bool exists (void) const { return ok (); } diff --git a/liboctave/idx-vector.h b/liboctave/idx-vector.h --- a/liboctave/idx-vector.h +++ b/liboctave/idx-vector.h @@ -212,8 +212,7 @@ return *this; } - operator void * () const - { return static_cast (rep->ok ()); } + operator bool () const { return rep->ok (); } int capacity (void) const { return rep->capacity (); } int length (int cl) const { return rep->length (cl); } diff --git a/liboctave/oct-alloc.cc b/liboctave/oct-alloc.cc --- a/liboctave/oct-alloc.cc +++ b/liboctave/oct-alloc.cc @@ -79,13 +79,13 @@ while (p < last) { char *next = p + item_size; - (static_cast (p)) -> next = static_cast (next); + (X_CAST (link *, p)) -> next = X_CAST (link *, next); p = next; } - (static_cast (last)) -> next = 0; + (X_CAST (link *, last)) -> next = 0; - head = static_cast (start); + head = X_CAST (link *, start); } else { diff --git a/liboctave/oct-group.h b/liboctave/oct-group.h --- a/liboctave/oct-group.h +++ b/liboctave/oct-group.h @@ -69,9 +69,7 @@ bool ok (void) const { return valid; } - operator void* () const - { return ok () - ? static_cast (-1) : static_cast (0); } + operator bool () const { return ok (); } static octave_group getgrent (void); static octave_group getgrent (string& msg); diff --git a/liboctave/oct-passwd.h b/liboctave/oct-passwd.h --- a/liboctave/oct-passwd.h +++ b/liboctave/oct-passwd.h @@ -80,9 +80,7 @@ bool ok (void) const { return valid; } - operator void* () const - { return ok () - ? static_cast (-1) : static_cast (0); } + operator bool () const { return ok (); } static octave_passwd getpwent (void); static octave_passwd getpwent (string& msg); diff --git a/liboctave/prog-args.cc b/liboctave/prog-args.cc --- a/liboctave/prog-args.cc +++ b/liboctave/prog-args.cc @@ -33,7 +33,7 @@ { if (long_opts) return ::getopt_long (xargc, xargv, short_opts, - static_cast (long_opts), 0); + X_CAST (const struct option *, long_opts), 0); else return ::getopt (xargc, xargv, short_opts); } diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,47 @@ +Thu Feb 5 02:27:18 1998 John W. Eaton + + * ov-bool-mat.cc: Only declare assign function if + CXX_NEW_FRIEND_TEMPLATE_DECL is not defined. + + * ov-base.h, ov-bool-mat.h, ov-bool.h, ov-ch-mat.h, ov-complex.h, + ov-cx-mat.h, ov-range.h, ov-re-mat.h, ov-scalar.h: Handle default + args for *_value functions consistently. + + * symtab.cc (maybe_list_cmp_fcn): Declare args as void*, not + void**, then use X_CAST. + + * OPERATORS/op-s-cm.cc: Include mx-cm-s.h. + + * defun-int.h: Include ov-builtin.h, ov-mapper.h, and symtab.h. + (install_builtin_mapper, install_builtin_function, + install_builtin_variable) Use specific types rather than void * in + declaration. + * defun.cc (install_builtin_mapper, install_builtin_function, + install_builtin_variable): Likewise. Eliminate casts. + + * load-save.cc (read_binary_data, read_mat_file_header, + save_binary_data): Use X_CAST, not static_cast. + * unwind-prot.h (unwind_protect::save_ptr): Likewise. + * Map.cc (goodCHptr, index_to_CHptr, CHptr_to_index): Likewise. + * dynamic-ld.cc (octave_dlopen_dynamic_loder::resolve_reference): + Likewise. + + * pt-mat.cc (tm_const::operator bool ()): + (tm_row_const::operator bool ()): Likewise. + * oct-stream.cc (printf_value_cache::operator bool ()): Likewise. + (scanf_format_list::operator bool ()): Likewise. + (printf_format_list::operator bool ()): Likewise. + (octave_stream::operator bool ()): Likewise. + +Wed Feb 4 13:08:29 1998 John W. Eaton + + * DLD-FUNCTIONS/minmax.cc: Include cmath, not oct-math.h. + + * syscalls.cc (Fdup2): Convert stream to actual system file id. + + * oct-stream.cc (octave_base_stream::fileno, octave_stream::fileno): + New functions. + Tue Feb 3 00:24:44 1998 John W. Eaton * defaults.cc (exec_path): Append Vbin_dir to std_path. diff --git a/src/DLD-FUNCTIONS/minmax.cc b/src/DLD-FUNCTIONS/minmax.cc --- a/src/DLD-FUNCTIONS/minmax.cc +++ b/src/DLD-FUNCTIONS/minmax.cc @@ -24,8 +24,9 @@ #include #endif +#include + #include "lo-ieee.h" -#include "oct-math.h" #include "defun-dld.h" #include "error.h" diff --git a/src/Map.cc b/src/Map.cc --- a/src/Map.cc +++ b/src/Map.cc @@ -116,22 +116,20 @@ static int goodCHptr (CHNode *t) { - return (((static_cast (t)) & 1) == 0); + return (((X_CAST (unsigned, t)) & 1) == 0); } -// This sucks, but avoids g++ 2.6.0 `type unification failed' errors. - static void * index_to_CHptr (int i) { - return static_cast ((i << 1) + 1); + return X_CAST (void *, (i << 1) + 1); } template static unsigned int CHptr_to_index (CHNode *t) { - return (static_cast (t)) >> 1; + return (X_CAST (unsigned, t)) >> 1; } template diff --git a/src/OPERATORS/op-s-cm.cc b/src/OPERATORS/op-s-cm.cc --- a/src/OPERATORS/op-s-cm.cc +++ b/src/OPERATORS/op-s-cm.cc @@ -29,6 +29,7 @@ #endif #include "mx-s-cm.h" +#include "mx-cm-s.h" #include "gripes.h" #include "ov.h" diff --git a/src/defun-int.h b/src/defun-int.h --- a/src/defun-int.h +++ b/src/defun-int.h @@ -25,6 +25,9 @@ #include +#include "ov-builtin.h" +#include "ov-mapper.h" +#include "symtab.h" #include "version.h" class octave_value; @@ -33,19 +36,17 @@ extern void check_version (const string& version, const string& fcn); -// XXX FIXME XXX -- change to use actual pointer types instead of void* -// when things are not changing as rapidly. +extern void +install_builtin_mapper (octave_mapper *mf); extern void -install_builtin_mapper (void *mf); - -extern void -install_builtin_function (void *f, const string& name, const string& doc, - bool is_text_fcn = false); +install_builtin_function (octave_builtin::fcn f, const string& name, + const string& doc, bool is_text_fcn = false); extern void install_builtin_variable (const string& n, const octave_value& v, - bool iaf, bool p, bool e, void *svf, + bool iaf, bool p, bool e, + symbol_record::change_function chg_fcn, const string& h); extern void diff --git a/src/defun.cc b/src/defun.cc --- a/src/defun.cc +++ b/src/defun.cc @@ -69,10 +69,8 @@ // Install variables and functions in the symbol tables. void -install_builtin_mapper (void *mf_arg) +install_builtin_mapper (octave_mapper *mf) { - octave_mapper *mf = static_cast (mf_arg); - symbol_record *sym_rec = global_sym_tab->lookup (mf->name (), true); unsigned int t @@ -86,11 +84,9 @@ } void -install_builtin_function (void *f_arg, const string& name, +install_builtin_function (octave_builtin::fcn f, const string& name, const string& doc, bool is_text_fcn) { - octave_builtin::fcn f = static_cast (f_arg); - symbol_record *sym_rec = global_sym_tab->lookup (name, true); unsigned int t = symbol_record::BUILTIN_FUNCTION; @@ -129,13 +125,11 @@ void install_builtin_variable (const string& name, const octave_value& value, - bool install_as_function, bool protect, - bool eternal, void *chg_fcn_arg, + bool install_as_function, + bool protect, bool eternal, + symbol_record::change_function chg_fcn, const string& help_string) { - symbol_record::change_function chg_fcn - = static_cast (chg_fcn_arg); - if (install_as_function) install_builtin_variable_as_function (name, value, protect, eternal, help_string); diff --git a/src/dynamic-ld.cc b/src/dynamic-ld.cc --- a/src/dynamic-ld.cc +++ b/src/dynamic-ld.cc @@ -98,7 +98,7 @@ { void *tmp = dlsym (handle, nm); - retval = static_cast (tmp); + retval = X_CAST (octave_dynamic_loader::builtin_fcn_installer, tmp); if (! retval) { diff --git a/src/load-save.cc b/src/load-save.cc --- a/src/load-save.cc +++ b/src/load-save.cc @@ -754,7 +754,7 @@ if (! is) return 0; if (swap) - swap_4_bytes (static_cast (&name_len)); + swap_4_bytes (X_CAST (char *, &name_len)); name = new char [name_len+1]; name[name_len] = '\0'; @@ -765,7 +765,7 @@ if (! is) goto data_read_error; if (swap) - swap_4_bytes (static_cast (&doc_len)); + swap_4_bytes (X_CAST (char *, &doc_len)); doc = new char [doc_len+1]; doc[doc_len] = '\0'; @@ -787,7 +787,7 @@ if (! is.read (&tmp, 1)) goto data_read_error; double dtmp; - read_doubles (is, &dtmp, static_cast (tmp), 1, swap, fmt); + read_doubles (is, &dtmp, X_CAST (save_type, tmp), 1, swap, fmt); if (error_state || ! is) goto data_read_error; tc = dtmp; @@ -800,17 +800,17 @@ if (! is.read (&nr, 4)) goto data_read_error; if (swap) - swap_4_bytes (static_cast (&nr)); + swap_4_bytes (X_CAST (char *, &nr)); if (! is.read (&nc, 4)) goto data_read_error; if (swap) - swap_4_bytes (static_cast (&nc)); + swap_4_bytes (X_CAST (char *, &nc)); if (! is.read (&tmp, 1)) goto data_read_error; Matrix m (nr, nc); double *re = m.fortran_vec (); int len = nr * nc; - read_doubles (is, re, static_cast (tmp), len, swap, fmt); + read_doubles (is, re, X_CAST (save_type, tmp), len, swap, fmt); if (error_state || ! is) goto data_read_error; tc = m; @@ -822,8 +822,8 @@ if (! is.read (&tmp, 1)) goto data_read_error; Complex ctmp; - read_doubles (is, static_cast (&ctmp), - static_cast (tmp), 2, swap, fmt); + read_doubles (is, X_CAST (double *, &ctmp), + X_CAST (save_type, tmp), 2, swap, fmt); if (error_state || ! is) goto data_read_error; tc = ctmp; @@ -836,18 +836,18 @@ if (! is.read (&nr, 4)) goto data_read_error; if (swap) - swap_4_bytes (static_cast (&nr)); + swap_4_bytes (X_CAST (char *, &nr)); if (! is.read (&nc, 4)) goto data_read_error; if (swap) - swap_4_bytes (static_cast (&nc)); + swap_4_bytes (X_CAST (char *, &nc)); if (! is.read (&tmp, 1)) goto data_read_error; ComplexMatrix m (nr, nc); Complex *im = m.fortran_vec (); int len = nr * nc; - read_doubles (is, static_cast (im), - static_cast (tmp), 2*len, swap, fmt); + read_doubles (is, X_CAST (double *, im), + X_CAST (save_type, tmp), 2*len, swap, fmt); if (error_state || ! is) goto data_read_error; tc = m; @@ -860,7 +860,7 @@ if (! is.read (&len, 4)) goto data_read_error; if (swap) - swap_4_bytes (static_cast (&len)); + swap_4_bytes (X_CAST (char *, &len)); char *s = new char [len+1]; if (! is.read (s, len)) { @@ -880,15 +880,15 @@ if (! is.read (&bas, 8)) goto data_read_error; if (swap) - swap_8_bytes (static_cast (&bas)); + swap_8_bytes (X_CAST (char *, &bas)); if (! is.read (&lim, 8)) goto data_read_error; if (swap) - swap_8_bytes (static_cast (&lim)); + swap_8_bytes (X_CAST (char *, &lim)); if (! is.read (&inc, 8)) goto data_read_error; if (swap) - swap_8_bytes (static_cast (&inc)); + swap_8_bytes (X_CAST (char *, &inc)); Range r (bas, lim, inc); tc = r; } @@ -900,7 +900,7 @@ if (! is.read (&elements, 4)) goto data_read_error; if (swap) - swap_4_bytes (static_cast (&elements)); + swap_4_bytes (X_CAST (char *, &elements)); charMatrix chm (elements, 0); int max_len = 0; for (int i = 0; i < elements; i++) @@ -909,7 +909,7 @@ if (! is.read (&len, 4)) goto data_read_error; if (swap) - swap_4_bytes (static_cast (&len)); + swap_4_bytes (X_CAST (char *, &len)); char *tmp = new char [len+1]; if (! is.read (tmp, len)) { @@ -1152,11 +1152,11 @@ if (swap) { - swap_4_bytes (static_cast (&mopt)); - swap_4_bytes (static_cast (&nr)); - swap_4_bytes (static_cast (&nc)); - swap_4_bytes (static_cast (&imag)); - swap_4_bytes (static_cast (&len)); + swap_4_bytes (X_CAST (char *, &mopt)); + swap_4_bytes (X_CAST (char *, &nr)); + swap_4_bytes (X_CAST (char *, &nc)); + swap_4_bytes (X_CAST (char *, &imag)); + swap_4_bytes (X_CAST (char *, &len)); } if (mopt > 9999 || mopt < 0 || imag > 1 || imag < 0) @@ -1918,7 +1918,7 @@ st = get_save_type (max_val, min_val); } const Complex *mtmp = m.data (); - write_doubles (os, static_cast (mtmp), st, 2*len); + write_doubles (os, X_CAST (const double *, mtmp), st, 2*len); } else if (tc.is_string ()) { diff --git a/src/oct-stream.cc b/src/oct-stream.cc --- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -720,6 +720,41 @@ } } +int +octave_base_stream::fileno (void) +{ + // Kluge alert! + + if (name () == "stdin") + return 0; + + if (name () == "stdout") + return 1; + + if (name () == "stderr") + return 2; + + int retval = -1; + + istream *is = input_stream (); + ostream *os = output_stream (); + + int i_fid = is ? ((filebuf *) (is->rdbuf ()))->fd () : -1; + int o_fid = os ? ((filebuf *) (os->rdbuf ()))->fd () : -1; + + if (i_fid >= 0) + { + if (o_fid >= 0) + retval = (i_fid == o_fid) ? i_fid : -1; + else + retval = i_fid; + } + else if (o_fid >= 0) + retval = o_fid; + + return retval; +} + void octave_base_stream::error (const string& msg) { @@ -1541,11 +1576,7 @@ // Get the current value as a string and advance the internal pointer. string string_value (void); - operator void* () const - { - return (curr_state == ok) - ? static_cast (-1) : static_cast (0); - } + operator bool () const { return (curr_state == ok); } bool no_more_values (void) { return curr_state == list_exhausted; } diff --git a/src/oct-stream.h b/src/oct-stream.h --- a/src/oct-stream.h +++ b/src/oct-stream.h @@ -93,11 +93,7 @@ bool ok (void) const { return (nconv >= 0); } - operator void* () const - { - return ok () - ? static_cast (-1) : static_cast (0); - } + operator bool () const { return ok (); } bool all_character_conversions (void); @@ -182,11 +178,7 @@ bool ok (void) const { return (nconv >= 0); } - operator void* () const - { - return ok () - ? static_cast (-1) : static_cast (0); - } + operator bool () const { return ok (); } private: @@ -265,6 +257,8 @@ virtual ostream *output_stream (void) { return 0; } + int fileno (void); + bool ok (void) const { return ! fail; } // Return current error message for this stream. @@ -418,13 +412,11 @@ return error (clear, err_num); } + int fileno (void) { return rep ? rep->fileno () : -1; } + bool ok (void) const { return rep && rep->ok (); } - operator void* () const - { - return ok () - ? static_cast (-1) : static_cast (0); - } + operator bool () const { return ok (); } string name (void); diff --git a/src/ov-base.h b/src/ov-base.h --- a/src/ov-base.h +++ b/src/ov-base.h @@ -146,17 +146,18 @@ bool is_function (void) const { return false; } - double double_value (bool) const; + double double_value (bool = false) const; - double scalar_value (bool) const { return double_value (); } - - Matrix matrix_value (bool frc_str_conv = false) const; + double scalar_value (bool frc_str_conv = false) const + { return double_value (frc_str_conv); } - Complex complex_value (bool frc_str_conv = false) const; + Matrix matrix_value (bool = false) const; + + Complex complex_value (bool = false) const; - ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const; + ComplexMatrix complex_matrix_value (bool = false) const; - charMatrix char_matrix_value (bool frc_str_conv = false) const; + charMatrix char_matrix_value (bool = false) const; string_vector all_strings (void) const; diff --git a/src/ov-bool-mat.cc b/src/ov-bool-mat.cc --- a/src/ov-bool-mat.cc +++ b/src/ov-bool-mat.cc @@ -112,7 +112,9 @@ return retval; } +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) extern void assign (Array2&, const Array2&); +#endif void octave_bool_matrix::assign (const octave_value_list& idx, diff --git a/src/ov-bool-mat.h b/src/ov-bool-mat.h --- a/src/ov-bool-mat.h +++ b/src/ov-bool-mat.h @@ -107,15 +107,18 @@ double double_value (bool = false) const; - double scalar_value (bool = false) const { return double_value (); } + double scalar_value (bool frc_str_conv = false) const + { return double_value (frc_str_conv); } Matrix matrix_value (bool = false) const { return matrix; } Complex complex_value (bool = false) const; - ComplexMatrix complex_matrix_value (bool = false) const { return matrix; } + ComplexMatrix complex_matrix_value (bool = false) const + { return matrix; } - boolMatrix bool_matrix_value (bool = false) const { return matrix; } + boolMatrix bool_matrix_value (bool = false) const + { return matrix; } octave_value convert_to_str (void) const { return octave_value (matrix); } diff --git a/src/ov-bool.h b/src/ov-bool.h --- a/src/ov-bool.h +++ b/src/ov-bool.h @@ -104,7 +104,8 @@ double scalar_value (bool = false) const { return scalar; } - Matrix matrix_value (bool = false) const { return Matrix (1, 1, scalar); } + Matrix matrix_value (bool = false) const + { return Matrix (1, 1, scalar); } Complex complex_value (bool = false) const { return scalar; } diff --git a/src/ov-ch-mat.h b/src/ov-ch-mat.h --- a/src/ov-ch-mat.h +++ b/src/ov-ch-mat.h @@ -106,15 +106,18 @@ double double_value (bool = false) const; - double scalar_value (bool = false) const { return double_value (); } + double scalar_value (bool frc_str_conv = false) const + { return double_value (frc_str_conv); } Matrix matrix_value (bool = false) const { return matrix; } Complex complex_value (bool = false) const; - ComplexMatrix complex_matrix_value (bool = false) const { return matrix; } + ComplexMatrix complex_matrix_value (bool = false) const + { return matrix; } - charMatrix char_matrix_value (bool = false) const { return matrix; } + charMatrix char_matrix_value (bool = false) const + { return matrix; } octave_value convert_to_str (void) const { return octave_value (matrix, true); } diff --git a/src/ov-complex.h b/src/ov-complex.h --- a/src/ov-complex.h +++ b/src/ov-complex.h @@ -104,7 +104,8 @@ double double_value (bool = false) const; - double scalar_value (bool = false) const { return double_value (); } + double scalar_value (bool frc_str_conv = false) const + { return double_value (frc_str_conv); } Matrix matrix_value (bool = false) const; diff --git a/src/ov-cx-mat.h b/src/ov-cx-mat.h --- a/src/ov-cx-mat.h +++ b/src/ov-cx-mat.h @@ -112,9 +112,10 @@ bool is_empty (void) const { return (rows () == 0 && columns () == 0); } - double double_value (bool) const; + double double_value (bool = false) const; - double scalar_value (bool) const { return double_value (); } + double scalar_value (bool frc_str_conv = false) const + { return double_value (frc_str_conv); } Matrix matrix_value (bool = false) const; diff --git a/src/ov-range.h b/src/ov-range.h --- a/src/ov-range.h +++ b/src/ov-range.h @@ -127,16 +127,17 @@ // XXX DO ME XXX bool is_true (void) const; - double double_value (bool) const; + double double_value (bool = false) const; - double scalar_value (bool) const { return double_value (); } + double scalar_value (bool frc_str_conv = false) const + { return double_value (frc_str_conv); } - Matrix matrix_value (bool) const + Matrix matrix_value (bool = false) const { return range.matrix_value (); } - Complex complex_value (bool) const; + Complex complex_value (bool = false) const; - ComplexMatrix complex_matrix_value (bool) const + ComplexMatrix complex_matrix_value (bool = false) const { return range.matrix_value (); } Range range_value (void) const { return range; } diff --git a/src/ov-re-mat.h b/src/ov-re-mat.h --- a/src/ov-re-mat.h +++ b/src/ov-re-mat.h @@ -128,13 +128,15 @@ double double_value (bool = false) const; - double scalar_value (bool = false) const { return double_value (); } + double scalar_value (bool frc_str_conv = false) const + { return double_value (frc_str_conv); } Matrix matrix_value (bool = false) const { return matrix; } Complex complex_value (bool = false) const; - ComplexMatrix complex_matrix_value (bool = false) const { return matrix; } + ComplexMatrix complex_matrix_value (bool = false) const + { return matrix; } octave_value not (void) const { return octave_value (! matrix); } diff --git a/src/ov-scalar.h b/src/ov-scalar.h --- a/src/ov-scalar.h +++ b/src/ov-scalar.h @@ -105,7 +105,8 @@ double scalar_value (bool = false) const { return scalar; } - Matrix matrix_value (bool = false) const { return Matrix (1, 1, scalar); } + Matrix matrix_value (bool = false) const + { return Matrix (1, 1, scalar); } Complex complex_value (bool = false) const { return scalar; } diff --git a/src/pt-mat.cc b/src/pt-mat.cc --- a/src/pt-mat.cc +++ b/src/pt-mat.cc @@ -161,11 +161,7 @@ Pix first (void) const { return rep->first (); } void next (Pix& p) const { rep->next (p); } - operator void* () const - { - return (rep && rep->ok) - ? static_cast (-1) : static_cast (0); - } + operator bool () const { return (rep && rep->ok); } private: @@ -287,8 +283,7 @@ bool complex_p (void) const { return is_cmplx; } bool all_empty_p (void) const { return all_mt; } - operator void* () const - { return ok ? static_cast (-1) : static_cast (0); } + operator bool () const { return ok; } private: diff --git a/src/symtab.cc b/src/symtab.cc --- a/src/symtab.cc +++ b/src/symtab.cc @@ -562,12 +562,15 @@ } static int -maybe_list_cmp_fcn (symbol_record **a_arg, symbol_record **b_arg) +maybe_list_cmp_fcn (const void *a_arg, const void *b_arg) { - string a = (*a_arg)->name (); - string b = (*b_arg)->name (); + const symbol_record *a = *(X_CAST (const symbol_record **, a_arg)); + const symbol_record *b = *(X_CAST (const symbol_record **, b_arg)); - return a.compare (b); + string a_nm = a->name (); + string b_nm = b->name (); + + return a_nm.compare (b_nm); } int diff --git a/src/syscalls.cc b/src/syscalls.cc --- a/src/syscalls.cc +++ b/src/syscalls.cc @@ -106,32 +106,28 @@ if (nargin == 2) { - double d_old = args(0).double_value (); - double d_new = args(1).double_value (); + octave_stream *old_stream = octave_stream_list::lookup (args(0)); + octave_stream *new_stream = octave_stream_list::lookup (args(1)); if (! error_state) { - if (D_NINT (d_old) == d_old && D_NINT (d_new) == d_new) - { - int i_old = NINT (d_old); - int i_new = NINT (d_new); + int i_old = old_stream->fileno (); + int i_new = new_stream->fileno (); - // XXX FIXME XXX -- are these checks sufficient? - if (i_old >= 0 && i_new >= 0) - { - string msg; + if (i_old >= 0 && i_new >= 0) + { + string msg; - int status = octave_syscalls::dup2 (i_old, i_new, msg); + int status = octave_syscalls::dup2 (i_old, i_new, msg); - retval(0) = static_cast (status); - retval(1) = msg; - } - else - error ("dup2: invalid file id"); + retval(0) = static_cast (status); + retval(1) = msg; } else - error ("dup2: arguments must be integer values"); + error ("dup2: invalid file id"); } + else + error ("dup2: invalid stream"); } else print_usage ("dup2"); diff --git a/src/unwind-prot.h b/src/unwind-prot.h --- a/src/unwind-prot.h +++ b/src/unwind-prot.h @@ -126,8 +126,7 @@ unwind_protect::save_str (&(s), (s)) #define unwind_protect_ptr(p) \ - unwind_protect::save_ptr (static_cast (&(p)), \ - static_cast (p)) + unwind_protect::save_ptr (X_CAST (void **, &(p)), X_CAST (void *, (p))) #endif