]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cobol: Eliminate unguarded clock_gettime dependencies. [PR119975]
authorRobert Dubner <rdubner@symas.com>
Wed, 11 Jun 2025 19:49:41 +0000 (15:49 -0400)
committerRobert Dubner <rdubner@symas.com>
Tue, 29 Jul 2025 16:06:39 +0000 (12:06 -0400)
These changes are help make it possible to compile on MacOS.  In
addition to guarding clock_settime() calls, it removes the use
of structures and constants needed for clock_settime().

libgcobol/ChangeLog:

PR cobol/119975
* intrinsic.cc (__gg__current_date): Eliminate CLOCK_REALTIME.
(__gg__seconds_past_midnight): Likewise.
(__gg__formatted_current_date): Likewise.
(__gg__random): Likewise.
(__gg__random_next): Likewise.
* libgcobol.cc: include <sys/time.h>.
(__gg__abort): Eliminate CLOCK_REALTIME.
(cobol_time): Likewise.
(get_time_nanoseconds): Rename.
(get_time_nanoseconds_local): Comment; Eliminate CLOCK_REALTIME.
(__gg__clock_gettime): Likewise.
(__gg__get_date_hhmmssff): Likewise.
* libgcobol.h (__gg__clock_gettime): Eliminate clockid_t from declaration.

(cherry picked from commit 582dda08eabc8f7dc9c504c0010d778bd6ff09b2)

libgcobol/intrinsic.cc
libgcobol/libgcobol.cc
libgcobol/libgcobol.h

index 2d8d79c1c7c799ef18df2b3739d51ebbabcd40a2..81ae638630f17e6c53a3b3bbf50835dbd176dbf7 100644 (file)
@@ -1219,7 +1219,7 @@ __gg__current_date(cblc_field_t *dest)
   {
   // FUNCTION CURRENT-DATE
   struct cbl_timespec tp = {};
-  __gg__clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec
+  __gg__clock_gettime(&tp); // time_t tv_sec; long tv_nsec
 
   char retval[DATE_STRING_BUFFER_SIZE];
   timespec_to_string(retval, tp);
@@ -1236,7 +1236,7 @@ __gg__seconds_past_midnight(cblc_field_t *dest)
   struct tm tm;
   __int128 retval=0;
   
-  __gg__clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec
+  __gg__clock_gettime(&tp); // time_t tv_sec; long tv_nsec
   localtime_r(&tp.tv_sec, &tm);
 
   retval += tm.tm_hour;
@@ -1460,7 +1460,7 @@ __gg__formatted_current_date( cblc_field_t *dest, // Destination string
                               size_t input_offset,
                               size_t input_size)
   {
-  // FUNCTION CURRENT-DATE
+  // FUNCTION FORMATTED-CURRENT-DATE
 
   // Establish the destination, and set it to spaces
   char *d    = PTRCAST(char, dest->data);
@@ -1485,7 +1485,7 @@ __gg__formatted_current_date( cblc_field_t *dest, // Destination string
     }
 
   struct cbl_timespec ts = {};
-  __gg__clock_gettime(CLOCK_REALTIME, &ts);
+  __gg__clock_gettime(&ts);
 
   struct tm tm = {};
 #ifdef HAVE_STRUCT_TM_TM_ZONE
@@ -3433,7 +3433,7 @@ __gg__random( cblc_field_t *dest,
     state = (char *)malloc(state_len);
 
     struct cbl_timespec ts;
-    __gg__clock_gettime(CLOCK_REALTIME, &ts);
+    __gg__clock_gettime(&ts);
     initstate_r( ts.tv_nsec, state, state_len, buf);
     }
   int seed = (int)__gg__binary_value_from_qualified_field(&rdigits,
@@ -3473,7 +3473,7 @@ __gg__random_next(cblc_field_t *dest)
     buf->state = NULL;
     state = (char *)malloc(state_len);
     struct cbl_timespec ts;
-    __gg__clock_gettime(CLOCK_REALTIME, &ts);
+    __gg__clock_gettime(&ts);
     initstate_r( ts.tv_nsec, state, state_len, buf);
     }
   random_r(buf, &retval_31);
index f8697afd59cb596ca098131edbac8124bdbe3622..81b5b7af812134cafde17487809f8023b6b8431a 100644 (file)
@@ -69,6 +69,7 @@
 #include <sys/resource.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/time.h>
 #include <execinfo.h>
 #include "exceptl.h"
 
@@ -264,7 +265,7 @@ class ec_status_t {
                     ,  operation(file_op_none)
                     ,  mode(file_mode_none_e)
                     ,  user_status(nullptr)
-                    ,  filename(nullptr) 
+                    ,  filename(nullptr)
                       {}
     explicit file_status_t( const cblc_file_t *file )
                     : ifile(file->symbol_table_index)
@@ -558,7 +559,7 @@ __gg__abort(const char *msg)
   abort();
   }
 
-void 
+void
 __gg__mabort()
   {
   __gg__abort("Memory allocation error\n");
@@ -2290,7 +2291,7 @@ static time_t
 cobol_time()
   {
   struct cbl_timespec tp;
-  __gg__clock_gettime(CLOCK_REALTIME, &tp);
+  __gg__clock_gettime(&tp);
   return tp.tv_sec;
   }
 
@@ -2402,12 +2403,28 @@ int_from_digits(const char * &p, int ndigits)
   return retval;
   }
 
-uint64_t
-get_time_nanoseconds()
+// For testing purposes, this undef causes the use of gettimeofday().
+// #undef HAVE_CLOCK_GETTIME
+
+static uint64_t
+get_time_nanoseconds_local()
 {
   // This code was unabashedly stolen from gcc/timevar.cc.
   // It returns the Unix epoch with nine decimal places.
 
+  /*  Note:  I am perplexed.  I have been examining the gcc Makefiles and
+      configure.ac files, and I am unable to locate where HAVE_GETTIMEOFDAY
+      is established.  There have been issues compiling on MacOS, where
+      apparently clock_gettime() is not available.  But I don't see exactly
+      how gettimeofday() gets used, instead.  But without the ability to
+      compile on a MacOS system, I am fumbling along as best I can.
+
+      I decided to simply replace clock_gettime() with getttimeofday() when
+      clock_gettime() isn't available, even though gcc/timevar.cc handles
+      the situation differently.
+
+           -- Bob Dubner, 2025-06-11*/
+
   uint64_t retval = 0;
 
 #ifdef HAVE_CLOCK_GETTIME
@@ -2415,8 +2432,9 @@ get_time_nanoseconds()
   clock_gettime (CLOCK_REALTIME, &ts);
   retval = ts.tv_sec * 1000000000 + ts.tv_nsec;
   return retval;
-#endif
-#ifdef HAVE_GETTIMEOFDAY
+//#endif
+//#ifdef HAVE_GETTIMEOFDAY
+#else
   struct timeval tv;
   gettimeofday (&tv, NULL);
   retval = tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
@@ -2427,7 +2445,7 @@ get_time_nanoseconds()
 
 extern "C"
 void
-__gg__clock_gettime(clockid_t clk_id, struct cbl_timespec *tp)
+__gg__clock_gettime(struct cbl_timespec *tp)
   {
   const char *p = getenv("GCOBOL_CURRENT_DATE");
 
@@ -2457,9 +2475,7 @@ __gg__clock_gettime(clockid_t clk_id, struct cbl_timespec *tp)
     }
   else
     {
-    timespec tm;
-    clock_gettime(clk_id, &tm);
-    uint64_t ns = get_time_nanoseconds();
+    uint64_t ns = get_time_nanoseconds_local();
     tp->tv_sec  = ns/1000000000;
     tp->tv_nsec = ns%1000000000;
     }
@@ -2472,7 +2488,7 @@ __gg__get_date_hhmmssff()
   char ach[32];
 
   struct cbl_timespec tv;
-  __gg__clock_gettime(CLOCK_REALTIME, &tv);
+  __gg__clock_gettime(&tv);
 
   struct tm tm;
   localtime_r(&tv.tv_sec, &tm);
@@ -3691,7 +3707,7 @@ compare_88( const char    *list,
     }
   else
     {
-    cmpval = cstrncmp (test, 
+    cmpval = cstrncmp (test,
                       PTRCAST(char, conditional_location),
                       conditional_length);
     if( cmpval == 0 && (int)strlen(test) != conditional_length )
@@ -4573,7 +4589,7 @@ __gg__compare_2(cblc_field_t *left_side,
         }
 
       static size_t right_string_size = MINIMUM_ALLOCATION_SIZE;
-      static char *right_string 
+      static char *right_string
                               = static_cast<char *>(malloc(right_string_size));
 
       right_string = format_for_display_internal(
index 4aa2cffb8035905bdb6feebd8cf7c3a446a40c12..2e338c2596a329ecccdc35420572f03df1700c7e 100644 (file)
@@ -112,7 +112,7 @@ struct cbl_timespec
   long    tv_nsec;   // Nanoseconds.
   } ;
 
-extern "C" void __gg__clock_gettime(clockid_t clk_id, struct cbl_timespec *tp);
+extern "C" void __gg__clock_gettime(struct cbl_timespec *tp);
 
 extern "C" GCOB_FP128 __gg__float128_from_location(
                                         const cblc_field_t *var,