This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[RFC] statically initialize spu FILE values
- From: Patrick Mansfield <patmans at us dot ibm dot com>
- To: newlib at sourceware dot org, Kazunori Asayama <asayama at sm dot sony dot co dot jp>, Joel Schopp <jschopp at austin dot ibm dot com>
- Date: Fri, 6 Apr 2007 08:00:41 -0700
- Subject: [RFC] statically initialize spu FILE values
Use a static initialization of the spu FILE values, and get rid of the
runtime spu calls to CHECK_INIT.
RFC especially on the location and use of the new defines.
Ran some simple tests for predefined FILE streams.
Hacked spu to test that it compiles OK without the special defines, and
that spu _REENT_INIT_PTR compiled OK (spu code does not use
_REENT_INIT_PTR).
ChangeLog:
2007-04-06 Patrick Mansfield <patmans@us.ibm.com>
* libc/include/sys/reent.h: Add and use defines for initialization
of the __sf FILE values.
* libc/machine/spu/sys/custom_file.h: Add spu specific __sf
initialization defines.
* libc/machine/spu/stdio.c: Remove __sinit.
* libc/machine/spu/c99ppe.h: Remove SPE_STD*, remove CHECK_INIT define.
* libc/machine/spu/clearerr.c: Remove call to CHECK_INIT.
* libc/machine/spu/fclose.c: Ditto.
* libc/machine/spu/feof.c: Ditto.
* libc/machine/spu/ferror.c: Ditto.
* libc/machine/spu/fflush.c: Ditto.
* libc/machine/spu/fgetc.c: Ditto.
* libc/machine/spu/fgetpos.c: Ditto.
* libc/machine/spu/fgets.c: Ditto.
* libc/machine/spu/fileno.c: Ditto.
* libc/machine/spu/fopen.c: Ditto.
* libc/machine/spu/fprintf.c: Ditto.
* libc/machine/spu/fputc.c: Ditto.
* libc/machine/spu/fputs.c: Ditto.
* libc/machine/spu/fread.c: Ditto.
* libc/machine/spu/freopen.c: Ditto.
* libc/machine/spu/fscanf.c: Ditto.
* libc/machine/spu/fseek.c: Ditto.
* libc/machine/spu/fsetpos.c: Ditto.
* libc/machine/spu/ftell.c: Ditto.
* libc/machine/spu/fwrite.c: Ditto.
* libc/machine/spu/getc.c: Ditto.
* libc/machine/spu/putc.c: Ditto.
* libc/machine/spu/rewind.c: Ditto.
* libc/machine/spu/setbuf.c: Ditto.
* libc/machine/spu/setvbuf.c: Ditto.
* libc/machine/spu/tmpfile.c: Ditto.
* libc/machine/spu/ungetc.c: Ditto.
* libc/machine/spu/vfprintf.c: Ditto.
* libc/machine/spu/vfscanf.c: Ditto.
Index: my-base-quilt/newlib/libc/include/sys/reent.h
===================================================================
--- my-base-quilt.orig/newlib/libc/include/sys/reent.h
+++ my-base-quilt/newlib/libc/include/sys/reent.h
@@ -646,6 +646,12 @@ struct _reent
__FILE __sf[3]; /* first three file descriptors */
};
+#ifndef __SF_INIT
+#define __SF_INIT
+#define __SF_INIT_PTR(var) memset(&var->__sf, 0, sizeof(var->__sf))
+#define __INIT_SDIDINIT 0
+#endif
+
#define _REENT_INIT(var) \
{ 0, \
&var.__sf[0], \
@@ -655,7 +661,7 @@ struct _reent
"", \
0, \
"C", \
- 0, \
+ __INIT_SDIDINIT, \
_NULL, \
_NULL, \
0, \
@@ -692,7 +698,8 @@ struct _reent
_NULL, \
{_NULL, 0, {_NULL}, {{_NULL}, {_NULL}, 0, 0}}, \
_NULL, \
- {_NULL, 0, _NULL} \
+ {_NULL, 0, _NULL}, \
+ __SF_INIT \
}
#define _REENT_INIT_PTR(var) \
@@ -754,7 +761,7 @@ struct _reent
var->__sglue._next = _NULL; \
var->__sglue._niobs = 0; \
var->__sglue._iobs = _NULL; \
- memset(&var->__sf, 0, sizeof(var->__sf)); \
+ __SF_INIT_PTR(var); \
}
#define _REENT_CHECK_RAND48(ptr) /* nothing */
Index: my-base-quilt/newlib/libc/machine/spu/sys/custom_file.h
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/sys/custom_file.h
+++ my-base-quilt/newlib/libc/machine/spu/sys/custom_file.h
@@ -9,5 +9,16 @@ struct __sFILE_spu {
};
typedef struct __sFILE_spu __FILE;
+#define __SPE_STDIN 1
+#define __SPE_STDOUT 2
+#define __SPE_STDERR 3
+
+#define __SF_INIT { __SPE_STDIN, __SPE_STDOUT, __SPE_STDERR }
+#define __SF_INIT_PTR(var) \
+ var->__sf[0]._fp = __SPE_STDIN; \
+ var->__sf[1]._fp = __SPE_STDOUT; \
+ var->__sf[2]._fp = __SPE_STDERR;
+#define __INIT_SDIDINIT 1
+
#endif /* __CUSTOM_FILE_H__ */
Index: my-base-quilt/newlib/libc/machine/spu/stdio.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/stdio.c
+++ my-base-quilt/newlib/libc/machine/spu/stdio.c
@@ -63,20 +63,3 @@ _DEFUN (__cleanup, (s),
}
}
}
-
-_VOID
-_DEFUN (__sinit, (s),
- struct _reent *s)
-{
- s->__cleanup = __cleanup;
- s->__sdidinit = 1;
-
- s->_stdin = &s->__sf[0];
- s->_stdin->_fp = SPE_STDIN;
-
- s->_stdout = &s->__sf[1];
- s->_stdout->_fp = SPE_STDOUT;
-
- s->_stderr = &s->__sf[2];
- s->_stderr->_fp = SPE_STDERR;
-}
Index: my-base-quilt/newlib/libc/machine/spu/c99ppe.h
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/c99ppe.h
+++ my-base-quilt/newlib/libc/machine/spu/c99ppe.h
@@ -85,9 +85,6 @@ enum {
};
#define SPE_C99_NR_OPCODES ((SPE_C99_LAST_OPCODE - SPE_C99_CLEARERR) + 1)
-#define SPE_STDIN 1
-#define SPE_STDOUT 2
-#define SPE_STDERR 3
#define SPE_FOPEN_MAX FOPEN_MAX
struct spe_reg128{
@@ -98,7 +95,5 @@ void _EXFUN(__sinit,(struct _reent *));
FILE *_EXFUN(__sfp,(struct _reent *));
#define __sfp_free(fp) ( (fp)->_fp = 0 )
-#define CHECK_INIT(ptr) \
- do { if ((ptr) && !(ptr)->__sdidinit) __sinit (ptr); } while (0)
#define CHECK_STD_INIT(ptr) /* currently, do nothing */
#define CHECK_STR_INIT(ptr) /* currently, do nothing */
Index: my-base-quilt/newlib/libc/machine/spu/clearerr.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/clearerr.c
+++ my-base-quilt/newlib/libc/machine/spu/clearerr.c
@@ -43,8 +43,6 @@ _DEFUN (clearerr, (fp),
{
int ret;
- CHECK_INIT(_REENT);
-
ret = fp->_fp;
__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_CLEARERR, &ret);
Index: my-base-quilt/newlib/libc/machine/spu/fclose.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fclose.c
+++ my-base-quilt/newlib/libc/machine/spu/fclose.c
@@ -42,8 +42,6 @@ _DEFUN (fclose, (fp),
{
int ret;
- CHECK_INIT(_REENT);
-
ret = fp->_fp;
__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FCLOSE, &ret);
Index: my-base-quilt/newlib/libc/machine/spu/feof.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/feof.c
+++ my-base-quilt/newlib/libc/machine/spu/feof.c
@@ -42,8 +42,6 @@ _DEFUN (feof, (fp),
{
int result;
- CHECK_INIT(_REENT);
-
result = fp->_fp;
__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FEOF, &result);
Index: my-base-quilt/newlib/libc/machine/spu/ferror.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/ferror.c
+++ my-base-quilt/newlib/libc/machine/spu/ferror.c
@@ -42,8 +42,6 @@ _DEFUN (ferror, (fp),
{
int result;
- CHECK_INIT(_REENT);
-
result = fp->_fp;
__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FERROR, &result);
Index: my-base-quilt/newlib/libc/machine/spu/fflush.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fflush.c
+++ my-base-quilt/newlib/libc/machine/spu/fflush.c
@@ -41,8 +41,6 @@ _DEFUN (fflush, (fp),
{
int result;
- CHECK_INIT(_REENT);
-
result = fp->_fp;
__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FFLUSH, &result);
Index: my-base-quilt/newlib/libc/machine/spu/fgetc.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fgetc.c
+++ my-base-quilt/newlib/libc/machine/spu/fgetc.c
@@ -42,8 +42,6 @@ _DEFUN (fgetc, (fp),
{
int result;
- CHECK_INIT(_REENT);
-
result = fp->_fp;
__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FGETC, &result);
Index: my-base-quilt/newlib/libc/machine/spu/fgetpos.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fgetpos.c
+++ my-base-quilt/newlib/libc/machine/spu/fgetpos.c
@@ -51,8 +51,6 @@ _DEFUN (fgetpos, (fp, pos),
c99_fgetpos_t arg;
int* result;
- CHECK_INIT(_REENT);
-
result = (int*)&arg;
arg.fp = fp->_fp;
Index: my-base-quilt/newlib/libc/machine/spu/fgets.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fgets.c
+++ my-base-quilt/newlib/libc/machine/spu/fgets.c
@@ -54,8 +54,6 @@ _DEFUN (fgets, (buf, n, fp),
char** ret;
c99_fgets_t args;
- CHECK_INIT(_REENT);
-
args.buf = buf;
args.n = n;
args.fp = fp->_fp;
Index: my-base-quilt/newlib/libc/machine/spu/fileno.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fileno.c
+++ my-base-quilt/newlib/libc/machine/spu/fileno.c
@@ -43,8 +43,6 @@ _DEFUN (fileno, (fp),
{
int ret;
- CHECK_INIT(_REENT);
-
ret = fp->_fp;
__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FILENO, &ret);
Index: my-base-quilt/newlib/libc/machine/spu/fopen.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fopen.c
+++ my-base-quilt/newlib/libc/machine/spu/fopen.c
@@ -54,8 +54,6 @@ _DEFUN (fopen, (file, mode),
FILE *fp;
struct _reent *ptr = _REENT;
- CHECK_INIT(ptr);
-
fp = __sfp(ptr);
if (!fp) {
return NULL;
Index: my-base-quilt/newlib/libc/machine/spu/fprintf.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fprintf.c
+++ my-base-quilt/newlib/libc/machine/spu/fprintf.c
@@ -62,8 +62,6 @@ fprintf(FILE * fp, _CONST char *fmt,...)
int* ret;
c99_fprintf_t args;
- CHECK_INIT(_REENT);
-
ret = (int*) &args;
args.fp = fp->_fp;
Index: my-base-quilt/newlib/libc/machine/spu/fputc.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fputc.c
+++ my-base-quilt/newlib/libc/machine/spu/fputc.c
@@ -53,8 +53,6 @@ fputc (c, fp)
int* ret;
c99_fputc_t args;
- CHECK_INIT(_REENT);
-
args.ch = c;
args.fp = fp->_fp;
ret = (int*)&args;
Index: my-base-quilt/newlib/libc/machine/spu/fputs.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fputs.c
+++ my-base-quilt/newlib/libc/machine/spu/fputs.c
@@ -53,8 +53,6 @@ _DEFUN (fputs, (s, fp),
int* ret;
c99_fputs_t args;
- CHECK_INIT(_REENT);
-
args.s = s;
args.fp = fp->_fp;
ret = (int*)&args;
Index: my-base-quilt/newlib/libc/machine/spu/fread.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fread.c
+++ my-base-quilt/newlib/libc/machine/spu/fread.c
@@ -58,8 +58,6 @@ _DEFUN (fread, (buf, size, count, fp),
size_t* ret;
c99_fread_t args;
- CHECK_INIT(_REENT);
-
args.buf = buf;
args.size = size;
args.count = count;
Index: my-base-quilt/newlib/libc/machine/spu/freopen.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/freopen.c
+++ my-base-quilt/newlib/libc/machine/spu/freopen.c
@@ -55,8 +55,6 @@ _DEFUN (freopen, (file, mode, fp),
int *ret;
c99_freopen_t args;
- CHECK_INIT(_REENT);
-
args.file = file;
args.mode = mode;
args.fp = fp->_fp;
Index: my-base-quilt/newlib/libc/machine/spu/fscanf.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fscanf.c
+++ my-base-quilt/newlib/libc/machine/spu/fscanf.c
@@ -61,8 +61,6 @@ fscanf(FILE *fp, _CONST char *fmt, ...)
int* ret;
c99_vfscanf_t args;
- CHECK_INIT(_REENT);
-
ret = (int*) &args;
args.fp = fp->_fp;
Index: my-base-quilt/newlib/libc/machine/spu/fseek.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fseek.c
+++ my-base-quilt/newlib/libc/machine/spu/fseek.c
@@ -55,8 +55,6 @@ _DEFUN (fseek, (fp, offset, whence),
int* ret;
c99_fseek_t args;
- CHECK_INIT(_REENT);
-
args.fp = fp->_fp;
args.offset = offset;
args.whence = whence;
Index: my-base-quilt/newlib/libc/machine/spu/fsetpos.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fsetpos.c
+++ my-base-quilt/newlib/libc/machine/spu/fsetpos.c
@@ -52,8 +52,6 @@ _DEFUN (fsetpos, (iop, pos),
int* ret;
c99_fsetpos_t args;
- CHECK_INIT(_REENT);
-
args.fp = iop->_fp;
args.pos = pos;
ret = (int*)&args;
Index: my-base-quilt/newlib/libc/machine/spu/ftell.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/ftell.c
+++ my-base-quilt/newlib/libc/machine/spu/ftell.c
@@ -43,8 +43,6 @@ _DEFUN (ftell, (fp),
{
long ret;
- CHECK_INIT(_REENT);
-
ret = fp->_fp;
__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_FTELL, &ret);
Index: my-base-quilt/newlib/libc/machine/spu/fwrite.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/fwrite.c
+++ my-base-quilt/newlib/libc/machine/spu/fwrite.c
@@ -58,8 +58,6 @@ _DEFUN (fwrite, (buf, size, count, fp),
size_t* ret;
c99_fwrite_t args;
- CHECK_INIT(_REENT);
-
args.buf = buf;
args.size = size;
args.count = count;
Index: my-base-quilt/newlib/libc/machine/spu/getc.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/getc.c
+++ my-base-quilt/newlib/libc/machine/spu/getc.c
@@ -45,8 +45,6 @@ getc (fp)
{
int ret;
- CHECK_INIT(_REENT);
-
ret = fp->_fp;
__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_GETC, &ret);
Index: my-base-quilt/newlib/libc/machine/spu/putc.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/putc.c
+++ my-base-quilt/newlib/libc/machine/spu/putc.c
@@ -53,8 +53,6 @@ putc (c, fp)
int* ret;
c99_putc_t args;
- CHECK_INIT(_REENT);
-
args.ch = c;
args.fp = fp->_fp;
ret = (int*)&args;
Index: my-base-quilt/newlib/libc/machine/spu/rewind.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/rewind.c
+++ my-base-quilt/newlib/libc/machine/spu/rewind.c
@@ -42,8 +42,6 @@ _DEFUN (rewind, (fp),
{
int ret;
- CHECK_INIT(_REENT);
-
ret = fp->_fp;
__send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_REWIND, &ret);
Index: my-base-quilt/newlib/libc/machine/spu/setbuf.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/setbuf.c
+++ my-base-quilt/newlib/libc/machine/spu/setbuf.c
@@ -52,8 +52,6 @@ _DEFUN (setbuf, (fp, buf),
{
c99_setbuf_t args;
- CHECK_INIT(_REENT);
-
args.fp = fp->_fp;
args.buf = buf;
Index: my-base-quilt/newlib/libc/machine/spu/setvbuf.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/setvbuf.c
+++ my-base-quilt/newlib/libc/machine/spu/setvbuf.c
@@ -59,8 +59,6 @@ _DEFUN (setvbuf, (fp, buf, mode, size),
int* ret;
c99_setvbuf_t args;
- CHECK_INIT(_REENT);
-
args.fp = fp->_fp;
args.buf = buf;
args.mode = mode;
Index: my-base-quilt/newlib/libc/machine/spu/tmpfile.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/tmpfile.c
+++ my-base-quilt/newlib/libc/machine/spu/tmpfile.c
@@ -43,8 +43,6 @@ _DEFUN_VOID (tmpfile)
FILE* fp;
struct _reent *ptr = _REENT;
- CHECK_INIT(ptr);
-
fp = __sfp(ptr);
if (!fp) {
return NULL;
Index: my-base-quilt/newlib/libc/machine/spu/ungetc.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/ungetc.c
+++ my-base-quilt/newlib/libc/machine/spu/ungetc.c
@@ -53,8 +53,6 @@ ungetc (c, fp)
int* ret;
c99_ungetc_t args;
- CHECK_INIT(_REENT);
-
args.c = c;
args.fp = fp->_fp;
ret = (int*)&args;
Index: my-base-quilt/newlib/libc/machine/spu/vfprintf.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/vfprintf.c
+++ my-base-quilt/newlib/libc/machine/spu/vfprintf.c
@@ -65,8 +65,6 @@ _DEFUN (vfprintf, (fp, fmt0, ap),
int* ret;
c99_vfprintf_t args;
- CHECK_INIT(_REENT);
-
ret = (int*) &args;
args.fp = fp->_fp;
Index: my-base-quilt/newlib/libc/machine/spu/vfscanf.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/vfscanf.c
+++ my-base-quilt/newlib/libc/machine/spu/vfscanf.c
@@ -65,8 +65,6 @@ _DEFUN (vfscanf, (fp, fmt, ap),
int* ret;
c99_vfscanf_t args;
- CHECK_INIT(_REENT);
-
ret = (int*) &args;
args.fp = fp->_fp;