+/*-------------------------------------------------------------------------
+ free.c - release allocated memory.
+
+ Copyright (C) 2004 - Maarten Brock, sourceforge.brock@dse.nl
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+-------------------------------------------------------------------------*/
+
#include <sdcc-lib.h>
#include <malloc.h>
+#if defined(SDCC_STACK_AUTO) || defined(SDCC_z80) || defined(SDCC_gbz80)
+ #define CRITICAL critical
+#else
+ #define CRITICAL
+#endif
+
#if _SDCC_MALLOC_TYPE_MLH
typedef struct _MEMHEADER MEMHEADER;
MEMHEADER *prev_header, *pthis;
if ( p ) //For allocated pointers only!
+ CRITICAL
{
pthis = (MEMHEADER * )((char *) p - HEADER_SIZE); //to start of header
if ( pthis->prev ) // For the regular header
register MEMHEADER xdata * cur_header;
if (!p)
- return NULL;
+ return NULL;
pthis = (MEMHEADER xdata *) p;
pthis -= 1; //to start of header
cur_header = _sdcc_first_memheader;
_sdcc_prev_memheader = NULL;
while (cur_header && pthis != cur_header)
- {
- _sdcc_prev_memheader = cur_header;
- cur_header = cur_header->next;
- }
+ {
+ _sdcc_prev_memheader = cur_header;
+ cur_header = cur_header->next;
+ }
return (cur_header);
}
{
register MEMHEADER xdata * pthis;
- pthis = _sdcc_find_memheader(p);
- if (pthis) //For allocated pointers only!
+ CRITICAL
{
- if (!_sdcc_prev_memheader)
- {
- pthis->len = 0;
- }
- else
+ pthis = _sdcc_find_memheader(p);
+ if (pthis) //For allocated pointers only!
{
- _sdcc_prev_memheader->next = pthis->next;
+ if (!_sdcc_prev_memheader)
+ {
+ pthis->len = 0;
+ }
+ else
+ {
+ _sdcc_prev_memheader->next = pthis->next;
+ }
}
}
}