Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Oct 2001 17:55:35 -0700 (PDT)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        arch@FreeBSD.ORG
Subject:   need review make time_t type agnostic changes
Message-ID:  <200110280055.f9S0tZ184290@apollo.backplane.com>

next in thread | raw e-mail | index | archive | help
    Here is a diff for review to remove int truncation of time in make.
    There is still an issue in that the archive format can only handle 11
    useful digits, so its only good for 10^11 seconds, but that's
    the way it goes.  I didn't even know make *tried* to read the
    table of contents for an archive!  Must be some weird mis-feature.

    In anycase, make needed to be fixed anyway since half the routines
    cast time_t to an int, which breaks any conceivable notion of the
    proper handling of time_t.

						-Matt

Index: arch.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/arch.c,v
retrieving revision 1.15.2.1
diff -u -r1.15.2.1 arch.c
--- arch.c	2001/02/13 03:13:57	1.15.2.1
+++ arch.c	2001/10/28 00:48:29
@@ -941,7 +941,7 @@
 			  &arh, "r+");
     efree(p1);
     efree(p2);
-    snprintf(arh.ar_date, sizeof(arh.ar_date), "%-12ld", (long) now);
+    snprintf(arh.ar_date, sizeof(arh.ar_date), "%-12qd", (quad_t) now);
 
     if (arch != NULL) {
 	(void)fwrite ((char *)&arh, sizeof (struct ar_hdr), 1, arch);
@@ -974,7 +974,7 @@
     struct utimbuf  times;	/* Times for utime() call */
 
     arch = ArchFindMember (gn->path, RANLIBMAG, &arh, "r+");
-    snprintf(arh.ar_date, sizeof(arh.ar_date), "%-12ld", (long) now);
+    snprintf(arh.ar_date, sizeof(arh.ar_date), "%-12qd", (quad_t) now);
 
     if (arch != NULL) {
 	(void)fwrite ((char *)&arh, sizeof (struct ar_hdr), 1, arch);
@@ -1000,12 +1000,12 @@
  *
  *-----------------------------------------------------------------------
  */
-int
+time_t
 Arch_MTime (gn)
     GNode	  *gn;	      /* Node describing archive member */
 {
     struct ar_hdr *arhPtr;    /* Header of desired member */
-    int		  modTime;    /* Modification time as an integer */
+    time_t	  modTime;    /* Modification time as an integer */
     char *p1, *p2;
 
     arhPtr = ArchStatMember (Var_Value (ARCHIVE, gn, &p1),
@@ -1015,7 +1015,7 @@
     efree(p2);
 
     if (arhPtr != NULL) {
-	modTime = (int) strtol(arhPtr->ar_date, NULL, 10);
+	modTime = (time_t) strtoq(arhPtr->ar_date, NULL, 10);
     } else {
 	modTime = 0;
     }
@@ -1038,7 +1038,7 @@
  *
  *-----------------------------------------------------------------------
  */
-int
+time_t
 Arch_MemMTime (gn)
     GNode   	  *gn;
 {
@@ -1176,12 +1176,12 @@
     } else {
 #ifdef RANLIBMAG
 	struct ar_hdr  	*arhPtr;    /* Header for __.SYMDEF */
-	int 	  	modTimeTOC; /* The table-of-contents's mod time */
+	time_t 	  	modTimeTOC; /* The table-of-contents's mod time */
 
 	arhPtr = ArchStatMember (gn->path, RANLIBMAG, FALSE);
 
 	if (arhPtr != NULL) {
-	    modTimeTOC = (int) strtol(arhPtr->ar_date, NULL, 10);
+	    modTimeTOC = (time_t)strtoq(arhPtr->ar_date, NULL, 10);
 
 	    if (DEBUG(ARCH) || DEBUG(MAKE)) {
 		printf("%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC));
Index: dir.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/dir.c,v
retrieving revision 1.10.2.1
diff -u -r1.10.2.1 dir.c
--- dir.c	2001/02/13 03:13:57	1.10.2.1
+++ dir.c	2001/10/28 00:33:12
@@ -858,7 +858,7 @@
 		}
 		entry = Hash_CreateEntry(&mtimes, (char *) file,
 					 (Boolean *)NULL);
-		Hash_SetValue(entry, (long)stb.st_mtime);
+		Hash_SetValue_Time(entry, stb.st_mtime);
 		nearmisses += 1;
 		return (file);
 	    } else {
@@ -936,7 +936,7 @@
 	    printf("Caching %s for %s\n", Targ_FmtTime(stb.st_mtime),
 		    name);
 	}
-	Hash_SetValue(entry, (long)stb.st_mtime);
+	Hash_SetValue_Time(entry, stb.st_mtime);
 	return (estrdup (name));
     } else {
 	if (DEBUG(DIR)) {
@@ -962,7 +962,7 @@
  *	found one for it, the full name is placed in the path slot.
  *-----------------------------------------------------------------------
  */
-int
+time_t
 Dir_MTime (gn)
     GNode         *gn;	      /* the file whose modification time is
 			       * desired */
@@ -992,9 +992,9 @@
 	 */
 	if (DEBUG(DIR)) {
 	    printf("Using cached time %s for %s\n",
-		    Targ_FmtTime((time_t)(long)Hash_GetValue(entry)), fullName);
+		    Targ_FmtTime(Hash_GetValue_Time(entry)), fullName);
 	}
-	stb.st_mtime = (time_t)(long)Hash_GetValue(entry);
+	stb.st_mtime = Hash_GetValue_Time(entry);
 	Hash_DeleteEntry(&mtimes, entry);
     } else if (stat (fullName, &stb) < 0) {
 	if (gn->type & OP_MEMBER) {
Index: dir.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/dir.h,v
retrieving revision 1.7
diff -u -r1.7 dir.h
--- dir.h	1999/08/28 01:03:29	1.7
+++ dir.h	2001/10/28 00:33:26
@@ -58,7 +58,7 @@
 Boolean Dir_HasWildcards __P((char *));
 void Dir_Expand __P((char *, Lst, Lst));
 char *Dir_FindFile __P((char *, Lst));
-int Dir_MTime __P((GNode *));
+time_t Dir_MTime __P((GNode *));
 void Dir_AddDir __P((Lst, char *));
 char *Dir_MakeFlags __P((char *, Lst));
 void Dir_ClearPath __P((Lst));
Index: hash.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/hash.c,v
retrieving revision 1.9
diff -u -r1.9 hash.c
--- hash.c	1999/09/11 13:08:01	1.9
+++ hash.c	2001/10/28 00:29:55
@@ -250,7 +250,7 @@
 	hp = &t->bucketPtr[h & t->mask];
 	e->next = *hp;
 	*hp = e;
-	e->clientData = NULL;
+	bzero(&e->u, sizeof(e->u));
 	e->namehash = h;
 	(void) strcpy(e->name, p);
 	t->numEntries++;
Index: hash.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/hash.h,v
retrieving revision 1.8
diff -u -r1.8 hash.h
--- hash.h	1999/08/28 01:03:30	1.8
+++ hash.h	2001/10/28 00:27:43
@@ -56,8 +56,11 @@
     struct Hash_Entry *next;		/* Used to link together all the
     					 * entries associated with the same
 					 * bucket. */
-    ClientData	      clientData;	/* Arbitrary piece of data associated
+    union {
+	ClientData	clientData;	/* Arbitrary piece of data associated
     					 * with key. */
+	time_t		timeData;	/* type agnostic time_t */
+    } u;
     unsigned	      namehash;		/* hash value of key */
     char	      name[1];		/* key string */
 } Hash_Entry;
@@ -90,7 +93,8 @@
  *     Hash_Entry *h;
  */
 
-#define Hash_GetValue(h) ((h)->clientData)
+#define Hash_GetValue(h) ((h)->u.clientData)
+#define Hash_GetValue_Time(h) ((h)->u.timeData)
 
 /*
  * Hash_SetValue(h, val);
@@ -98,7 +102,8 @@
  *     char *val;
  */
 
-#define Hash_SetValue(h, val) ((h)->clientData = (ClientData) (val))
+#define Hash_SetValue(h, val) ((h)->u.clientData = (ClientData) (val))
+#define Hash_SetValue_Time(h, val) ((h)->u.timeData = (val))
 
 /*
  * Hash_Size(n) returns the number of words in an object of n bytes
Index: make.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/make.h,v
retrieving revision 1.12.2.2
diff -u -r1.12.2.2 make.h
--- make.h	2001/02/13 03:13:58	1.12.2.2
+++ make.h	2001/10/28 00:31:05
@@ -144,8 +144,8 @@
 				 * made */
     int             unmade;    	/* The number of unmade children */
 
-    int             mtime;     	/* Its modification time */
-    int        	    cmtime;    	/* The modification time of its youngest
+    time_t          mtime;     	/* Its modification time */
+    time_t    	    cmtime;    	/* The modification time of its youngest
 				 * child */
 
     Lst     	    iParents;  	/* Links to parents for which this is an
Index: nonints.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/nonints.h,v
retrieving revision 1.8
diff -u -r1.8 nonints.h
--- nonints.h	1999/08/28 01:03:35	1.8
+++ nonints.h	2001/10/28 00:48:33
@@ -43,8 +43,8 @@
 ReturnStatus Arch_ParseArchive __P((char **, Lst, GNode *));
 void Arch_Touch __P((GNode *));
 void Arch_TouchLib __P((GNode *));
-int Arch_MTime __P((GNode *));
-int Arch_MemMTime __P((GNode *));
+time_t Arch_MTime __P((GNode *));
+time_t Arch_MemMTime __P((GNode *));
 void Arch_FindLib __P((GNode *, Lst));
 Boolean Arch_LibOODate __P((GNode *));
 void Arch_Init __P((void));

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200110280055.f9S0tZ184290>