]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
modula2: iso library SysClock.mod and wrapclock.cc fixes.
authorGaius Mulley <gaiusmod2@gmail.com>
Fri, 29 Sep 2023 16:18:16 +0000 (17:18 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Fri, 29 Sep 2023 16:18:16 +0000 (17:18 +0100)
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>
gcc/m2/gm2-compiler/M2Quads.mod
gcc/m2/gm2-libs-iso/SysClock.mod
libgm2/libm2iso/wrapclock.cc

index 95ca15a0b9e5a565ca494846d7bf4bfaa3d0d64c..f3a5c05a15a8e319fb53efd6bc412507ad419f51 100644 (file)
@@ -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.
 *)
 
index 56d5503a87c584fdf2b035bc933d86ea045fda61..5f2c377fb4161111ac76cde423ff9ae4769ee2e3 100644 (file)
@@ -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)) ;
index 1f4ca8c325d084f7414e4eb14b6cd0c3dfa88100..a4d62b7085c9c4b469d00da1594bb95f680e0c2f 100644 (file)
@@ -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)