commit f9deeac632ce1f6637bbfc1ccaddb08641082568
parent 29f0021837b9e4f5624806e03ef493ec488ea114
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 24 May 1996 11:30:50 -0300
"luaI_malloc(s)" is just a macro to "luaI_realloc(NULL, s)".
Diffstat:
2 files changed, 10 insertions(+), 19 deletions(-)
diff --git a/luamem.c b/luamem.c
@@ -3,7 +3,7 @@
** 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>
@@ -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"
-#define mem_error() lua_error(memEM)
-
-
void luaI_free (void *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 *block = oldblock ? realloc(oldblock, (size_t)size) :
- malloc((size_t)size);
+ void *block;
+ 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)
- mem_error();
+ lua_error(memEM);
return block;
}
@@ -52,7 +43,7 @@ int luaI_growvector (void **block, unsigned long nelems, int size,
if (nelems > limit)
nelems = limit;
*block = luaI_realloc(*block, nelems*size);
- return (int) nelems;
+ return (int)nelems;
}
diff --git a/luamem.h b/luamem.h
@@ -1,7 +1,7 @@
/*
** mem.c
** 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
@@ -24,12 +24,12 @@
void luaI_free (void *block);
-void *luaI_malloc (unsigned long size);
void *luaI_realloc (void *oldblock, unsigned long size);
void *luaI_buffer (unsigned long size);
int luaI_growvector (void **block, unsigned long nelems, int size,
char *errormsg, unsigned long limit);
+#define luaI_malloc(s) luaI_realloc(NULL, (s))
#define new(s) ((s *)luaI_malloc(sizeof(s)))
#define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s)))
#define growvector(old,n,s,e,l) \