# HG changeset patch # User Markus Mützel # Date 1645879608 -3600 # Sat Feb 26 13:46:48 2022 +0100 # Branch stable # Node ID 770abc46e312bc29cb9b63f4b66056899e16aa02 # Parent a4dbec69e1b5e0b59ee5d5de3eda20f3e4bf1aa1 Remove `time_t` from API (bug #61821). The bit-width of `time_t` might change depending on compile time switches. That can cause a mismatch between class declarations in public headers and the actual alignment of the compiled classes. Avoid that problem by not using `time_t` in (public) headers. * build-aux/mk-octave-config-h.sh, oct-conf-post.in.h: Define OCTAVE_TIME_T to `int64_t`. The type of `time_t` is not defined in the C/C++ standards. However in all(?) implementations, it's either a signed 32-bit or a signed 64-bit integer. Use a signed 64-bit integer for storing those values in Octave classes. * other files: Use OCTAVE_TIME_T instead of `time_t`. diff -r a4dbec69e1b5 -r 770abc46e312 build-aux/mk-octave-config-h.sh --- a/build-aux/mk-octave-config-h.sh Sat Feb 26 11:35:54 2022 +0100 +++ b/build-aux/mk-octave-config-h.sh Sat Feb 26 13:46:48 2022 +0100 @@ -266,6 +266,8 @@ # define OCTAVE_HAVE_F77_INT_TYPE 1 +/* time type in API is always 64 bits wide */ +# define OCTAVE_TIME_T int64_t # if defined (__cplusplus) && ! defined (OCTAVE_THREAD_LOCAL) # define OCTAVE_THREAD_LOCAL diff -r a4dbec69e1b5 -r 770abc46e312 libgui/liboctgui-build-info.h --- a/libgui/liboctgui-build-info.h Sat Feb 26 11:35:54 2022 +0100 +++ b/libgui/liboctgui-build-info.h Sat Feb 26 13:46:48 2022 +0100 @@ -28,8 +28,6 @@ #include "octave-config.h" -#include - #include extern OCTGUI_API std::string liboctgui_hg_id (void); diff -r a4dbec69e1b5 -r 770abc46e312 libinterp/corefcn/__ftp__.cc --- a/libinterp/corefcn/__ftp__.cc Sat Feb 26 11:35:54 2022 +0100 +++ b/libinterp/corefcn/__ftp__.cc Sat Feb 26 13:46:48 2022 +0100 @@ -167,14 +167,15 @@ for (octave_idx_type i = 0; i < n; i++) { - time_t ftime; + OCTAVE_TIME_T ftime; bool fisdir; double fsize; url_xfer.get_fileinfo (sv(i), fsize, ftime, fisdir); fileisdir(i) = fisdir; - filectime(i) = ctime (&ftime); + time_t ftime_t = ftime; + filectime(i) = ctime (&ftime_t); filesize(i) = fsize; filedatenum(i) = double (ftime); } @@ -439,7 +440,7 @@ { n++; - time_t ftime; + OCTAVE_TIME_T ftime; bool fisdir; double fsize; diff -r a4dbec69e1b5 -r 770abc46e312 libinterp/corefcn/fcn-info.cc --- a/libinterp/corefcn/fcn-info.cc Sat Feb 26 11:35:54 2022 +0100 +++ b/libinterp/corefcn/fcn-info.cc Sat Feb 26 13:46:48 2022 +0100 @@ -603,7 +603,7 @@ // Same file. If it is out of date, then reload it. sys::time ottp = fcn->time_parsed (); - time_t tp = ottp.unix_time (); + OCTAVE_TIME_T tp = ottp.unix_time (); fcn->mark_fcn_file_up_to_date (sys::time ()); diff -r a4dbec69e1b5 -r 770abc46e312 libinterp/corefcn/load-path.cc --- a/libinterp/corefcn/load-path.cc Sat Feb 26 11:35:54 2022 +0100 +++ b/libinterp/corefcn/load-path.cc Sat Feb 26 13:46:48 2022 +0100 @@ -1487,7 +1487,7 @@ { is_relative = ! sys::env::absolute_pathname (dir_name); - dir_time_last_checked = sys::time (static_cast (0)); + dir_time_last_checked = sys::time (static_cast (0)); sys::file_stat fs (dir_name); diff -r a4dbec69e1b5 -r 770abc46e312 libinterp/liboctinterp-build-info.h --- a/libinterp/liboctinterp-build-info.h Sat Feb 26 11:35:54 2022 +0100 +++ b/libinterp/liboctinterp-build-info.h Sat Feb 26 13:46:48 2022 +0100 @@ -28,8 +28,6 @@ #include "octave-config.h" -#include - #include extern OCTINTERP_API std::string liboctinterp_hg_id (void); diff -r a4dbec69e1b5 -r 770abc46e312 libinterp/octave-value/ov-fcn.h --- a/libinterp/octave-value/ov-fcn.h Sat Feb 26 11:35:54 2022 +0100 +++ b/libinterp/octave-value/ov-fcn.h Sat Feb 26 13:46:48 2022 +0100 @@ -95,10 +95,10 @@ virtual octave::symbol_scope scope (void) { return octave::symbol_scope (); } virtual octave::sys::time time_parsed (void) const - { return octave::sys::time (static_cast (0)); } + { return octave::sys::time (static_cast (0)); } virtual octave::sys::time time_checked (void) const - { return octave::sys::time (static_cast (0)); } + { return octave::sys::time (static_cast (0)); } virtual int call_depth (void) const { return 0; } diff -r a4dbec69e1b5 -r 770abc46e312 libinterp/octave-value/ov-usr-fcn.h --- a/libinterp/octave-value/ov-usr-fcn.h Sat Feb 26 11:35:54 2022 +0100 +++ b/libinterp/octave-value/ov-usr-fcn.h Sat Feb 26 13:46:48 2022 +0100 @@ -28,8 +28,6 @@ #include "octave-config.h" -#include - #include #include "comment-list.h" @@ -64,8 +62,8 @@ octave::tree_statement_list *cmds = nullptr, const std::string& ds = "") : octave_function (nm, ds), m_scope (scope), m_file_name (fnm), - m_t_parsed (static_cast (0)), - m_t_checked (static_cast (0)), + m_t_parsed (static_cast (0)), + m_t_checked (static_cast (0)), m_file_info (nullptr), m_cmd_list (cmds) { if (m_scope) diff -r a4dbec69e1b5 -r 770abc46e312 liboctave/liboctave-build-info.h --- a/liboctave/liboctave-build-info.h Sat Feb 26 11:35:54 2022 +0100 +++ b/liboctave/liboctave-build-info.h Sat Feb 26 13:46:48 2022 +0100 @@ -28,8 +28,6 @@ #include "octave-config.h" -#include - #include extern OCTAVE_API std::string liboctave_hg_id (void); diff -r a4dbec69e1b5 -r 770abc46e312 liboctave/system/file-stat.cc --- a/liboctave/system/file-stat.cc Sat Feb 26 11:35:54 2022 +0100 +++ b/liboctave/system/file-stat.cc Sat Feb 26 13:46:48 2022 +0100 @@ -235,9 +235,9 @@ } else { - m_atime = sys::time (sys_atime); - m_mtime = sys::time (sys_mtime); - m_ctime = sys::time (sys_ctime); + m_atime = sys::time (static_cast (sys_atime)); + m_mtime = sys::time (static_cast (sys_mtime)); + m_ctime = sys::time (static_cast (sys_ctime)); } m_initialized = true; @@ -267,9 +267,9 @@ } else { - m_atime = sys::time (sys_atime); - m_mtime = sys::time (sys_mtime); - m_ctime = sys::time (sys_ctime); + m_atime = sys::time (static_cast (sys_atime)); + m_mtime = sys::time (static_cast (sys_mtime)); + m_ctime = sys::time (static_cast (sys_ctime)); } m_initialized = true; diff -r a4dbec69e1b5 -r 770abc46e312 liboctave/system/oct-time.cc --- a/liboctave/system/oct-time.cc Sat Feb 26 11:35:54 2022 +0100 +++ b/liboctave/system/oct-time.cc Sat Feb 26 13:46:48 2022 +0100 @@ -53,7 +53,7 @@ namespace sys { time::time (double d) - : m_ot_unix_time (static_cast (d)), m_ot_usec (0) + : m_ot_unix_time (static_cast (d)), m_ot_usec (0) { double ip; m_ot_usec = static_cast (std::modf (d, &ip) * 1e6); @@ -113,7 +113,9 @@ void time::stamp (void) { - octave_gettimeofday_wrapper (&m_ot_unix_time, &m_ot_usec); + time_t ot_unix_time; + octave_gettimeofday_wrapper (&ot_unix_time, &m_ot_usec); + m_ot_unix_time = ot_unix_time; } // From the mktime() manual page: @@ -346,7 +348,10 @@ void cpu_time::stamp (void) { - octave_cpu_time (&m_usr_sec, &m_sys_sec, &m_usr_usec, &m_sys_usec); + time_t usr_sec, sys_sec; + octave_cpu_time (&usr_sec, &sys_sec, &m_usr_usec, &m_sys_usec); + m_usr_sec = usr_sec; + m_sys_sec = sys_sec; } void diff -r a4dbec69e1b5 -r 770abc46e312 liboctave/system/oct-time.h --- a/liboctave/system/oct-time.h Sat Feb 26 11:35:54 2022 +0100 +++ b/liboctave/system/oct-time.h Sat Feb 26 13:46:48 2022 +0100 @@ -28,13 +28,11 @@ #include "octave-config.h" -#include - #include #include static inline double -as_double (time_t sec, long usec) +as_double (OCTAVE_TIME_T sec, long usec) { // Unix time will be exactly representable as a double for more than // 100 million years, so no worry there, and microseconds has a @@ -57,10 +55,10 @@ time (void) : m_ot_unix_time (0), m_ot_usec (0) { stamp (); } - time (time_t t) + time (OCTAVE_TIME_T t) : m_ot_unix_time (t), m_ot_usec (0) { } - time (time_t t, long us) + time (OCTAVE_TIME_T t, long us) : m_ot_unix_time (t), m_ot_usec () { long rem, extra; @@ -109,7 +107,7 @@ return as_double (m_ot_unix_time, m_ot_usec); } - time_t unix_time (void) const { return m_ot_unix_time; } + OCTAVE_TIME_T unix_time (void) const { return m_ot_unix_time; } long usec (void) const { return m_ot_usec; } @@ -120,7 +118,7 @@ private: // Seconds since the epoch. - time_t m_ot_unix_time; + OCTAVE_TIME_T m_ot_unix_time; // Additional microseconds. long m_ot_usec; @@ -422,21 +420,21 @@ return as_double (m_sys_sec, m_sys_usec); } - time_t user_sec (void) const { return m_usr_sec; } + OCTAVE_TIME_T user_sec (void) const { return m_usr_sec; } long user_usec (void) const { return m_usr_usec; } - time_t system_sec (void) const { return m_sys_sec; } + OCTAVE_TIME_T system_sec (void) const { return m_sys_sec; } long system_usec (void) const { return m_sys_usec; } private: - time_t m_usr_sec; - time_t m_sys_sec; + OCTAVE_TIME_T m_usr_sec; + OCTAVE_TIME_T m_sys_sec; long m_usr_usec; long m_sys_usec; - cpu_time (time_t usr_sec, time_t sys_sec, long usr_usec, long sys_usec) + cpu_time (OCTAVE_TIME_T usr_sec, OCTAVE_TIME_T sys_sec, long usr_usec, long sys_usec) : m_usr_sec (usr_sec), m_sys_sec (sys_sec), m_usr_usec (usr_usec), m_sys_usec (sys_usec) { } diff -r a4dbec69e1b5 -r 770abc46e312 liboctave/util/file-info.h --- a/liboctave/util/file-info.h Sat Feb 26 11:35:54 2022 +0100 +++ b/liboctave/util/file-info.h Sat Feb 26 13:46:48 2022 +0100 @@ -42,7 +42,7 @@ public: file_info (void) - : m_file_buf (), m_offsets (), m_timestamp (static_cast (0)) + : m_file_buf (), m_offsets (), m_timestamp (static_cast (0)) { } file_info (const std::string& text, const sys::time& timestamp) diff -r a4dbec69e1b5 -r 770abc46e312 liboctave/util/oct-shlib.h --- a/liboctave/util/oct-shlib.h Sat Feb 26 11:35:54 2022 +0100 +++ b/liboctave/util/oct-shlib.h Sat Feb 26 13:46:48 2022 +0100 @@ -50,7 +50,7 @@ public: dynlib_rep (void) - : m_count (1), m_fcn_names (), m_file (), m_time_loaded (time_t ()), + : m_count (1), m_fcn_names (), m_file (), m_time_loaded (OCTAVE_TIME_T ()), m_search_all_loaded (false) { } diff -r a4dbec69e1b5 -r 770abc46e312 liboctave/util/url-transfer.cc --- a/liboctave/util/url-transfer.cc Sat Feb 26 11:35:54 2022 +0100 +++ b/liboctave/util/url-transfer.cc Sat Feb 26 13:46:48 2022 +0100 @@ -101,7 +101,7 @@ for (octave_idx_type i = 0; i < sv.numel (); i++) { - time_t ftime; + OCTAVE_TIME_T ftime; bool fisdir; double fsize; @@ -547,7 +547,7 @@ } void get_fileinfo (const std::string& filename, double& filesize, - time_t& filetime, bool& fileisdir) + OCTAVE_TIME_T& filetime, bool& fileisdir) { std::string path = pwd (); @@ -573,7 +573,7 @@ } fileisdir = false; - time_t ft; + OCTAVE_TIME_T ft; curl_easy_getinfo (m_curl, CURLINFO_FILETIME, &ft); filetime = ft; double fs; diff -r a4dbec69e1b5 -r 770abc46e312 liboctave/util/url-transfer.h --- a/liboctave/util/url-transfer.h Sat Feb 26 11:35:54 2022 +0100 +++ b/liboctave/util/url-transfer.h Sat Feb 26 13:46:48 2022 +0100 @@ -131,7 +131,7 @@ virtual void get_fileinfo (const std::string& /* filename */, double& /* filesize */, - time_t& /* filetime */, + OCTAVE_TIME_T& /* filetime */, bool& /* fileisdir */) { } virtual std::string pwd (void) { return ""; } @@ -247,7 +247,7 @@ string_vector list (void) { return m_rep->list (); } void get_fileinfo (const std::string& filename, double& filesize, - time_t& filetime, bool& fileisdir) + OCTAVE_TIME_T& filetime, bool& fileisdir) { m_rep->get_fileinfo (filename, filesize, filetime, fileisdir); } diff -r a4dbec69e1b5 -r 770abc46e312 oct-conf-post.in.h --- a/oct-conf-post.in.h Sat Feb 26 11:35:54 2022 +0100 +++ b/oct-conf-post.in.h Sat Feb 26 13:46:48 2022 +0100 @@ -279,6 +279,9 @@ #define OCTAVE_HAVE_F77_INT_TYPE 1 +/* time type in API is always 64 bits wide */ +#define OCTAVE_TIME_T int64_t + #if defined (__cplusplus) && ! defined (OCTAVE_THREAD_LOCAL) # define OCTAVE_THREAD_LOCAL #endif diff -r a4dbec69e1b5 -r 770abc46e312 src/octave-build-info.h --- a/src/octave-build-info.h Sat Feb 26 11:35:54 2022 +0100 +++ b/src/octave-build-info.h Sat Feb 26 13:46:48 2022 +0100 @@ -28,8 +28,6 @@ #include "octave-config.h" -#include - #include extern std::string octave_hg_id (void);