Roland Mainz
2013-08-17 16:48:44 UTC
Hi!
----
Attached (as "astksh20130814_restrict001.diff.txt") is a patch which
provides the C99 flag |restrict| as |_AST_RESTRICT| if we compile with
a C99 (or better) compiler...
* Notes:
- I've converted a few functions to use |_AST_RESTRICT| already. The
point is that instrumentation tools can find issues (e.g. overlapping
memory accesses etc.) in those cases
- Tested with C89, C99 and C1X modes with gcc, clang and Sun Studio
- If this patch gets accepted (please please for the next alpha) I'll
do more conversion stuff per prototypes listed at opengroup.org. This
should give better instrumentation coverage and *MUCH* better
performance, too.
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
-------------- next part --------------
diff -r -u original/src/lib/libast/features/sys build_restrict/src/lib/libast/features/sys
--- src/lib/libast/features/sys 2013-08-09 16:55:32.000000000 +0200
+++ src/lib/libast/features/sys 2013-08-17 18:12:13.421570259 +0200
@@ -222,6 +222,14 @@
print #define extern __EXPORT__
print #endif
+print #ifndef _AST_RESTRICT
+print #if __STDC_VERSION__ >= 199901L
+print #define _AST_RESTRICT restrict
+print #else
+print #define _AST_RESTRICT
+print #endif
+print #endif
+
extern _exit void (int)
extern abort void (void)
extern abs int (int)
@@ -308,8 +316,8 @@
extern spawnvex_get intmax_t (Spawnvex_t*, int, int)
extern spawnvex_close int (Spawnvex_t*)
extern srand void (unsigned int)
-extern stpcpy char* (char*, const char*)
-extern stpncpy char* (char*, const char*, size_t)
+extern stpcpy char* (char* _AST_RESTRICT, const char* _AST_RESTRICT)
+extern stpncpy char* (char* _AST_RESTRICT, const char* _AST_RESTRICT, size_t)
extern strcasecmp int (const char*, const char*)
extern strcat char* (char*, const char*)
extern strchr char* (const char*, int)
diff -r -u original/src/lib/libast/include/ast.h build_restrict/src/lib/libast/include/ast.h
--- src/lib/libast/include/ast.h 2013-08-09 17:26:20.000000000 +0200
+++ src/lib/libast/include/ast.h 2013-08-17 18:28:01.265585566 +0200
@@ -63,6 +63,14 @@
#endif
#endif
+#ifndef _AST_RESTRICT
+#if __STDC_VERSION__ >= 199901L
+#define _AST_RESTRICT restrict
+#else
+#define _AST_RESTRICT
+#endif
+#endif
+
/*
* exit() support -- this matches shell exit codes
*/
@@ -352,7 +360,7 @@
extern ssize_t qpdecode(const void*, size_t, void**, void*, size_t, void**);
extern char* setenviron(const char*);
extern int stracmp(const char*, const char*);
-extern char* strcopy(char*, const char*);
+extern char* strcopy(char* _AST_RESTRICT, const char* _AST_RESTRICT);
extern unsigned long strelapsed(const char*, char**, int);
extern int stresc(char*);
extern int strexp(char*, int);
@@ -367,7 +375,7 @@
extern int strmatch(const char*, const char*);
extern int strmode(const char*);
extern int strnacmp(const char*, const char*, size_t);
-extern char* strncopy(char*, const char*, size_t);
+extern char* strncopy(char* _AST_RESTRICT, const char* _AST_RESTRICT, size_t);
extern int strnpcmp(const char*, const char*, size_t);
extern double strntod(const char*, size_t, char**);
extern _ast_fltmax_t strntold(const char*, size_t, char**);
diff -r -u original/src/lib/libast/string/stpcpy.c build_restrict/src/lib/libast/string/stpcpy.c
--- src/lib/libast/string/stpcpy.c 2013-08-09 16:43:42.000000000 +0200
+++ src/lib/libast/string/stpcpy.c 2013-08-17 18:09:20.527143900 +0200
@@ -48,7 +48,7 @@
*/
extern char*
-stpcpy(register char* t, register const char* f)
+stpcpy(register char _AST_RESTRICT* t, register const char _AST_RESTRICT* f)
{
if (!f)
return t;
diff -r -u original/src/lib/libast/string/stpncpy.c build_restrict/src/lib/libast/string/stpncpy.c
--- src/lib/libast/string/stpncpy.c 2013-08-14 07:46:52.000000000 +0200
+++ src/lib/libast/string/stpncpy.c 2013-08-17 18:09:31.431304811 +0200
@@ -54,7 +54,7 @@
*/
extern char*
-stpncpy(char *t, const char *f, size_t n)
+stpncpy(char *_AST_RESTRICT t, const char *_AST_RESTRICT f, size_t n)
{
const char* e = f + n;
diff -r -u original/src/lib/libast/string/strcopy.c build_restrict/src/lib/libast/string/strcopy.c
--- src/lib/libast/string/strcopy.c 2012-08-09 09:37:53.000000000 +0200
+++ src/lib/libast/string/strcopy.c 2013-08-17 18:27:41.443472883 +0200
@@ -28,7 +28,7 @@
*/
char*
-strcopy(register char* s, register const char* t)
+strcopy(register char* _AST_RESTRICT s, register const char* _AST_RESTRICT t)
{
if (!t)
return s;
diff -r -u original/src/lib/libast/string/strncopy.c build_restrict/src/lib/libast/string/strncopy.c
--- src/lib/libast/string/strncopy.c 2002-11-18 19:42:21.000000000 +0100
+++ src/lib/libast/string/strncopy.c 2013-08-17 18:28:44.048145275 +0200
@@ -30,7 +30,7 @@
*/
char*
-strncopy(register char* t, register const char* f, size_t n)
+strncopy(register char* _AST_RESTRICT t, register const char* _AST_RESTRICT f, size_t n)
{
register char* e = t + n - 1;
----
Attached (as "astksh20130814_restrict001.diff.txt") is a patch which
provides the C99 flag |restrict| as |_AST_RESTRICT| if we compile with
a C99 (or better) compiler...
* Notes:
- I've converted a few functions to use |_AST_RESTRICT| already. The
point is that instrumentation tools can find issues (e.g. overlapping
memory accesses etc.) in those cases
- Tested with C89, C99 and C1X modes with gcc, clang and Sun Studio
- If this patch gets accepted (please please for the next alpha) I'll
do more conversion stuff per prototypes listed at opengroup.org. This
should give better instrumentation coverage and *MUCH* better
performance, too.
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
-------------- next part --------------
diff -r -u original/src/lib/libast/features/sys build_restrict/src/lib/libast/features/sys
--- src/lib/libast/features/sys 2013-08-09 16:55:32.000000000 +0200
+++ src/lib/libast/features/sys 2013-08-17 18:12:13.421570259 +0200
@@ -222,6 +222,14 @@
print #define extern __EXPORT__
print #endif
+print #ifndef _AST_RESTRICT
+print #if __STDC_VERSION__ >= 199901L
+print #define _AST_RESTRICT restrict
+print #else
+print #define _AST_RESTRICT
+print #endif
+print #endif
+
extern _exit void (int)
extern abort void (void)
extern abs int (int)
@@ -308,8 +316,8 @@
extern spawnvex_get intmax_t (Spawnvex_t*, int, int)
extern spawnvex_close int (Spawnvex_t*)
extern srand void (unsigned int)
-extern stpcpy char* (char*, const char*)
-extern stpncpy char* (char*, const char*, size_t)
+extern stpcpy char* (char* _AST_RESTRICT, const char* _AST_RESTRICT)
+extern stpncpy char* (char* _AST_RESTRICT, const char* _AST_RESTRICT, size_t)
extern strcasecmp int (const char*, const char*)
extern strcat char* (char*, const char*)
extern strchr char* (const char*, int)
diff -r -u original/src/lib/libast/include/ast.h build_restrict/src/lib/libast/include/ast.h
--- src/lib/libast/include/ast.h 2013-08-09 17:26:20.000000000 +0200
+++ src/lib/libast/include/ast.h 2013-08-17 18:28:01.265585566 +0200
@@ -63,6 +63,14 @@
#endif
#endif
+#ifndef _AST_RESTRICT
+#if __STDC_VERSION__ >= 199901L
+#define _AST_RESTRICT restrict
+#else
+#define _AST_RESTRICT
+#endif
+#endif
+
/*
* exit() support -- this matches shell exit codes
*/
@@ -352,7 +360,7 @@
extern ssize_t qpdecode(const void*, size_t, void**, void*, size_t, void**);
extern char* setenviron(const char*);
extern int stracmp(const char*, const char*);
-extern char* strcopy(char*, const char*);
+extern char* strcopy(char* _AST_RESTRICT, const char* _AST_RESTRICT);
extern unsigned long strelapsed(const char*, char**, int);
extern int stresc(char*);
extern int strexp(char*, int);
@@ -367,7 +375,7 @@
extern int strmatch(const char*, const char*);
extern int strmode(const char*);
extern int strnacmp(const char*, const char*, size_t);
-extern char* strncopy(char*, const char*, size_t);
+extern char* strncopy(char* _AST_RESTRICT, const char* _AST_RESTRICT, size_t);
extern int strnpcmp(const char*, const char*, size_t);
extern double strntod(const char*, size_t, char**);
extern _ast_fltmax_t strntold(const char*, size_t, char**);
diff -r -u original/src/lib/libast/string/stpcpy.c build_restrict/src/lib/libast/string/stpcpy.c
--- src/lib/libast/string/stpcpy.c 2013-08-09 16:43:42.000000000 +0200
+++ src/lib/libast/string/stpcpy.c 2013-08-17 18:09:20.527143900 +0200
@@ -48,7 +48,7 @@
*/
extern char*
-stpcpy(register char* t, register const char* f)
+stpcpy(register char _AST_RESTRICT* t, register const char _AST_RESTRICT* f)
{
if (!f)
return t;
diff -r -u original/src/lib/libast/string/stpncpy.c build_restrict/src/lib/libast/string/stpncpy.c
--- src/lib/libast/string/stpncpy.c 2013-08-14 07:46:52.000000000 +0200
+++ src/lib/libast/string/stpncpy.c 2013-08-17 18:09:31.431304811 +0200
@@ -54,7 +54,7 @@
*/
extern char*
-stpncpy(char *t, const char *f, size_t n)
+stpncpy(char *_AST_RESTRICT t, const char *_AST_RESTRICT f, size_t n)
{
const char* e = f + n;
diff -r -u original/src/lib/libast/string/strcopy.c build_restrict/src/lib/libast/string/strcopy.c
--- src/lib/libast/string/strcopy.c 2012-08-09 09:37:53.000000000 +0200
+++ src/lib/libast/string/strcopy.c 2013-08-17 18:27:41.443472883 +0200
@@ -28,7 +28,7 @@
*/
char*
-strcopy(register char* s, register const char* t)
+strcopy(register char* _AST_RESTRICT s, register const char* _AST_RESTRICT t)
{
if (!t)
return s;
diff -r -u original/src/lib/libast/string/strncopy.c build_restrict/src/lib/libast/string/strncopy.c
--- src/lib/libast/string/strncopy.c 2002-11-18 19:42:21.000000000 +0100
+++ src/lib/libast/string/strncopy.c 2013-08-17 18:28:44.048145275 +0200
@@ -30,7 +30,7 @@
*/
char*
-strncopy(register char* t, register const char* f, size_t n)
+strncopy(register char* _AST_RESTRICT t, register const char* _AST_RESTRICT f, size_t n)
{
register char* e = t + n - 1;