Hi Shaobo,

On Nov 10 12:15, Shaobo Song wrote:
> This commit revises `pthread_cleanup_push` and `pthread_cleanup_pop` macros to
> use a `do { ... } while(0)` wrapper, preventing syntax errors when used in
> certain contexts. The original code could fail when they are wrapped within a
> `do { ... } while(0)`, causing unintended behavior or compilation issues.
> Example of error:
> 
>   #include <pthread.h>
> 
>   #define pthread_cleanup_push_wrapper(_fn, _arg) do { \
>     pthread_cleanup_push(_fn, _arg); \
>   } while (0)
> 
>   #define pthread_cleanup_pop_wrapper(_execute) do { \
>     pthread_cleanup_pop(_execute); \
>   } while (0)
> 
>   void cleanup_fn (void *arg) {}
> 
>   void *thread_func (void *arg)
>   {
>     pthread_cleanup_push_wrapper(cleanup_fn, NULL);
>     pthread_cleanup_pop_wrapper(1);
>     return NULL;
>   }
> 
>   int main (int argc, char **argv) {
>     pthread_t thread_id;
>     pthread_create(&thread_id, NULL, thread_func, NULL);
>   }
> 
> This would fail due to unmatched braces in the macro expansion. The new
> structure ensures the macro expands correctly in all cases.
> 
> Signed-off-by: Shaobo Song <shnusongsha...@gmail.com>

Thanks for the patch. Pushed with an extra "Fixes" line in the
commit message to main and cygwin-3_5-branch.


Corinna

Reply via email to