Re: [PATCH] nvptx: Add _ssize_t as _READ_WRITE_RETURN_TYPE in newlib/libc/include/sys/config.h
Thomas Schwinge <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
Hi Arijit! Thanks for looking into this! On 2025-07-14T08:11:41+0530, Arijit Kumar Das via Newlib <[email protected]> wrote: > --- a/newlib/libc/include/sys/config.h > +++ b/newlib/libc/include/sys/config.h > @@ -12,6 +12,10 @@ > #define __DYNAMIC_REENT__ > #endif > > +#ifdef __nvptx__ > +#define _READ_WRITE_RETURN_TYPE _ssize_t > +#endif > + > /* exceptions first */ > #if defined(__H8500__) || defined(__W65__) > #define __SMALL_BITFIELDS I did wonder why placing this new '#define' here is a good choice -- but then, I've just looked at the current 'config.h' file, and found that placement of most of its content appears to be rather disorganized, so this placement here indeed should be as good as (almost) any other. (We shall of course be happy to hear from the newlib maintainers, if they've got any better advice.) But: won't that change in isolation break the build, or at least warn, given that we've still got 'newlib/libc/machine/nvptx/misc.c': int read(int fd, void *buf, size_t count) { ..., that is, 'int' instead of the desire 'ssize_t' return type? In 'newlib/libc/machine/nvptx/write.c' we have: _READ_WRITE_RETURN_TYPE write (int fd, const void *buf, size_t count) { Apparently, there isn't any diagnostic about the 'int' vs. 'ssize_t' for 'read', but I suggest that you change the return types of both 'read' and 'write' to the actual type, 'ssize_t'. (Actually, I don't see any '-W[...]' flags get used for an combined-tree GCC/newlib build, huh...) Another thing I've now noticed: nvptx' 'read' and 'write' implementations correctly use 'size_t count' (see cited above) -- but in 'config.h', as far as I can tell, we use the default 'int': /* Define `count' parameter of read/write routines. In POSIX, the `count' parameter is "size_t" but legacy newlib code has been using "int" for some time. If not specified, "int" is defaulted. */ #ifndef _READ_WRITE_BUFSIZE_TYPE #define _READ_WRITE_BUFSIZE_TYPE int #endif I suggest that for nvptx, next to your new '_READ_WRITE_RETURN_TYPE', you also add '#define _READ_WRITE_BUFSIZE_TYPE __size_t' (double underscore, per 'newlib/libc/include/sys/_types.h'), what do you think? (I'm slightly confused, as no configuration apart from Cygwin, 'winsup/cygwin/include/cygwin/config.h', appears to be doing this, but it still seems the right thing to do?) Make that either an additional commit, or as part of this one, as you like. I'll meanwhile test all this, too. Grüße Thomas