mirror of https://github.com/rusefi/lua.git
free(b) is equivalent to realloc(b, 0)
This commit is contained in:
parent
72a1d81b51
commit
1d7857bc63
8
luamem.c
8
luamem.c
|
@ -3,7 +3,7 @@
|
||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_luamem = "$Id: luamem.c,v 1.15 1997/03/31 14:17:09 roberto Exp roberto $";
|
char *rcs_luamem = "$Id: luamem.c,v 1.16 1997/04/01 21:23:20 roberto Exp $";
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ char *rcs_luamem = "$Id: luamem.c,v 1.15 1997/03/31 14:17:09 roberto Exp roberto
|
||||||
|
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
|
|
||||||
void luaI_free (void *block)
|
static void lfree (void *block)
|
||||||
{
|
{
|
||||||
if (block)
|
if (block)
|
||||||
{
|
{
|
||||||
|
@ -31,6 +31,10 @@ void *luaI_realloc (void *oldblock, unsigned long size)
|
||||||
size_t s = (size_t)size;
|
size_t s = (size_t)size;
|
||||||
if (s != size)
|
if (s != size)
|
||||||
lua_error("Allocation Error: Block too big");
|
lua_error("Allocation Error: Block too big");
|
||||||
|
if (size == 0) { /* ANSI doen't need this, but some machines... */
|
||||||
|
lfree(oldblock);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
block = oldblock ? realloc(oldblock, s) : malloc(s);
|
block = oldblock ? realloc(oldblock, s) : malloc(s);
|
||||||
if (block == NULL)
|
if (block == NULL)
|
||||||
lua_error(memEM);
|
lua_error(memEM);
|
||||||
|
|
4
luamem.h
4
luamem.h
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
** mem.c
|
** mem.c
|
||||||
** memory manager for lua
|
** memory manager for lua
|
||||||
** $Id: luamem.h,v 1.9 1997/03/31 14:10:11 roberto Exp roberto $
|
** $Id: luamem.h,v 1.10 1997/07/29 20:38:45 roberto Exp roberto $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef luamem_h
|
#ifndef luamem_h
|
||||||
|
@ -23,12 +23,12 @@
|
||||||
#define memEM "not enough memory"
|
#define memEM "not enough memory"
|
||||||
|
|
||||||
|
|
||||||
void luaI_free (void *block);
|
|
||||||
void *luaI_realloc (void *oldblock, unsigned long size);
|
void *luaI_realloc (void *oldblock, unsigned long size);
|
||||||
void *luaI_buffer (unsigned long size);
|
void *luaI_buffer (unsigned long size);
|
||||||
int luaI_growvector (void **block, unsigned long nelems, int size,
|
int luaI_growvector (void **block, unsigned long nelems, int size,
|
||||||
char *errormsg, unsigned long limit);
|
char *errormsg, unsigned long limit);
|
||||||
|
|
||||||
|
#define luaI_free(b) luaI_realloc((b), 0)
|
||||||
#define luaI_malloc(s) luaI_realloc(NULL, (s))
|
#define luaI_malloc(s) luaI_realloc(NULL, (s))
|
||||||
#define new(s) ((s *)luaI_malloc(sizeof(s)))
|
#define new(s) ((s *)luaI_malloc(sizeof(s)))
|
||||||
#define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s)))
|
#define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s)))
|
||||||
|
|
Loading…
Reference in New Issue