mirror of
https://github.com/lua/lua
synced 2024-12-27 12:49:43 +03:00
"luaI_malloc(s)" is just a macro to "luaI_realloc(NULL, s)".
This commit is contained in:
parent
29f0021837
commit
f9deeac632
25
luamem.c
25
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;
|
||||
}
|
||||
|
||||
|
||||
|
4
luamem.h
4
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) \
|
||||
|
Loading…
Reference in New Issue
Block a user