Patch - Add restrict to time.h

Joel Sherrill joel.sherrill@oarcorp.com
Sun Nov 24 17:46:00 GMT 2013


Hi

This should be the next to the last patch in the Google Code-In
add restrict keyword series. wchar.h should be the last.

This patch has one oddity -- strftime and wcsftime are built
from the same source as best I can tell. And there are multiple
versions of them in the same file to support different build
options.

Please review this one a little closer than the others.

I hope this version is OK to commit but won't be surprised
if there are comments. I tried to review it carefully but...

Thanks.

2013-11-24  Sahil Patnayakuni <sahil.patnayakuni@gmail.com>

        * libc/include/time.h (time): Add restrict keyword.
        * libc/include/wchar.h (wcsftime): Add restrict keyword.
        * libc/time/asctime_r.c (asctime_r): Same.
        * libc/time/gmtime_r.c (gmtime_r): Same.
        * libc/time/lcltime_r.c (lcltime_r): Same.
        * libc/time/strftime.c (strftime): Same.
        * libc/time/strptime.c (strptime): Same.
        * libc/sys/linux/linuxthreads/timer_create.c (timer_create): Same.
        * libc/sys/linux/linuxthreads/timer_settime.c (timer_settime):
Same.


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill@OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985
-------------- next part --------------
? .TODO.swp
? TODO
? cscope.out
? libc/libc.info
? libm/libm.info
Index: libc/include/time.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/time.h,v
retrieving revision 1.22
diff -u -r1.22 time.h
--- libc/include/time.h	1 Nov 2012 11:51:11 -0000	1.22
+++ libc/include/time.h	24 Nov 2013 17:40:30 -0000
@@ -51,12 +51,17 @@
 struct tm *_EXFUN(gmtime,   (const time_t *_timer));
 struct tm *_EXFUN(localtime,(const time_t *_timer));
 #endif
-size_t	   _EXFUN(strftime, (char *_s, size_t _maxsize, const char *_fmt, const struct tm *_t));
+size_t	   _EXFUN(strftime, (char *__restrict _s,
+			     size_t _maxsize, const char *__restrict _fmt,
+			     const struct tm *__restrict _t));
 
-char	  *_EXFUN(asctime_r,	(const struct tm *, char *));
+char	  *_EXFUN(asctime_r,	(const struct tm *__restrict,
+				 char *__restrict));
 char	  *_EXFUN(ctime_r,	(const time_t *, char *));
-struct tm *_EXFUN(gmtime_r,	(const time_t *, struct tm *));
-struct tm *_EXFUN(localtime_r,	(const time_t *, struct tm *));
+struct tm *_EXFUN(gmtime_r,	(const time_t *__restrict,
+				 struct tm *__restrict));
+struct tm *_EXFUN(localtime_r,	(const time_t *__restrict,
+				 struct tm *__restrict));
 
 _END_STD_C
 
@@ -65,7 +70,9 @@
 #endif
 
 #ifndef __STRICT_ANSI__
-char      *_EXFUN(strptime,     (const char *, const char *, struct tm *));
+char      *_EXFUN(strptime,     (const char *__restrict,
+				 const char *__restrict,
+				 struct tm *__restrict));
 _VOID      _EXFUN(tzset,	(_VOID));
 _VOID      _EXFUN(_tzset_r,	(struct _reent *));
 
@@ -150,7 +157,9 @@
 /* Create a Per-Process Timer, P1003.1b-1993, p. 264 */
 
 int _EXFUN(timer_create,
-  (clockid_t clock_id, struct sigevent *evp, timer_t *timerid));
+  	(clockid_t clock_id,
+ 	struct sigevent *__restrict evp,
+	timer_t *__restrict timerid));
 
 /* Delete a Per_process Timer, P1003.1b-1993, p. 266 */
 
@@ -159,8 +168,9 @@
 /* Per-Process Timers, P1003.1b-1993, p. 267 */
 
 int _EXFUN(timer_settime,
-  (timer_t timerid, int flags, const struct itimerspec *value,
-   struct itimerspec *ovalue));
+	(timer_t timerid, int flags,
+	const struct itimerspec *__restrict value,
+	struct itimerspec *__restrict ovalue));
 int _EXFUN(timer_gettime, (timer_t timerid, struct itimerspec *value));
 int _EXFUN(timer_getoverrun, (timer_t timerid));
 
Index: libc/include/wchar.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/wchar.h,v
retrieving revision 1.31
diff -u -r1.31 wchar.h
--- libc/include/wchar.h	26 Jun 2013 21:34:16 -0000	1.31
+++ libc/include/wchar.h	24 Nov 2013 17:40:30 -0000
@@ -79,7 +79,8 @@
 wchar_t	*_EXFUN(wcsdup, (const wchar_t *));
 wchar_t	*_EXFUN(_wcsdup_r, (struct _reent *, const wchar_t * ));
 size_t	_EXFUN(wcscspn, (const wchar_t *, const wchar_t *));
-size_t  _EXFUN(wcsftime, (wchar_t *, size_t, const wchar_t *, const struct tm *));
+size_t  _EXFUN(wcsftime, (wchar_t *__restrict, size_t,
+               const wchar_t *__restrict, const struct tm *__restrict));
 size_t	_EXFUN(wcslcat, (wchar_t *, const wchar_t *, size_t));
 size_t	_EXFUN(wcslcpy, (wchar_t *, const wchar_t *, size_t));
 size_t	_EXFUN(wcslen, (const wchar_t *));
Index: libc/sys/linux/linuxthreads/timer_create.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/linux/linuxthreads/timer_create.c,v
retrieving revision 1.1
diff -u -r1.1 timer_create.c
--- libc/sys/linux/linuxthreads/timer_create.c	28 May 2003 22:04:38 -0000	1.1
+++ libc/sys/linux/linuxthreads/timer_create.c	24 Nov 2013 17:40:30 -0000
@@ -30,8 +30,8 @@
 int
 timer_create (clock_id, evp, timerid)
      clockid_t clock_id;
-     struct sigevent *evp;
-     timer_t *timerid;
+     struct sigevent *__restrict evp;
+     timer_t *__restrict timerid;
 {
   int retval = -1;
   struct timer_node *newtimer = NULL;
Index: libc/sys/linux/linuxthreads/timer_settime.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/linux/linuxthreads/timer_settime.c,v
retrieving revision 1.1
diff -u -r1.1 timer_settime.c
--- libc/sys/linux/linuxthreads/timer_settime.c	28 May 2003 22:04:38 -0000	1.1
+++ libc/sys/linux/linuxthreads/timer_settime.c	24 Nov 2013 17:40:30 -0000
@@ -29,8 +29,8 @@
 timer_settime (timerid, flags, value, ovalue)
      timer_t timerid;
      int flags;
-     const struct itimerspec *value;
-     struct itimerspec *ovalue;
+     const struct itimerspec *__restrict value;
+     struct itimerspec *__restrict ovalue;
 {
   struct timer_node *timer;
   struct thread_node *thread = NULL;
Index: libc/time/asctime_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/time/asctime_r.c,v
retrieving revision 1.3
diff -u -r1.3 asctime_r.c
--- libc/time/asctime_r.c	14 Jun 2011 14:31:59 -0000	1.3
+++ libc/time/asctime_r.c	24 Nov 2013 17:40:30 -0000
@@ -7,8 +7,8 @@
 
 char *
 _DEFUN (asctime_r, (tim_p, result),
-	_CONST struct tm *tim_p _AND
-	char *result)
+	_CONST struct tm *__restrict tim_p _AND
+	char *__restrict result)
 {
   static _CONST char day_name[7][3] = {
 	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
Index: libc/time/gmtime_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/time/gmtime_r.c,v
retrieving revision 1.2
diff -u -r1.2 gmtime_r.c
--- libc/time/gmtime_r.c	17 Apr 2002 21:23:31 -0000	1.2
+++ libc/time/gmtime_r.c	24 Nov 2013 17:40:30 -0000
@@ -7,8 +7,8 @@
 
 struct tm *
 _DEFUN (gmtime_r, (tim_p, res),
-	_CONST time_t * tim_p _AND
-	struct tm *res)
+	_CONST time_t *__restrict tim_p _AND
+	struct tm *__restrict res)
 {
   return (_mktm_r (tim_p, res, 1));
 }
Index: libc/time/lcltime_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/time/lcltime_r.c,v
retrieving revision 1.2
diff -u -r1.2 lcltime_r.c
--- libc/time/lcltime_r.c	17 Apr 2002 21:23:31 -0000	1.2
+++ libc/time/lcltime_r.c	24 Nov 2013 17:40:30 -0000
@@ -11,8 +11,8 @@
 
 struct tm *
 _DEFUN (localtime_r, (tim_p, res),
-	_CONST time_t * tim_p _AND
-	struct tm *res)
+	_CONST time_t *__restrict tim_p _AND
+	struct tm *__restrict res)
 {
   return _mktm_r (tim_p, res, 0);
 }
Index: libc/time/strftime.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/time/strftime.c,v
retrieving revision 1.19
diff -u -r1.19 strftime.c
--- libc/time/strftime.c	10 Aug 2012 15:21:57 -0000	1.19
+++ libc/time/strftime.c	24 Nov 2013 17:40:30 -0000
@@ -24,8 +24,9 @@
 
 ANSI_SYNOPSIS
 	#include <time.h>
-	size_t strftime(char *<[s]>, size_t <[maxsize]>,
-			const char *<[format]>, const struct tm *<[timp]>);
+	size_t strftime(char *restrict<[s]>, size_t <[maxsize]>,
+			const char *restrict<[format]>,
+                        const struct tm *restrict<[timp]>);
 
 TRAD_SYNOPSIS
 	#include <time.h>
@@ -662,10 +663,10 @@
 
 size_t
 _DEFUN (strftime, (s, maxsize, format, tim_p),
-	CHAR *s _AND
+	CHAR *__restrict s _AND
 	size_t maxsize _AND
-	_CONST CHAR *format _AND
-	_CONST struct tm *tim_p)
+	_CONST CHAR *__restrict format _AND
+	_CONST struct tm *__restrict tim_p)
 {
   era_info_t *era_info = NULL;
   alt_digits_t *alt_digits = NULL;
@@ -686,10 +687,10 @@
 
 size_t
 _DEFUN (strftime, (s, maxsize, format, tim_p),
-	CHAR *s _AND
+	CHAR *__restrict s _AND
 	size_t maxsize _AND
-	_CONST CHAR *format _AND
-	_CONST struct tm *tim_p)
+	_CONST CHAR *__restrict format _AND
+	_CONST struct tm *__restrict tim_p)
 #endif /* !_WANT_C99_TIME_FORMATS */
 {
   size_t count = 0;
Index: libc/time/strptime.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/time/strptime.c,v
retrieving revision 1.9
diff -u -r1.9 strptime.c
--- libc/time/strptime.c	8 Aug 2012 11:04:18 -0000	1.9
+++ libc/time/strptime.c	24 Nov 2013 17:40:30 -0000
@@ -153,9 +153,9 @@
 char *
 //strptime (const char *buf, const char *format, struct tm *timeptr)
 _DEFUN (strptime, (buf, format, timeptr),
-	_CONST char *buf _AND
-	_CONST char *format _AND
-	struct tm *timeptr)
+	_CONST char *__restrict buf _AND
+	_CONST char *__restrict format _AND
+	struct tm *__restrict timeptr)
 {
     char c;
     int ymd = 0;


More information about the Newlib mailing list