1
0
mirror of https://github.com/lua/lua.git synced 2025-01-14 05:43:00 +08:00

"luaI_malloc(s)" is just a macro to "luaI_realloc(NULL, s)".

This commit is contained in:
Roberto Ierusalimschy 1996-05-24 11:31:10 -03:00
parent 29f0021837
commit f9deeac632
2 changed files with 10 additions and 19 deletions

View File

@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** TecCGraf - PUC-Rio
*/ */
char *rcs_mem = "$Id: mem.c,v 1.11 1996/03/21 18:54:29 roberto Exp roberto $"; char *rcs_mem = "$Id: mem.c,v 1.12 1996/05/06 16:59:00 roberto Exp roberto $";
#include <stdlib.h> #include <stdlib.h>
@ -11,9 +11,6 @@ char *rcs_mem = "$Id: mem.c,v 1.11 1996/03/21 18:54:29 roberto Exp roberto $";
#include "lua.h" #include "lua.h"
#define mem_error() lua_error(memEM)
void luaI_free (void *block) void luaI_free (void *block)
{ {
if (block) if (block)
@ -24,21 +21,15 @@ void luaI_free (void *block)
} }
void *luaI_malloc (unsigned long size)
{
void *block = malloc((size_t)size);
if (block == NULL)
mem_error();
return block;
}
void *luaI_realloc (void *oldblock, unsigned long size) void *luaI_realloc (void *oldblock, unsigned long size)
{ {
void *block = oldblock ? realloc(oldblock, (size_t)size) : void *block;
malloc((size_t)size); size_t s = (size_t)size;
if (s != size)
lua_error("Allocation Error: Block too big");
block = oldblock ? realloc(oldblock, s) : malloc(s);
if (block == NULL) if (block == NULL)
mem_error(); lua_error(memEM);
return block; return block;
} }
@ -52,7 +43,7 @@ int luaI_growvector (void **block, unsigned long nelems, int size,
if (nelems > limit) if (nelems > limit)
nelems = limit; nelems = limit;
*block = luaI_realloc(*block, nelems*size); *block = luaI_realloc(*block, nelems*size);
return (int) nelems; return (int)nelems;
} }

View File

@ -1,7 +1,7 @@
/* /*
** mem.c ** mem.c
** memory manager for lua ** memory manager for lua
** $Id: mem.h,v 1.6 1996/03/21 18:54:29 roberto Exp roberto $ ** $Id: mem.h,v 1.7 1996/04/22 18:00:37 roberto Exp roberto $
*/ */
#ifndef mem_h #ifndef mem_h
@ -24,12 +24,12 @@
void luaI_free (void *block); void luaI_free (void *block);
void *luaI_malloc (unsigned long size);
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_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)))
#define growvector(old,n,s,e,l) \ #define growvector(old,n,s,e,l) \