[PATCH] nvptx: Add _ssize_t as _READ_WRITE_RETURN_TYPE in newlib/libc/include/sys/config.h

Arijit Kumar Das arijitkdgit.official@gmail.com
Wed Jul 16 17:15:39 GMT 2025


Hi Thomas!

On Wed, Jul 16, 2025 at 1:17 PM Thomas Schwinge <tschwinge@baylibre.com> wrote:

> > Okay, so I change it directly to ssize_t instead of _ssize_t?
> > (Actually, I followed the convention
> > of the other #define -s for _READ_WRITE_RETURN_TYPE from config.h).
>
> I've not researched all the context/history here, but usually it goes
> similar to this:
>
> Generic code (for example: 'newlib/libc/include/sys/config.h',
> 'newlib/libc/stdio/stdio.c'), which has to work for all possible newlib
> targets/configurations, is often using some indirections/abstractions
> (for example: '_ssize_t' corresponding to the actual 'ssize_t', or
> '_READ_WRITE_RETURN_TYPE' corresponding to the actual 'read', 'write'
> return type), so that certain targets/configurations are able to "fix up
> things" if necessary.
>
> In contrast, the target-specific implementations (for example:
> 'newlib/libc/machine/nvptx/write.c') can directly use the actual types
> (for example: 'ssize_t' instead of '_ssize_t' or
> '_READ_WRITE_RETURN_TYPE'); they (mostly) don't need the
> indirections/abstractions, as they define (implement) code for the actual
> target/configuration.
>

Got it! I'll be sending the patch soon. Here's what I'll add to config.h:

#ifdef __nvptx__
#define _READ_WRITE_RETURN_TYPE    ssize_t
#define _READ_WRITE_BUFSIZE_TYPE    size_t

Does that look good?


>
> > Another thing which I was thinking is that, now that my work in
> > newlib/libc/machine/nvptx/misc.c
> > is functional (albeit, not optimized or following some expected
> > standards per se) could I add this
> > one too, in my commit? That doesn't break the build, adds some
> > functionality, and I can still
> > continue working on it and sending my commits without breaking stuff.
>
> :-) I understand you're eager to get your new code out there, but let's
> first sort out the '_READ_WRITE_RETURN_TYPE', '_READ_WRITE_BUFSIZE_TYPE'
> thing, and then continue to work on the new code some more, test it
> properly (via the GCC test suite, for example), and clean it up, etc.
> We'll get there.  :-)
>

Alright! But can I also update the function signatures in write.c and misc.c to
_READ_WRITE_RETURN_TYPE and _READ_WRITE_BUFSIZE_TYPE
wherever applicable and leave the rest of the things as it is (i.e. not include
my filesystem code yet)? Otherwise the function signatures for read()
and write()
become different since write() uses_READ_WRITE_RETURN_TYPE and
read() uses int which can cause a run time CUDA error.

Let me know what do you think and I'll be glad to send my first commit
to be merged :-)

Best regards,
Arijit


More information about the Newlib mailing list