This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add missing iprintf and iscanf family for SPU


On Mon, Feb 19, 2007 at 12:22:23PM +0900, Kazunori Asayama wrote:
> Patrick Mansfield <patmans@us.ibm.com> wrote:

> > That fixes the assert problem, but can (or should) we lose the defines for
> > normal compiles?
> > 
> > And then lose the externs for the unsupplied functions? (Now we just end
> > up with two externs for some functions.)
> > 
> > I mean this is confusing, and we should not (strictly) prevent a user
> > defined iprintf when we aren't supplying one:
> 
> Right. I had considered about the same issue too, but on the other
> hand, I wanted to avoid increase of code size by linking with both of
> printf family and iprintf family.
> 
> Here is an alternative approach:
> 
>   - to eliminate internal use of iprintf family, and
>   - to leave iprintf family undefined.
>     (or to define iprintf family as functions if required.)
> 
> Attached is a patch to implement this.
> What do you think ?

That still leaves the (potentially) conflicting prototypes for the
iprintf's in stdio.h. I don't like the double negative ("#ifndef ifndef
NO_INTERNAL_IPRINTF") but since SPU is the exception, I guess it is OK
(versus having INTERNAL_IPRINTF defined for most archs, and then
undefining it for SPU).

So here is your patch modified to move the define into sys/config.h so we
have it for user space *and* for newlib builds, and then never have
prototypes for iprintf in stdio.h when NO_INTERNAL_IPRINTF is not defined.

So the name_collision.c file I previously posted compiles and runs as
expected, and then assert() also works, and we have no references or
definitions of iprintf in the resulting libc.a or libgloss.a.

Comments?

diff -uprN -X /home/patman/dontdiff base/newlib/libc/include/stdio.h iprintf_more/newlib/libc/include/stdio.h
--- base/newlib/libc/include/stdio.h	2007-02-19 10:24:30.000000000 -0800
+++ iprintf_more/newlib/libc/include/stdio.h	2007-02-19 10:27:09.000000000 -0800
@@ -227,34 +227,38 @@ int	_EXFUN(fseeko, (FILE *, off_t, int))
 off_t	_EXFUN(ftello, ( FILE *));
 #endif
 #ifndef _REENT_ONLY
+#ifndef NO_INTERNAL_IPRINTF
 int	_EXFUN(asiprintf, (char **, const char *, ...));
+#endif
 int	_EXFUN(asprintf, (char **, const char *, ...));
 #ifndef dprintf
 int	_EXFUN(dprintf, (int, const char *, ...));
 #endif
 int	_EXFUN(fcloseall, (_VOID));
-int	_EXFUN(fiprintf, (FILE *, const char *, ...));
 int	_EXFUN(fiscanf, (FILE *, const char *, ...));
-int	_EXFUN(iprintf, (const char *, ...));
 int	_EXFUN(iscanf, (const char *, ...));
-int	_EXFUN(siprintf, (char *, const char *, ...));
 int	_EXFUN(siscanf, (const char *, const char *, ...));
 int	_EXFUN(snprintf, (char *, size_t, const char *, ...));
-int	_EXFUN(sniprintf, (char *, size_t, const char *, ...));
 char *	_EXFUN(tempnam, (const char *, const char *));
-int	_EXFUN(vasiprintf, (char **, const char *, __VALIST));
 int	_EXFUN(vasprintf, (char **, const char *, __VALIST));
 int	_EXFUN(vdprintf, (int, const char *, __VALIST));
-int	_EXFUN(vsniprintf, (char *, size_t, const char *, __VALIST));
 int	_EXFUN(vsnprintf, (char *, size_t, const char *, __VALIST));
-int	_EXFUN(vfiprintf, (FILE *, const char *, __VALIST));
 int	_EXFUN(vfiscanf, (FILE *, const char *, __VALIST));
 int	_EXFUN(vfscanf, (FILE *, const char *, __VALIST));
-int	_EXFUN(viprintf, (const char *, __VALIST));
 int	_EXFUN(viscanf, (const char *, __VALIST));
 int	_EXFUN(vscanf, (const char *, __VALIST));
 int	_EXFUN(vsiscanf, (const char *, const char *, __VALIST));
 int	_EXFUN(vsscanf, (const char *, const char *, __VALIST));
+#ifndef NO_INTERNAL_IPRINTF
+int	_EXFUN(fiprintf, (FILE *, const char *, ...));
+int	_EXFUN(iprintf, (const char *, ...));
+int	_EXFUN(siprintf, (char *, const char *, ...));
+int	_EXFUN(sniprintf, (char *, size_t, const char *, ...));
+int	_EXFUN(vasiprintf, (char **, const char *, __VALIST));
+int	_EXFUN(vsniprintf, (char *, size_t, const char *, __VALIST));
+int	_EXFUN(vfiprintf, (FILE *, const char *, __VALIST));
+int	_EXFUN(viprintf, (const char *, __VALIST));
+#endif
 #endif
 #endif
 
diff -uprN -X /home/patman/dontdiff base/newlib/libc/include/sys/config.h iprintf_more/newlib/libc/include/sys/config.h
--- base/newlib/libc/include/sys/config.h	2007-02-19 10:24:30.000000000 -0800
+++ iprintf_more/newlib/libc/include/sys/config.h	2007-02-19 10:27:09.000000000 -0800
@@ -133,6 +133,7 @@
 #ifdef __SPU__
 #define MALLOC_ALIGNMENT 16
 #define __CUSTOM_FILE_IO__
+#define NO_INTERNAL_IPRINTF
 #endif
 
 /* This block should be kept in sync with GCC's limits.h.  The point
diff -uprN -X /home/patman/dontdiff base/newlib/libc/stdlib/assert.c iprintf_more/newlib/libc/stdlib/assert.c
--- base/newlib/libc/stdlib/assert.c	2007-02-19 10:24:34.000000000 -0800
+++ iprintf_more/newlib/libc/stdlib/assert.c	2007-02-19 10:24:35.000000000 -0800
@@ -47,6 +47,7 @@ Supporting OS subroutines required (only
 #include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include "local.h"
 
 void
 _DEFUN (__assert, (file, line, failedexpr),
diff -uprN -X /home/patman/dontdiff base/newlib/libc/stdlib/eprintf.c iprintf_more/newlib/libc/stdlib/eprintf.c
--- base/newlib/libc/stdlib/eprintf.c	2007-02-19 10:24:34.000000000 -0800
+++ iprintf_more/newlib/libc/stdlib/eprintf.c	2007-02-19 10:24:35.000000000 -0800
@@ -12,6 +12,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include "local.h"
 
 void
 __eprintf (format, file, line, expression)
diff -uprN -X /home/patman/dontdiff base/newlib/libc/stdlib/local.h iprintf_more/newlib/libc/stdlib/local.h
--- base/newlib/libc/stdlib/local.h	2007-02-19 10:24:34.000000000 -0800
+++ iprintf_more/newlib/libc/stdlib/local.h	2007-02-19 10:24:35.000000000 -0800
@@ -5,4 +5,8 @@
 
 char *	_EXFUN(_gcvt,(struct _reent *, double , int , char *, char, int));
 
+#ifdef NO_INTERNAL_IPRINTF
+#  define fiprintf fprintf
+#endif
+
 #endif
diff -uprN -X /home/patman/dontdiff base/newlib/libc/stdlib/mallocr.c iprintf_more/newlib/libc/stdlib/mallocr.c
--- base/newlib/libc/stdlib/mallocr.c	2007-02-19 10:24:34.000000000 -0800
+++ iprintf_more/newlib/libc/stdlib/mallocr.c	2007-02-19 10:24:35.000000000 -0800
@@ -3504,7 +3504,9 @@ void malloc_stats(RONEARG) RDECL
 #ifdef INTERNAL_NEWLIB
   _REENT_SMALL_CHECK_INIT(reent_ptr);
   fp = _stderr_r(reent_ptr);
+#ifndef NO_INTERNAL_IPRINTF
 #define fprintf fiprintf
+#endif
 #else
   fp = stderr;
 #endif
diff -uprN -X /home/patman/dontdiff base/newlib/libc/stdlib/mstats.c iprintf_more/newlib/libc/stdlib/mstats.c
--- base/newlib/libc/stdlib/mstats.c	2007-02-19 10:24:34.000000000 -0800
+++ iprintf_more/newlib/libc/stdlib/mstats.c	2007-02-19 10:24:35.000000000 -0800
@@ -101,6 +101,7 @@ not portable.
 #include <stdlib.h>
 #include <malloc.h>
 #include <stdio.h>
+#include "local.h"
 
 #ifndef _REENT_ONLY
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]