diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-05-24 11:31:10 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-05-24 11:31:10 -0300 |
commit | f9deeac632ce1f6637bbfc1ccaddb08641082568 (patch) | |
tree | 79c4dfe5d9935ce0a50ec546140985aad0996147 | |
parent | 29f0021837b9e4f5624806e03ef493ec488ea114 (diff) | |
download | lua-f9deeac632ce1f6637bbfc1ccaddb08641082568.tar.gz lua-f9deeac632ce1f6637bbfc1ccaddb08641082568.tar.bz2 lua-f9deeac632ce1f6637bbfc1ccaddb08641082568.zip |
"luaI_malloc(s)" is just a macro to "luaI_realloc(NULL, s)".
-rw-r--r-- | luamem.c | 25 | ||||
-rw-r--r-- | luamem.h | 4 |
2 files changed, 10 insertions, 19 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_mem = "$Id: mem.c,v 1.11 1996/03/21 18:54:29 roberto Exp roberto $"; | 6 | char *rcs_mem = "$Id: mem.c,v 1.12 1996/05/06 16:59:00 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | 9 | ||
@@ -11,9 +11,6 @@ char *rcs_mem = "$Id: mem.c,v 1.11 1996/03/21 18:54:29 roberto Exp roberto $"; | |||
11 | #include "lua.h" | 11 | #include "lua.h" |
12 | 12 | ||
13 | 13 | ||
14 | #define mem_error() lua_error(memEM) | ||
15 | |||
16 | |||
17 | void luaI_free (void *block) | 14 | void luaI_free (void *block) |
18 | { | 15 | { |
19 | if (block) | 16 | if (block) |
@@ -24,21 +21,15 @@ void luaI_free (void *block) | |||
24 | } | 21 | } |
25 | 22 | ||
26 | 23 | ||
27 | void *luaI_malloc (unsigned long size) | ||
28 | { | ||
29 | void *block = malloc((size_t)size); | ||
30 | if (block == NULL) | ||
31 | mem_error(); | ||
32 | return block; | ||
33 | } | ||
34 | |||
35 | |||
36 | void *luaI_realloc (void *oldblock, unsigned long size) | 24 | void *luaI_realloc (void *oldblock, unsigned long size) |
37 | { | 25 | { |
38 | void *block = oldblock ? realloc(oldblock, (size_t)size) : | 26 | void *block; |
39 | malloc((size_t)size); | 27 | size_t s = (size_t)size; |
28 | if (s != size) | ||
29 | lua_error("Allocation Error: Block too big"); | ||
30 | block = oldblock ? realloc(oldblock, s) : malloc(s); | ||
40 | if (block == NULL) | 31 | if (block == NULL) |
41 | mem_error(); | 32 | lua_error(memEM); |
42 | return block; | 33 | return block; |
43 | } | 34 | } |
44 | 35 | ||
@@ -52,7 +43,7 @@ int luaI_growvector (void **block, unsigned long nelems, int size, | |||
52 | if (nelems > limit) | 43 | if (nelems > limit) |
53 | nelems = limit; | 44 | nelems = limit; |
54 | *block = luaI_realloc(*block, nelems*size); | 45 | *block = luaI_realloc(*block, nelems*size); |
55 | return (int) nelems; | 46 | return (int)nelems; |
56 | } | 47 | } |
57 | 48 | ||
58 | 49 | ||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | ** mem.c | 2 | ** mem.c |
3 | ** memory manager for lua | 3 | ** memory manager for lua |
4 | ** $Id: mem.h,v 1.6 1996/03/21 18:54:29 roberto Exp roberto $ | 4 | ** $Id: mem.h,v 1.7 1996/04/22 18:00:37 roberto Exp roberto $ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef mem_h | 7 | #ifndef mem_h |
@@ -24,12 +24,12 @@ | |||
24 | 24 | ||
25 | 25 | ||
26 | void luaI_free (void *block); | 26 | void luaI_free (void *block); |
27 | void *luaI_malloc (unsigned long size); | ||
28 | void *luaI_realloc (void *oldblock, unsigned long size); | 27 | void *luaI_realloc (void *oldblock, unsigned long size); |
29 | void *luaI_buffer (unsigned long size); | 28 | void *luaI_buffer (unsigned long size); |
30 | int luaI_growvector (void **block, unsigned long nelems, int size, | 29 | int luaI_growvector (void **block, unsigned long nelems, int size, |
31 | char *errormsg, unsigned long limit); | 30 | char *errormsg, unsigned long limit); |
32 | 31 | ||
32 | #define luaI_malloc(s) luaI_realloc(NULL, (s)) | ||
33 | #define new(s) ((s *)luaI_malloc(sizeof(s))) | 33 | #define new(s) ((s *)luaI_malloc(sizeof(s))) |
34 | #define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) | 34 | #define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) |
35 | #define growvector(old,n,s,e,l) \ | 35 | #define growvector(old,n,s,e,l) \ |