dmalloc icon indicating copy to clipboard operation
dmalloc copied to clipboard

Remove the buffer argument from loc_getenv

Open xiaoxiang781216 opened this issue 4 years ago • 7 comments

1.Avoid to allocate the big buffer on the caller stack 2.The temporary buffer is only used on cygwin

xiaoxiang781216 avatar Apr 15 '21 17:04 xiaoxiang781216

@j256 we are porting dmalloc to RTOS environment, it's critical to reduce the stack consumption as much as possbile.

xiaoxiang781216 avatar Apr 15 '21 17:04 xiaoxiang781216

Thanks for this. Can you instead make the change where it is used. So revert the changes to loc_compat.[ch] and user_malloc.[ch] and make the dmalloc_t.c, dmalloc.c, dmalloc_argv.c, and user_malloc.c define it statically? Then it is up to the caller to ensure that we are in single thread mode.

j256 avatar Apr 15 '21 22:04 j256

Since the buffer is only needed for cygwin, it isn't good to expose the buffer allocation outside loc_getenv to pollute other platform. I I add __thread to make buf become per thread, could you take a look?

xiaoxiang781216 avatar Apr 17 '21 19:04 xiaoxiang781216

Don't think of portability as polluting. The __thread feels a lot less portable.

j256 avatar Apr 17 '21 20:04 j256

__thread is only used in cygwin, and I test that cygwin's clang and gcc both support __thread. So the portability isn't problem here.

xiaoxiang781216 avatar Apr 17 '21 20:04 xiaoxiang781216

@j256 I fix the problem by macro to avoid __thread, please review again.

xiaoxiang781216 avatar Apr 19 '21 12:04 xiaoxiang781216

@j256 could you take time to review my patch?

xiaoxiang781216 avatar Jun 27 '21 11:06 xiaoxiang781216