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!

On 2025-07-16T22:45:39+0530, Arijit Kumar Das <[email protected]> wrote:
> On Wed, Jul 16, 2025 at 1:17 PM Thomas Schwinge <[email protected]> wrote:
>> 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

No, in the (generic) 'newlib/libc/include/sys/config.h', you should use
'_ssize_t' and '__size_t'.  It won't make a difference in practice, but
for consistency.

>> [...] let's
>> first sort out the '_READ_WRITE_RETURN_TYPE', '_READ_WRITE_BUFSIZE_TYPE'
>> thing, [...]
>
> 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)?

Do not include your new code yet, just update:

> 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.

... these to 'ssize_t' return type.


Grüße
 Thomas
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.