2007-03-08 04:03:40 +08:00
|
|
|
/**************************************************************************
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
**************************************************************************/
|
|
|
|
#include "freelist.h"
|
|
|
|
|
|
|
|
#include <memory.h>
|
|
|
|
|
2009-06-03 06:11:51 +08:00
|
|
|
#include "danerror.h"
|
|
|
|
#include "memry.h"
|
|
|
|
#include "tprintf.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* memalloc
|
|
|
|
*
|
|
|
|
* Memory allocator with protection.
|
|
|
|
**********************************************************************/
|
|
|
|
int *memalloc(int size) {
|
2009-06-03 06:11:51 +08:00
|
|
|
return ((int *) alloc_mem (size));
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* memrealloc
|
|
|
|
*
|
|
|
|
* Memory allocator with protection.
|
|
|
|
**********************************************************************/
|
|
|
|
int *memrealloc(void *ptr, int size, int oldsize) {
|
|
|
|
int shiftsize;
|
|
|
|
int *newbuf;
|
|
|
|
|
|
|
|
shiftsize = size > oldsize ? oldsize : size;
|
2009-06-03 06:11:51 +08:00
|
|
|
newbuf = (int *) alloc_mem (size);
|
2007-03-08 04:03:40 +08:00
|
|
|
memcpy(newbuf, ptr, shiftsize);
|
2009-06-03 06:11:51 +08:00
|
|
|
free_mem(ptr);
|
2007-03-08 04:03:40 +08:00
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* memfree
|
|
|
|
*
|
|
|
|
* Memory allocator with protection.
|
|
|
|
**********************************************************************/
|
|
|
|
void memfree(void *element) {
|
|
|
|
if (element) {
|
2009-06-03 06:11:51 +08:00
|
|
|
free_mem(element);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* mem_tidy
|
|
|
|
*
|
|
|
|
* Do nothing.
|
|
|
|
**********************************************************************/
|
|
|
|
void mem_tidy(int level) {
|
2009-06-03 06:11:51 +08:00
|
|
|
check_mem ("Old tidy", level);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|