_reclaim_reent and _REENT_SMALL

Corinna Vinschen vinschen@redhat.com
Mon Mar 9 12:36:00 GMT 2009

On Mar  6 11:25, Hans-Erik Floryd wrote:
> [...]
> There is no check that ptr->_atexit is not NULL. The attached patch  
> fixes this also.

Thanks for these patches.  I've check them in.

> However, I am not sure I understand how atexit works for  
> __DYNAMIC_REENT__. The code in _wrapup_reent calls all registered exit  
> procedures in the given reent structure, but __register_exitproc always  
> works on the _GLOBAL_REENT structure. So how does a thread register its  
> own exit function?

This one I can't answer.  Anybody?

> Having been unable to register an exit procedure for a thread I am  
> unsure of the following, but this code in _wrapup_reent also seems  
> questionable:
>   register struct _atexit *p;
> #ifdef _REENT_SMALL
>   for (p = &ptr->_atexit, n = p->_ind; --n >= 0;)
>     (*p->_fns[n]) ();
> #else
> This gives a warning when compiling:
> ../../../../../../newlib-1.16.0/newlib/libc/reent/reent.c:139: warning:  
> assignment from incompatible pointer type
> which is because the type of &ptr->_atexit is struct _atexit **, whereas  
> p is just struct _atexit *. When evaluating p->_ind, wouldn't you get  
> the value of some other member in the reent structure? I suspect  
> something like this
>   if (ptr->_atexit)
>   {
>     for (p = ptr->_atexit, n = p->_ind; --n >= 0;)
>       (*p->_fns[n]) ();
>   }
> would work better but as I said I haven't been able to investigate if  
> this works or if there really is a problem here.

I assume it's a typo and so the code accidentally accessed _atexit
instead of _atexit0.  That would explain the ampersand.  But OTOH that
would disallow to install an _atexit pointer different from _atexit0.
Maybe Jeff can answer that when he's back from vacation.  Until then,
I'll apply a preliminary patch which checks for _atexit, like this:

  for (p = ptr->_atexit, n = p ? p->_ind : 0; --n >= 0;)


Corinna Vinschen
Cygwin Project Co-Leader
Red Hat

More information about the Newlib mailing list