PATCH - Add C99 restrict to stdlib

Joel Sherrill joel.sherrill@oarcorp.com
Fri Nov 15 18:51:00 GMT 2013


Hi

Attached is a patch which adds the restrict keyword
as required to stdlib.h methods. An attempt was made
to add them everywhere. I only built the documentation
and sparc-rtems.

OK to apply?

2013-11-15  Sahil Patnayakuni  <sahilp@oarcorp.com>

	* libc/include/stdlib.h, libc/stdlib/mbstowcs.c,
	libc/stdlib/mbstowcs_r.c, libc/stdlib/mbtowc.c,
	libc/stdlib/mbtowc_r.c, libc/stdlib/strtod.c,
	libc/stdlib/strtol.c, libc/stdlib/strtold.c,
	libc/stdlib/strtoll.c, libc/stdlib/strtoll_r.c,
	libc/stdlib/strtoul.c, libc/stdlib/strtoull.c,
	libc/stdlib/strtoull_r.c, libc/stdlib/wcstombs.c,
	libc/stdlib/wcstombs_r.c: Add restrict keyword.


-- 
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 --------------
Index: newlib/libc/include/stdlib.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdlib.h,v
retrieving revision 1.45
diff -u -r1.45 stdlib.h
--- newlib/libc/include/stdlib.h	8 Sep 2013 07:11:33 -0000	1.45
+++ newlib/libc/include/stdlib.h	15 Nov 2013 18:23:34 -0000
@@ -94,14 +94,14 @@
 _PTR	_EXFUN_NOTHROW(malloc,(size_t __size));
 int	_EXFUN(mblen,(const char *, size_t));
 int	_EXFUN(_mblen_r,(struct _reent *, const char *, size_t, _mbstate_t *));
-int	_EXFUN(mbtowc,(wchar_t *, const char *, size_t));
-int	_EXFUN(_mbtowc_r,(struct _reent *, wchar_t *, const char *, size_t, _mbstate_t *));
+int	_EXFUN(mbtowc,(wchar_t *__restrict, const char *__restrict, size_t));
+int	_EXFUN(_mbtowc_r,(struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *));
 int	_EXFUN(wctomb,(char *, wchar_t));
 int	_EXFUN(_wctomb_r,(struct _reent *, char *, wchar_t, _mbstate_t *));
-size_t	_EXFUN(mbstowcs,(wchar_t *, const char *, size_t));
-size_t	_EXFUN(_mbstowcs_r,(struct _reent *, wchar_t *, const char *, size_t, _mbstate_t *));
-size_t	_EXFUN(wcstombs,(char *, const wchar_t *, size_t));
-size_t	_EXFUN(_wcstombs_r,(struct _reent *, char *, const wchar_t *, size_t, _mbstate_t *));
+size_t	_EXFUN(mbstowcs,(wchar_t *__restrict, const char *__restrict, size_t));
+size_t	_EXFUN(_mbstowcs_r,(struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *));
+size_t	_EXFUN(wcstombs,(char *__restrict, const wchar_t *__restrict, size_t));
+size_t	_EXFUN(_wcstombs_r,(struct _reent *, char *__restrict, const wchar_t *__restrict, size_t, _mbstate_t *));
 #ifndef __STRICT_ANSI__
 #ifndef _REENT_ONLY
 char *	_EXFUN(mkdtemp,(char *));
@@ -125,10 +125,10 @@
 _PTR	_EXFUN(reallocf,(_PTR __r, size_t __size));
 #endif
 _VOID	_EXFUN(srand,(unsigned __seed));
-double	_EXFUN(strtod,(const char *__n, char **__end_PTR));
-double	_EXFUN(_strtod_r,(struct _reent *,const char *__n, char **__end_PTR));
+double	_EXFUN(strtod,(const char *__restrict __n, char **__restrict __end_PTR));
+double	_EXFUN(_strtod_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR));
 #if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
-float	_EXFUN(strtof,(const char *__n, char **__end_PTR));
+float	_EXFUN(strtof,(const char *__restrict __n, char **__restrict __end_PTR));
 #endif
 #ifndef __STRICT_ANSI__
 /* the following strtodf interface is deprecated...use strtof instead */
@@ -136,10 +136,10 @@
 #  define strtodf strtof
 # endif
 #endif
-long	_EXFUN(strtol,(const char *__n, char **__end_PTR, int __base));
-long	_EXFUN(_strtol_r,(struct _reent *,const char *__n, char **__end_PTR, int __base));
-unsigned long _EXFUN(strtoul,(const char *__n, char **__end_PTR, int __base));
-unsigned long _EXFUN(_strtoul_r,(struct _reent *,const char *__n, char **__end_PTR, int __base));
+long	_EXFUN(strtol,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
+long	_EXFUN(_strtol_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base));
+unsigned long _EXFUN(strtoul,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
+unsigned long _EXFUN(_strtoul_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base));
 
 int	_EXFUN(system,(const char *__string));
 
@@ -192,16 +192,16 @@
 lldiv_t	_EXFUN(lldiv,(long long __numer, long long __denom));
 #endif /* ! __STRICT_ANSI__ */
 #if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
-long long _EXFUN(strtoll,(const char *__n, char **__end_PTR, int __base));
+long long _EXFUN(strtoll,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
 #endif
 #ifndef __STRICT_ANSI__
-long long _EXFUN(_strtoll_r,(struct _reent *, const char *__n, char **__end_PTR, int __base));
+long long _EXFUN(_strtoll_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base));
 #endif /* ! __STRICT_ANSI__ */
 #if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
-unsigned long long _EXFUN(strtoull,(const char *__n, char **__end_PTR, int __base));
+unsigned long long _EXFUN(strtoull,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
 #endif
 #ifndef __STRICT_ANSI__
-unsigned long long _EXFUN(_strtoull_r,(struct _reent *, const char *__n, char **__end_PTR, int __base));
+unsigned long long _EXFUN(_strtoull_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base));
 
 #ifndef __CYGWIN__
 _VOID	_EXFUN(cfree,(_PTR));
@@ -230,7 +230,7 @@
 /* On platforms where long double equals double.  */
 #ifdef _LDBL_EQ_DBL
 #if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
-extern long double strtold (const char *, char **);
+extern long double strtold (const char *__restrict, char **__restrict);
 #endif
 extern long double wcstold (const wchar_t *, wchar_t **);
 #endif /* _LDBL_EQ_DBL */
Index: newlib/libc/stdlib/mbstowcs.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/mbstowcs.c,v
retrieving revision 1.4
diff -u -r1.4 mbstowcs.c
--- newlib/libc/stdlib/mbstowcs.c	23 Apr 2004 21:44:22 -0000	1.4
+++ newlib/libc/stdlib/mbstowcs.c	15 Nov 2013 18:23:34 -0000
@@ -7,7 +7,7 @@
 
 ANSI_SYNOPSIS
 	#include <stdlib.h>
-	int mbstowcs(wchar_t *<[pwc]>, const char *<[s]>, size_t <[n]>);
+	int mbstowcs(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>);
 
 TRAD_SYNOPSIS
 	#include <stdlib.h>
@@ -55,8 +55,8 @@
 
 size_t
 _DEFUN (mbstowcs, (pwcs, s, n),
-        wchar_t *pwcs _AND
-        const char *s _AND
+        wchar_t *__restrict pwcs _AND
+        const char *__restrict s _AND
         size_t n)
 {
 #ifdef _MB_CAPABLE
Index: newlib/libc/stdlib/mbstowcs_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/mbstowcs_r.c,v
retrieving revision 1.5
diff -u -r1.5 mbstowcs_r.c
--- newlib/libc/stdlib/mbstowcs_r.c	18 Nov 2009 09:49:57 -0000	1.5
+++ newlib/libc/stdlib/mbstowcs_r.c	15 Nov 2013 18:23:34 -0000
@@ -5,8 +5,8 @@
 size_t
 _DEFUN (_mbstowcs_r, (reent, pwcs, s, n, state),
         struct _reent *r    _AND         
-        wchar_t       *pwcs _AND
-        const char    *s    _AND
+        wchar_t       *__restrict pwcs _AND
+        const char    *__restrict s    _AND
         size_t         n    _AND
         mbstate_t     *state)
 {
Index: newlib/libc/stdlib/mbtowc.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/mbtowc.c,v
retrieving revision 1.7
diff -u -r1.7 mbtowc.c
--- newlib/libc/stdlib/mbtowc.c	29 Apr 2013 21:06:23 -0000	1.7
+++ newlib/libc/stdlib/mbtowc.c	15 Nov 2013 18:23:34 -0000
@@ -7,7 +7,7 @@
 
 ANSI_SYNOPSIS
 	#include <stdlib.h>
-	int mbtowc(wchar_t *<[pwc]>, const char *<[s]>, size_t <[n]>);
+	int mbtowc(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>);
 
 TRAD_SYNOPSIS
 	#include <stdlib.h>
@@ -58,8 +58,8 @@
 
 int
 _DEFUN (mbtowc, (pwc, s, n),
-        wchar_t *pwc _AND
-        const char *s _AND
+        wchar_t *__restrict pwc _AND
+        const char *__restrict s _AND
         size_t n)
 {
 #ifdef _MB_CAPABLE
Index: newlib/libc/stdlib/mbtowc_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/mbtowc_r.c,v
retrieving revision 1.21
diff -u -r1.21 mbtowc_r.c
--- newlib/libc/stdlib/mbtowc_r.c	8 Aug 2012 11:04:18 -0000	1.21
+++ newlib/libc/stdlib/mbtowc_r.c	15 Nov 2013 18:23:34 -0000
@@ -19,8 +19,8 @@
 int
 _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
         struct _reent *r   _AND
-        wchar_t       *pwc _AND 
-        const char    *s   _AND        
+        wchar_t       *__restrict pwc _AND 
+        const char    *__restrict s   _AND        
         size_t         n   _AND
         mbstate_t      *state)
 {
Index: newlib/libc/stdlib/strtod.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/strtod.c,v
retrieving revision 1.21
diff -u -r1.21 strtod.c
--- newlib/libc/stdlib/strtod.c	10 Jun 2013 15:27:43 -0000	1.21
+++ newlib/libc/stdlib/strtod.c	15 Nov 2013 18:23:34 -0000
@@ -11,11 +11,11 @@
 
 ANSI_SYNOPSIS
         #include <stdlib.h>
-        double strtod(const char *<[str]>, char **<[tail]>);
-        float strtof(const char *<[str]>, char **<[tail]>);
+        double strtod(const char *restrict <[str]>, char **restrict <[tail]>);
+        float strtof(const char *restrict <[str]>, char **restrict <[tail]>);
 
         double _strtod_r(void *<[reent]>,
-                         const char *<[str]>, char **<[tail]>);
+                         const char *restrict <[str]>, char **restrict <[tail]>);
 
 TRAD_SYNOPSIS
         #include <stdlib.h>
@@ -236,8 +236,8 @@
 double
 _DEFUN (_strtod_r, (ptr, s00, se),
 	struct _reent *ptr _AND
-	_CONST char *s00 _AND
-	char **se)
+	_CONST char *__restrict s00 _AND
+	char **__restrict se)
 {
 #ifdef Avoid_Underflow
 	int scale;
@@ -1255,15 +1255,15 @@
 
 double
 _DEFUN (strtod, (s00, se),
-	_CONST char *s00 _AND char **se)
+	_CONST char *__restrict s00 _AND char **__restrict se)
 {
   return _strtod_r (_REENT, s00, se);
 }
 
 float
 _DEFUN (strtof, (s00, se),
-	_CONST char *s00 _AND
-	char **se)
+	_CONST char *__restrict s00 _AND
+	char **__restrict se)
 {
   double retval = _strtod_r (_REENT, s00, se);
   if (isnan (retval))
Index: newlib/libc/stdlib/strtol.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/strtol.c,v
retrieving revision 1.3
diff -u -r1.3 strtol.c
--- newlib/libc/stdlib/strtol.c	27 Oct 2010 19:06:10 -0000	1.3
+++ newlib/libc/stdlib/strtol.c	15 Nov 2013 18:23:34 -0000
@@ -9,10 +9,10 @@
 
 ANSI_SYNOPSIS
 	#include <stdlib.h>
-        long strtol(const char *<[s]>, char **<[ptr]>,int <[base]>);
+        long strtol(const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>);
 
         long _strtol_r(void *<[reent]>, 
-                       const char *<[s]>, char **<[ptr]>,int <[base]>);
+                       const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>);
 
 TRAD_SYNOPSIS
 	#include <stdlib.h>
@@ -133,8 +133,8 @@
 long
 _DEFUN (_strtol_r, (rptr, nptr, endptr, base),
 	struct _reent *rptr _AND
-	_CONST char *nptr _AND
-	char **endptr _AND
+	_CONST char *__restrict nptr _AND
+	char **__restrict endptr _AND
 	int base)
 {
 	register const unsigned char *s = (const unsigned char *)nptr;
@@ -216,8 +216,8 @@
 
 long
 _DEFUN (strtol, (s, ptr, base),
-	_CONST char *s _AND
-	char **ptr _AND
+	_CONST char *__restrict s _AND
+	char **__restrict ptr _AND
 	int base)
 {
 	return _strtol_r (_REENT, s, ptr, base);
Index: newlib/libc/stdlib/strtold.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/strtold.c,v
retrieving revision 1.2
diff -u -r1.2 strtold.c
--- newlib/libc/stdlib/strtold.c	17 Apr 2009 22:15:43 -0000	1.2
+++ newlib/libc/stdlib/strtold.c	15 Nov 2013 18:23:34 -0000
@@ -34,7 +34,7 @@
 /* On platforms where long double is as wide as double.  */
 #ifdef _LDBL_EQ_DBL
 long double
-strtold (const char *s00, char **se)
+strtold (const char *__restrict s00, char **__restrict se)
 {
   return strtod(s00, se);
 }
Index: newlib/libc/stdlib/strtoll.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/strtoll.c,v
retrieving revision 1.3
diff -u -r1.3 strtoll.c
--- newlib/libc/stdlib/strtoll.c	6 Jul 2007 20:03:28 -0000	1.3
+++ newlib/libc/stdlib/strtoll.c	15 Nov 2013 18:23:34 -0000
@@ -9,10 +9,10 @@
 
 ANSI_SYNOPSIS
 	#include <stdlib.h>
-        long long strtoll(const char *<[s]>, char **<[ptr]>,int <[base]>);
+        long long strtoll(const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>);
 
         long long _strtoll_r(void *<[reent]>, 
-                       const char *<[s]>, char **<[ptr]>,int <[base]>);
+                       const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>);
 
 TRAD_SYNOPSIS
 	#include <stdlib.h>
@@ -128,8 +128,8 @@
 
 long long
 _DEFUN (strtoll, (s, ptr, base),
-	_CONST char *s _AND
-	char **ptr _AND
+	_CONST char *__restrict s _AND
+	char **__restrict ptr _AND
 	int base)
 {
 	return _strtoll_r (_REENT, s, ptr, base);
Index: newlib/libc/stdlib/strtoll_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/strtoll_r.c,v
retrieving revision 1.3
diff -u -r1.3 strtoll_r.c
--- newlib/libc/stdlib/strtoll_r.c	27 Oct 2010 19:06:10 -0000	1.3
+++ newlib/libc/stdlib/strtoll_r.c	15 Nov 2013 18:23:34 -0000
@@ -58,8 +58,8 @@
 long long
 _DEFUN (_strtoll_r, (rptr, nptr, endptr, base),
 	struct _reent *rptr _AND
-	_CONST char *nptr _AND
-	char **endptr _AND
+	_CONST char *__restrict nptr _AND
+	char **__restrict endptr _AND
 	int base)
 {
 	register const unsigned char *s = (const unsigned char *)nptr;
Index: newlib/libc/stdlib/strtoul.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/strtoul.c,v
retrieving revision 1.3
diff -u -r1.3 strtoul.c
--- newlib/libc/stdlib/strtoul.c	27 Oct 2010 19:06:10 -0000	1.3
+++ newlib/libc/stdlib/strtoul.c	15 Nov 2013 18:23:34 -0000
@@ -9,11 +9,11 @@
 
 ANSI_SYNOPSIS
 	#include <stdlib.h>
-        unsigned long strtoul(const char *<[s]>, char **<[ptr]>,
+        unsigned long strtoul(const char *restrict <[s]>, char **restrict <[ptr]>,
                               int <[base]>);
 
-        unsigned long _strtoul_r(void *<[reent]>, const char *<[s]>,
-                              char **<[ptr]>, int <[base]>);
+        unsigned long _strtoul_r(void *<[reent]>, const char *restrict <[s]>,
+                              char **restrict <[ptr]>, int <[base]>);
 
 TRAD_SYNOPSIS
 	#include <stdlib.h>
@@ -134,8 +134,8 @@
 unsigned long
 _DEFUN (_strtoul_r, (rptr, nptr, endptr, base),
 	struct _reent *rptr _AND
-	_CONST char *nptr _AND
-	char **endptr _AND
+	_CONST char *__restrict nptr _AND
+	char **__restrict endptr _AND
 	int base)
 {
 	register const unsigned char *s = (const unsigned char *)nptr;
@@ -196,8 +196,8 @@
 
 unsigned long
 _DEFUN (strtoul, (s, ptr, base),
-	_CONST char *s _AND
-	char **ptr _AND
+	_CONST char *__restrict s _AND
+	char **__restrict ptr _AND
 	int base)
 {
 	return _strtoul_r (_REENT, s, ptr, base);
Index: newlib/libc/stdlib/strtoull.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/strtoull.c,v
retrieving revision 1.2
diff -u -r1.2 strtoull.c
--- newlib/libc/stdlib/strtoull.c	6 Jul 2007 20:03:28 -0000	1.2
+++ newlib/libc/stdlib/strtoull.c	15 Nov 2013 18:23:34 -0000
@@ -9,11 +9,11 @@
 
 ANSI_SYNOPSIS
 	#include <stdlib.h>
-        unsigned long long strtoull(const char *<[s]>, char **<[ptr]>,
+        unsigned long long strtoull(const char *restrict <[s]>, char **restrict <[ptr]>,
                               int <[base]>);
 
-        unsigned long long _strtoull_r(void *<[reent]>, const char *<[s]>,
-                              char **<[ptr]>, int <[base]>);
+        unsigned long long _strtoull_r(void *<[reent]>, const char *restrict <[s]>,
+                              char **restrict <[ptr]>, int <[base]>);
 
 TRAD_SYNOPSIS
 	#include <stdlib.h>
@@ -129,8 +129,8 @@
 
 unsigned long long
 _DEFUN (strtoull, (s, ptr, base),
-	_CONST char *s _AND
-	char **ptr _AND
+	_CONST char *__restrict s _AND
+	char **__restrict ptr _AND
 	int base)
 {
 	return _strtoull_r (_REENT, s, ptr, base);
Index: newlib/libc/stdlib/strtoull_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/strtoull_r.c,v
retrieving revision 1.3
diff -u -r1.3 strtoull_r.c
--- newlib/libc/stdlib/strtoull_r.c	27 Oct 2010 19:06:10 -0000	1.3
+++ newlib/libc/stdlib/strtoull_r.c	15 Nov 2013 18:23:34 -0000
@@ -59,8 +59,8 @@
 unsigned long long
 _DEFUN (_strtoull_r, (rptr, nptr, endptr, base),
 	struct _reent *rptr _AND
-	_CONST char *nptr _AND
-	char **endptr _AND
+	_CONST char *__restrict nptr _AND
+	char **__restrict endptr _AND
 	int base)
 {
 	register const unsigned char *s = (const unsigned char *)nptr;
Index: newlib/libc/stdlib/wcstombs.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/wcstombs.c,v
retrieving revision 1.6
diff -u -r1.6 wcstombs.c
--- newlib/libc/stdlib/wcstombs.c	10 Aug 2009 16:23:20 -0000	1.6
+++ newlib/libc/stdlib/wcstombs.c	15 Nov 2013 18:23:34 -0000
@@ -7,7 +7,7 @@
 
 ANSI_SYNOPSIS
 	#include <stdlib.h>
-	size_t wcstombs(char *<[s]>, const wchar_t *<[pwc]>, size_t <[n]>);
+	size_t wcstombs(char *restrict <[s]>, const wchar_t *restrict <[pwc]>, size_t <[n]>);
 
 TRAD_SYNOPSIS
 	#include <stdlib.h>
@@ -56,8 +56,8 @@
 
 size_t
 _DEFUN (wcstombs, (s, pwcs, n),
-        char          *s    _AND
-        const wchar_t *pwcs _AND
+        char          *__restrict s    _AND
+        const wchar_t *__restrict pwcs _AND
         size_t         n)
 {
 #ifdef _MB_CAPABLE
Index: newlib/libc/stdlib/wcstombs_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/wcstombs_r.c,v
retrieving revision 1.5
diff -u -r1.5 wcstombs_r.c
--- newlib/libc/stdlib/wcstombs_r.c	19 Jan 2010 21:14:53 -0000	1.5
+++ newlib/libc/stdlib/wcstombs_r.c	15 Nov 2013 18:23:34 -0000
@@ -5,8 +5,8 @@
 size_t
 _DEFUN (_wcstombs_r, (reent, s, pwcs, n, state),
         struct _reent *r    _AND         
-        char          *s    _AND
-        const wchar_t *pwcs _AND
+        char          *__restrict s    _AND
+        const wchar_t *__restrict pwcs _AND
         size_t         n    _AND
         mbstate_t     *state)
 {


More information about the Newlib mailing list