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: _REENT_SMALL IO broken


Paul Brook wrote:
a) Every use of a file descriptor needs to check if it has the read FD,
or a dummy copy. In this case there's no point having the dummy
structure, we can just assign stdin/out/err magic values. As a bonus
_reent gets even smaller, at the expense of a small code size increase.


IMO, the right solution is a) but not the 2nd part of your proposal.
The reason we have the dummy structure is to handle the stdio macros
(e.g. getc and putc).  For speed/compactness, we want them to think they
are operating on a real FILE * and we set the values such that we always
force a function call to occur based on their regular logic path.


I guess this is the only way to do it without slowing down the !_REENT_SMALL case. However consider:

#include <stdio.h>
int main()
{
  FILE *foo = stdout;
  fprintf(foo, "Hello World\n");
  if (foo != stdout)
    abort();
  return 0;
}

I find it surprising for this program to abort.


_REENT_SMALL was specifically added for embedded platforms that are extremely tight on storage (some verging on crippled IMO). It should not be used by platforms that just want to save a few bytes. It is not surprising that these platforms can't do everything in a Standard's test bucket (some of them don't even do file I/O). Storing away the standard streams isn't something any reasonable program other than a concocted standard-test is going to do. It certainly won't be found in real code written for such platforms.


I'll start working on the fix.

There are also more subtle bugs that can occur when using the dummy FILE* with the feof, ferror, and clearerr macros.


These macros should be ok. You shouldn't be at EOF since you haven't issued any read and you haven't caused any error to occur prior to the first reference.


-- Jeff J.


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