Problem with recent change to getlocalename_l

Torbjorn SVENSSON torbjorn.svensson@foss.st.com
Thu Feb 1 20:55:50 GMT 2024



On 2024-02-01 20:11, Corinna Vinschen wrote:
> No, wait.
> 
> On Feb  1 20:00, Corinna Vinschen wrote:
>> Given that this new functionality needs a 32 byte buffer, and given that
>> _REENT_SMALL targets are... well... small, I made the new buffer
>> optional via `#ifdef _MB_CAPABLE' in struct _misc_reent, which only used
>> by _REENT_SMALL targets.
>>
>> Apparently I missed to take the _REENT_CHECK_MISC expression into account.
>> AFAICS the culprit is the _REENT_INIT_MISC macro now.
>>
>> Can you please check if this change fixes the problem?
> 
> Try this one instead, please:
> 
> diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
> index 4e60c3096ae2..1fd503b9a699 100644
> --- a/newlib/libc/include/sys/reent.h
> +++ b/newlib/libc/include/sys/reent.h
> @@ -514,8 +514,8 @@ struct _reent
>   #define _REENT_CHECK_EMERGENCY(var) \
>     _REENT_CHECK(var, _emergency, char *, _REENT_EMERGENCY_SIZE, /* nothing */)
>   
> -#define _REENT_INIT_MISC(var) do { \
> -  struct _reent *_r = (var); \
> +/* Do not call directly, use _REENT_INIT_MISC(var) instead */

Maybe do an #undef after the _REENT_INIT_MISC has been define to prevent 
the __REENT_INIT_MISC_BODY symbol to be visible outside this block would 
work here?

> +#define __REENT_INIT_MISC_BODY(_r) \
>     _r->_misc->_strtok_last = _NULL; \
>     _r->_misc->_mblen_state.__count = 0; \
>     _r->_misc->_mblen_state.__value.__wch = 0; \
> @@ -533,10 +533,20 @@ struct _reent
>     _r->_misc->_wcrtomb_state.__value.__wch = 0; \
>     _r->_misc->_wcsrtombs_state.__count = 0; \
>     _r->_misc->_wcsrtombs_state.__value.__wch = 0; \
> -  _r->_misc->_getlocale_l_buf[0] = '\0'; \
>     _r->_misc->_l64a_buf[0] = '\0'; \
> -  _r->_misc->_getdate_err = 0; \
> +  _r->_misc->_getdate_err = 0;
> +#ifdef _MB_CAPABLE
> +#define _REENT_INIT_MISC(var) do { \
> +  struct _reent *_r = (var); \
> +  __REENT_INIT_MISC_BODY(_r) \
> +  _r->_misc->_getlocale_l_buf[0] = '\0'; \
> +} while (0)
> +#else
> +#define _REENT_INIT_MISC(var) do { \
> +  struct _reent *_r = (var); \
> +  __REENT_INIT_MISC_BODY(_r) \
>   } while (0)
> +#endif

Something like this here:

#undef __REENT_INIT_MISC_BODY

>   #define _REENT_CHECK_MISC(var) \
>     _REENT_CHECK(var, _misc, struct _misc_reent *, sizeof *((var)->_misc), _REENT_INIT_MISC(var))
>   
> 


More information about the Newlib mailing list