This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: How to destroy _reent structure
- From: Sebastian Huber <sebastian dot huber at embedded-brains dot de>
- To: newlib at sourceware dot org
- Date: Wed, 24 Apr 2013 13:10:01 +0200
- Subject: Re: How to destroy _reent structure
- References: <5177920B dot 4040100 at embedded-brains dot de> <20130424102604 dot GK26397 at calimero dot vinschen dot de>
Hello Corinna,
On 04/24/2013 12:26 PM, Corinna Vinschen wrote:
On Apr 24 10:04, Sebastian Huber wrote:
Hello,
there is _REENT_INIT_PTR() for initialization, but how can I destroy
a _reent structure. Is this _wrapup_reent()?
Try _reclaim_reent. But it's not the same as _REENT_INIT_PTR since
_REENT_INIT_PTR does not allocate any memory.
Corinna
so for initialization we can use:
struct _reent *p = malloc(sizeof(*p));
if (p != NULL) {
_REENT_INIT_PTR(p);
}
For destruction we can use:
_reclaim_reent(p);
free(p);
What is the purpose of _wrapup_reent()? Its not called from within Newlib and
I don't find a function that can register an atexit handler in a non-global
_reent structure. There is also no public header file for this function.
In RTEMS we currently use this:
static int newlib_free_buffers(
FILE *fp
)
{
switch ( fileno(fp) ) {
case 0:
case 1:
case 2:
if (fp->_flags & __SMBF) {
free( fp->_bf._base );
fp->_flags &= ~__SMBF;
fp->_bf._base = fp->_p = (unsigned char *) NULL;
}
break;
default:
fclose(fp);
}
return 0;
}
void newlib_delete_hook(
rtems_tcb *current_task,
rtems_tcb *deleted_task
)
{
struct _reent *ptr;
ptr = deleted_task->libc_reent;
deleted_task->libc_reent = NULL;
/*
* Just in case there are some buffers lying around.
*/
_fwalk(ptr, newlib_free_buffers);
_Workspace_Free(ptr);
}
So this looks pretty wrong.
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschÃftliche Mitteilung im Sinne des EHUG.