# HG changeset patch # User jwe # Date 1041363787 0 # Node ID df5f2e433a1144b86a40b345d260065c96f48ba6 # Parent c3acf8a967fa16e06210238298ad99310b31b0e1 [project @ 2002-12-31 19:43:07 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,28 @@ 2002-12-31 John W. Eaton + * syscalls.cc (Fmkfifo): Use long_value instead of cast. + + * ov.h (octave_value::short_value, octave_value::ushort_value, + octave_value::uint_value, octave_value::long_value, + octave_value::ulong_value): New functions. + + * syscalls.cc (mk_stat_map, Fgetegid, getgid, geteuid): Likewise. + Delete unnecessary casts. + * file-io.cc (Ffgetl, Ffgets, Fftell, Fsscanf): Likewise. + * toplev.cc (Fsystem): Likewise. + + * ov-file.h (octave_file::double_value, octave_file::scalar_value): + Delete unnecessry cast. + + * ov.cc (octave_value::octave_value): Add constructors for + octave_time, short int, unsigned short int, unsigned int, long + int, unsigned long int, + + * ov.h (octave_value::do_subsref (const std::string&, const + octave_value_list&)): Rename from subsref. Change all derived classes. + + * input.cc (generate_completion): Delete unused variable prefix_len. + * ov.h (DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA): Delete volatile qualifier for decls of static_type_id and t_id. (DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA): Likewise, for def of t_id. diff --git a/src/file-io.cc b/src/file-io.cc --- a/src/file-io.cc +++ b/src/file-io.cc @@ -246,7 +246,7 @@ if (! err) { - retval(1) = static_cast (tmp.length ()); + retval(1) = tmp.length (); retval(0) = tmp; } } @@ -292,7 +292,7 @@ if (! err) { - retval(1) = static_cast (tmp.length ()); + retval(1) = tmp.length (); retval(0) = tmp; } } @@ -623,7 +623,7 @@ octave_stream os = octave_stream_list::lookup (args(0), "ftell"); if (! error_state) - retval = static_cast (os.tell ()); + retval = os.tell (); } else print_usage ("ftell"); @@ -949,7 +949,7 @@ // position will clear it. std::string errmsg = os.error (); - retval(3) = static_cast (os.tell () + 1); + retval(3) = os.tell () + 1; retval(2) = errmsg; retval(1) = count; retval(0) = tmp; diff --git a/src/oct-stream.cc b/src/oct-stream.cc --- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -1796,7 +1796,7 @@ if (OCTAVE_SCAN (is, *elt, &tmp)) { if (! discard) - retval = static_cast (tmp); + retval = tmp; } else quit = true; diff --git a/src/ov-base.cc b/src/ov-base.cc --- a/src/ov-base.cc +++ b/src/ov-base.cc @@ -28,6 +28,8 @@ #include #endif +#include + #include #include "lo-ieee.h" @@ -196,28 +198,39 @@ os << "no info for type: " << type_name () << "\n"; } -int -octave_base_value::int_value (bool require_int, bool frc_str_conv) const -{ - int retval = 0; - - double d = double_value (frc_str_conv); +#define INT_CONV_METHOD(T, F, MIN_LIMIT, MAX_LIMIT) \ + T \ + octave_base_value::F ## _value (bool require_int, bool frc_str_conv) const \ + { \ + T retval = 0; \ + \ + double d = double_value (frc_str_conv); \ + \ + if (! error_state) \ + { \ + if (require_int && D_NINT (d) != d) \ + error ("conversion of %g to " #T " value failed", d); \ + else if (d < MIN_LIMIT || d > MAX_LIMIT) \ + error ("conversion of %g to short int out of range (%d, %d)", \ + d, MIN_LIMIT, MAX_LIMIT); \ + else \ + retval = static_cast (d); \ + } \ + else \ + gripe_wrong_type_arg ("octave_base_value::" #F "_value ()", \ + type_name ()); \ + \ + return retval; \ + } - if (! error_state) - { - if (require_int && D_NINT (d) != d) - { - error ("conversion to integer value failed"); - return retval; - } +INT_CONV_METHOD (short int, short, SHRT_MIN, SHRT_MAX) +INT_CONV_METHOD (unsigned short int, ushort, 0, USHRT_MAX) - retval = static_cast (d); - } - else - gripe_wrong_type_arg ("octave_base_value::int_value ()", type_name ()); +INT_CONV_METHOD (int, int, INT_MIN, INT_MAX) +INT_CONV_METHOD (unsigned int, uint, 0, UINT_MAX) - return retval; -} +INT_CONV_METHOD (long int, long, LONG_MIN, LONG_MAX) +INT_CONV_METHOD (unsigned long int, ulong, 0, ULONG_MAX) int octave_base_value::nint_value (bool frc_str_conv) const diff --git a/src/ov-base.h b/src/ov-base.h --- a/src/ov-base.h +++ b/src/ov-base.h @@ -166,10 +166,20 @@ bool is_dld_function (void) const { return false; } + short int short_value (bool = false, bool = false) const; + + unsigned short int ushort_value (bool = false, bool = false) const; + int int_value (bool = false, bool = false) const; + unsigned int uint_value (bool = false, bool = false) const; + int nint_value (bool = false) const; + long int long_value (bool = false, bool = false) const; + + unsigned long int ulong_value (bool = false, bool = false) const; + double double_value (bool = false) const; double scalar_value (bool frc_str_conv = false) const diff --git a/src/ov-file.h b/src/ov-file.h --- a/src/ov-file.h +++ b/src/ov-file.h @@ -65,9 +65,9 @@ type_conv_fcn numeric_conversion_function (void) const; - double double_value (bool) const { return static_cast (number); } + double double_value (bool) const { return number; } - double scalar_value (bool) const { return static_cast (number); } + double scalar_value (bool) const { return number; } octave_stream stream_value (void) const { return stream; } diff --git a/src/ov.cc b/src/ov.cc --- a/src/ov.cc +++ b/src/ov.cc @@ -343,12 +343,48 @@ rep->count = 1; } +octave_value::octave_value (short int i) + : rep (new octave_scalar (i)) +{ + rep->count = 1; +} + +octave_value::octave_value (unsigned short int i) + : rep (new octave_scalar (i)) +{ + rep->count = 1; +} + octave_value::octave_value (int i) : rep (new octave_scalar (i)) { rep->count = 1; } +octave_value::octave_value (unsigned int i) + : rep (new octave_scalar (i)) +{ + rep->count = 1; +} + +octave_value::octave_value (long int i) + : rep (new octave_scalar (i)) +{ + rep->count = 1; +} + +octave_value::octave_value (unsigned long int i) + : rep (new octave_scalar (i)) +{ + rep->count = 1; +} + +octave_value::octave_value (octave_time t) + : rep (new octave_scalar (t)) +{ + rep->count = 1; +} + octave_value::octave_value (double d) : rep (new octave_scalar (d)) { diff --git a/src/ov.h b/src/ov.h --- a/src/ov.h +++ b/src/ov.h @@ -37,6 +37,7 @@ #include "idx-vector.h" #include "mx-base.h" #include "oct-alloc.h" +#include "oct-time.h" #include "str-vec.h" class Cell; @@ -157,7 +158,13 @@ enum all_va_args { all_va_args_t }; octave_value (void); + octave_value (short int i); + octave_value (unsigned short int i); octave_value (int i); + octave_value (unsigned int i); + octave_value (long int i); + octave_value (unsigned long int i); + octave_value (octave_time t); octave_value (double d); octave_value (const Cell& m); octave_value (const Matrix& m); @@ -408,12 +415,32 @@ octave_value eval (void) { return *this; } + virtual short int + short_value (bool req_int = false, bool frc_str_conv = false) const + { return rep->short_value (req_int, frc_str_conv); } + + virtual unsigned short int + ushort_value (bool req_int = false, bool frc_str_conv = false) const + { return rep->ushort_value (req_int, frc_str_conv); } + virtual int int_value (bool req_int = false, bool frc_str_conv = false) const { return rep->int_value (req_int, frc_str_conv); } + virtual unsigned int + uint_value (bool req_int = false, bool frc_str_conv = false) const + { return rep->uint_value (req_int, frc_str_conv); } + virtual int nint_value (bool frc_str_conv = false) const { return rep->nint_value (frc_str_conv); } + virtual long int + long_value (bool req_int = false, bool frc_str_conv = false) const + { return rep->long_value (req_int, frc_str_conv); } + + virtual unsigned long int + ulong_value (bool req_int = false, bool frc_str_conv = false) const + { return rep->ulong_value (req_int, frc_str_conv); } + virtual double double_value (bool frc_str_conv = false) const { return rep->double_value (frc_str_conv); } diff --git a/src/syscalls.cc b/src/syscalls.cc --- a/src/syscalls.cc +++ b/src/syscalls.cc @@ -66,23 +66,23 @@ Octave_map m; m["dev"](0) = static_cast (fs.dev ()); - m["ino"](0) = static_cast (fs.ino ()); + m["ino"](0) = fs.ino (); m["modestr"](0) = fs.mode_as_string (); - m["nlink"](0) = static_cast (fs.nlink ()); - m["uid"](0) = static_cast (fs.uid ()); - m["gid"](0) = static_cast (fs.gid ()); + m["nlink"](0) = fs.nlink (); + m["uid"](0) = fs.uid (); + m["gid"](0) = fs.gid (); #if defined (HAVE_STRUCT_STAT_ST_RDEV) m["rdev"](0) = static_cast (fs.rdev ()); #endif - m["size"](0) = static_cast (fs.size ()); - m["atime"](0) = static_cast (fs.atime ()); - m["mtime"](0) = static_cast (fs.mtime ()); - m["ctime"](0) = static_cast (fs.ctime ()); + m["size"](0) = fs.size (); + m["atime"](0) = fs.atime (); + m["mtime"](0) = fs.mtime (); + m["ctime"](0) = fs.ctime (); #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE) - m["blksize"](0) = static_cast (fs.blksize ()); + m["blksize"](0) = fs.blksize (); #endif #if defined (HAVE_STRUCT_STAT_ST_BLOCKS) - m["blocks"](0) = static_cast (fs.blocks ()); + m["blocks"](0) = fs.blocks (); #endif return m; @@ -433,7 +433,7 @@ int nargin = args.length (); if (nargin == 0) - retval = static_cast (octave_syscalls::getegid ()); + retval = octave_syscalls::getegid (); else print_usage ("getegid"); @@ -451,7 +451,7 @@ int nargin = args.length (); if (nargin == 0) - retval = static_cast (octave_syscalls::getgid ()); + retval = octave_syscalls::getgid (); else print_usage ("getgid"); @@ -469,7 +469,7 @@ int nargin = args.length (); if (nargin == 0) - retval = static_cast (octave_syscalls::geteuid ()); + retval = octave_syscalls::geteuid (); else print_usage ("geteuid"); @@ -487,7 +487,7 @@ int nargin = args.length (); if (nargin == 0) - retval = static_cast (octave_syscalls::getuid ()); + retval = octave_syscalls::getuid (); else print_usage ("getuid"); @@ -557,16 +557,21 @@ if (args(1).is_scalar_type ()) { - long mode = static_cast (args(1).double_value ()); + long mode = args(1).long_value (); - std::string msg; + if (! error_state) + { + std::string msg; + + int status = file_ops::mkfifo (name, mode, msg); - int status = file_ops::mkfifo (name, mode, msg); + retval(0) = status; - retval(0) = status; - - if (status < 0) - retval(1) = msg; + if (status < 0) + retval(1) = msg; + } + else + error ("mkfifo: invalid MODE"); } else error ("mkfifo: MODE must be an integer"); diff --git a/src/toplev.cc b/src/toplev.cc --- a/src/toplev.cc +++ b/src/toplev.cc @@ -547,7 +547,7 @@ panic_impossible (); } else - retval(0) = static_cast (pid); + retval(0) = pid; #else error ("asynchronous system calls are not supported"); #endif diff --git a/src/utils.cc b/src/utils.cc --- a/src/utils.cc +++ b/src/utils.cc @@ -694,7 +694,7 @@ octave_value retval; if (args.length () == 0) - retval = static_cast (errno); + retval = errno; else print_usage ("errno");