public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4337] modula2: iso library SysClock.mod and wrapclock.cc fixes.
@ 2023-09-29 16:18 Gaius Mulley
  0 siblings, 0 replies; only message in thread
From: Gaius Mulley @ 2023-09-29 16:18 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5f2408712a4e3994ad903c2f72af19c5a473ef5d

commit r14-4337-g5f2408712a4e3994ad903c2f72af19c5a473ef5d
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Fri Sep 29 17:18:16 2023 +0100

    modula2: iso library SysClock.mod and wrapclock.cc fixes.
    
    This patch corrects the C equivalent of m2 LONGINT parameters
    in wrapclock.cc and corrects the SysClock.mod module.
    wrapclock.cc uses a typedef long long int longint_t to match
    m2 LONGINT (rather than unsigned long).  These fixes
    prevent calls to SysClock hanging spinning on an (incorrect)
    large day count from the epoch.
    
    gcc/m2/ChangeLog:
    
            * gm2-compiler/M2Quads.mod (EndBuildFor): Improve
            block comments.
            * gm2-libs-iso/SysClock.mod (ExtractDate): Replace
            testDays with yearOfDays.  New local variable monthOfDays.
    
    libgm2/ChangeLog:
    
            * libm2iso/wrapclock.cc (longint_t): New declaration.
            (GetTimespec): Replace types for sec and nano with
            longint_t.
            (SetTimespec): Replace types for sec and nano with
            longint_t.
    
    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod  |  6 +++---
 gcc/m2/gm2-libs-iso/SysClock.mod | 20 ++++++++++++--------
 libgm2/libm2iso/wrapclock.cc     | 12 +++++++-----
 3 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 95ca15a0b9e..f3a5c05a15a 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -4625,7 +4625,7 @@ BEGIN
       BuildRange (InitForLoopEndRangeCheck (tsym, BySym)) ;  (* --fixme-- pass endpostok.  *)
       IncQuad := NextQuad ;
       (* we have explicitly checked using the above and also
-         this addition can legally overflow if a cardinal type
+         this addition can legitimately overflow if a cardinal type
          is counting down.  The above test will generate a more
          precise error message, so we suppress overflow detection
          here.  *)
@@ -4636,7 +4636,7 @@ BEGIN
       BuildRange (InitForLoopEndRangeCheck (IdSym, BySym)) ;
       IncQuad := NextQuad ;
       (* we have explicitly checked using the above and also
-         this addition can legally overflow if a cardinal type
+         this addition can legitimately overflow if a cardinal type
          is counting down.  The above test will generate a more
          precise error message, so we suppress overflow detection
          here.  *)
@@ -5548,7 +5548,7 @@ END IsReallyPointer ;
 
 
 (*
-   LegalUnboundedParam - returns TRUE if the parameter, Actual, can legally be
+   LegalUnboundedParam - returns TRUE if the parameter, Actual, can legitimately be
                          passed to ProcSym, i, the, Formal, parameter.
 *)
 
diff --git a/gcc/m2/gm2-libs-iso/SysClock.mod b/gcc/m2/gm2-libs-iso/SysClock.mod
index 56d5503a87c..5f2c377fb41 100644
--- a/gcc/m2/gm2-libs-iso/SysClock.mod
+++ b/gcc/m2/gm2-libs-iso/SysClock.mod
@@ -137,7 +137,8 @@ END daysInYear ;
 
 
 (*
-   ExtractDate - extracts the year, month, day from days.
+   ExtractDate - extracts the year, month, day from secs.  days is the
+                 total days since 1970.
 *)
 
 PROCEDURE ExtractDate (days: LONGCARD;
@@ -145,28 +146,29 @@ PROCEDURE ExtractDate (days: LONGCARD;
 VAR
    testMonth,
    testYear : CARDINAL ;
-   testDays : LONGCARD ;
+   monthOfDays,
+   yearOfDays : LONGCARD ;
 BEGIN
    testYear := 1970 ;
    LOOP
-      testDays := daysInYear (31, 12, testYear) ;
-      IF days < testDays
+      yearOfDays := daysInYear (31, 12, testYear) ;
+      IF days < yearOfDays
       THEN
          year := testYear ;
          testMonth := 1 ;
          LOOP
-            testDays := daysInMonth (year, testMonth) ;
-            IF days < testDays
+            monthOfDays := daysInMonth (year, testMonth) ;
+            IF days < monthOfDays
             THEN
                day := VAL (Day, days) + MIN (Day) ;
                month := VAL (Month, testMonth) ;
                RETURN
             END ;
-            DEC (days, testDays) ;
+            DEC (days, monthOfDays) ;
             INC (testMonth)
          END
       ELSE
-         DEC (days, testDays) ;
+         DEC (days, yearOfDays) ;
          INC (testYear)
       END
    END
@@ -218,6 +220,8 @@ BEGIN
                printf ("getclock = %ld\n", sec)
             END ;
             WITH userData DO
+               (* Here we keep dividing sec by max seconds, minutes, hours
+                  to convert sec into total days since epoch.  *)
                second := VAL (Sec, DivMod (sec, MAX (Sec) + 1)) ;
                minute := VAL (Min, DivMod (sec, MAX (Min) + 1)) ;
                hour := VAL (Hour, DivMod (sec, MAX (Hour) + 1)) ;
diff --git a/libgm2/libm2iso/wrapclock.cc b/libgm2/libm2iso/wrapclock.cc
index 1f4ca8c325d..a4d62b7085c 100644
--- a/libgm2/libm2iso/wrapclock.cc
+++ b/libgm2/libm2iso/wrapclock.cc
@@ -75,6 +75,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define NULL (void *)0
 #endif
 
+typedef long long int longint_t;
+
 
 /* GetTimeRealtime performs return gettime (CLOCK_REALTIME, ts).
    gettime returns 0 on success and -1 on failure.  If the underlying
@@ -175,7 +177,7 @@ EXPORT(KillTimespec) (void *ts)
 
 #if defined(HAVE_STRUCT_TIMESPEC)
 extern "C" int
-EXPORT(GetTimespec) (timespec *ts, unsigned long *sec, unsigned long *nano)
+EXPORT(GetTimespec) (timespec *ts, longint_t *sec, longint_t *nano)
 {
 #if defined(HAVE_STRUCT_TIMESPEC)
   *sec = ts->tv_sec;
@@ -188,7 +190,7 @@ EXPORT(GetTimespec) (timespec *ts, unsigned long *sec, unsigned long *nano)
 
 #else
 extern "C" int
-EXPORT(GetTimespec) (void *ts, unsigned long *sec, unsigned long *nano)
+EXPORT(GetTimespec) (void *ts, longint_t *sec, longint_t *nano)
 {
   return 0;
 }
@@ -199,7 +201,7 @@ EXPORT(GetTimespec) (void *ts, unsigned long *sec, unsigned long *nano)
 
 #if defined(HAVE_STRUCT_TIMESPEC)
 extern "C" int
-EXPORT(SetTimespec) (timespec *ts, unsigned long sec, unsigned long nano)
+EXPORT(SetTimespec) (timespec *ts, longint_t sec, longint_t nano)
 {
 #if defined(HAVE_STRUCT_TIMESPEC)
   ts->tv_sec = sec;
@@ -213,13 +215,13 @@ EXPORT(SetTimespec) (timespec *ts, unsigned long sec, unsigned long nano)
 #else
 
 extern "C" int
-EXPORT(SetTimespec) (void *ts, unsigned long sec, unsigned long nano)
+EXPORT(SetTimespec) (void *ts, longint_t sec, longint_t nano)
 {
   return 0;
 }
 #endif
 
-extern "C" long int
+extern "C" longint_t
 EXPORT(timezone) (void)
 {
 #if defined(HAVE_STRUCT_TIMESPEC)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-29 16:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-29 16:18 [gcc r14-4337] modula2: iso library SysClock.mod and wrapclock.cc fixes Gaius Mulley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).