Conversation
thiagomacieira
left a comment
There was a problem hiding this comment.
Thank you for the POC, but we're going to need to work on this. The patch cannot be right.
Please start with what error messages you're getting.
| #ifdef __PICOLIBC__ | ||
| static RetType write_to_buffer(void *cookie, const void *data, LenType len) | ||
| #else | ||
| static RetType write_to_buffer(void *cookie, const char *data, LenType len) | ||
| #endif |
There was a problem hiding this comment.
This is the same thing, so you didn't do anything.
There was a problem hiding this comment.
Thank you for response.
Error that I'm facing:
tinycbor/src/open_memstream.c:103:29: error: passing argument 3 of 'funopen' from incompatible pointer type [-Wincompatible-pointer-types]
103 | return funopen(b, NULL, write_to_buffer, NULL, close_buffer);
| ^~~~~~~~~~~~~~~
| |
| RetType (*)(void *, const char *, LenType) {aka int (*)(void *, const char *, int)}
In file included from tinycbor/src/open_memstream.c:31:
picolibc/include/stdio.h:429:28: note: expected '_ssize_t (*)(void *, const void *, size_t)' {aka 'int (*)(void *, const void *, unsigned int)'} but argument is of type 'RetType (*)(void *, const char *, LenType)' {aka 'int (*)(void *, const char *, int)'}
429 | _ssize_t (*writefn)(void *cookie, const void *buf, size_t n),
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The goal is to align signature of tinycbor's write_to_buffer function with picolibc's writefn function signature:
_ssize_t (*writefn)(void *cookie, const void *buf, size_t n)In my POC, for __PICOLIBC__, I've set:
RetTypeto bessize_tLenTypeto besize_t
With that I'm still getting error of signature mismatch since second parameter (data) of tinycbor's function write_to_buffer is type of const char* but picolibc expects that param to be type ofconst void*. I've fixed that with this:
+ #ifdef __PICOLIBC__
+ static RetType write_to_buffer(void *cookie, const void *data, LenType len)
+ #else
static RetType write_to_buffer(void *cookie, const char *data, LenType len)
+ #endif^ you can see there that type of second parameter is changed from const char* to const void* for picolibc.
Maybe we need new DataType beside RetType and LenType to make open_memstream.c more scalable?
Hope I've explain it better this time.
There was a problem hiding this comment.
Ok, I see the problem: for BSD systems (including Apple's macOS), funopen's callback functions take a const char * second parameter, but in picolibc, it's const void *. I suppose that makes sense, as we could be writing binary data through fwrite and such. However, this is very stupid of picolibc to mismatch the API: if you're trying to implement the API that 4.4 BSD introduced, it should match the signature.
To fix this, we need to update the CMakeLists.txt test to do more than check_symbol_exists:
Lines 133 to 135 in 6442e74
We need a compile check that we are matching the arguments correctly, to be able to match the two variants.
With current
HAVE_OPEN_FUNOPENandHAVE_OPEN_FOPENCOOKIEdefines i can not configuresrc/open_memstream.cto work with picolibc's version offunopen.This PR is just POC (i'm sure there is a cleaner way) how to configure it to work.
picolibc is default libc for espressif's esp-idf from version 6 so it's going to be used there a lot so it would be cool if tinycbor could support picolibc somehow as well.