diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-01-14 13:40:26 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-01-14 13:40:26 -0200 |
| commit | f4591397da8444d1917a67a34cb6a6ac8137385e (patch) | |
| tree | 749a23af6964bee4a373aecf13f3cdfcda8656f0 | |
| parent | 8faf4d1de2cbda61ae871fc23091deff3672e0fc (diff) | |
| download | lua-f4591397da8444d1917a67a34cb6a6ac8137385e.tar.gz lua-f4591397da8444d1917a67a34cb6a6ac8137385e.tar.bz2 lua-f4591397da8444d1917a67a34cb6a6ac8137385e.zip | |
strdup is done via mem.c to control its memory allocation
| -rw-r--r-- | lua.stx | 4 | ||||
| -rw-r--r-- | luamem.c | 9 | ||||
| -rw-r--r-- | luamem.h | 4 | ||||
| -rw-r--r-- | strlib.c | 6 | ||||
| -rw-r--r-- | table.c | 4 |
5 files changed, 18 insertions, 9 deletions
| @@ -1,6 +1,6 @@ | |||
| 1 | %{ | 1 | %{ |
| 2 | 2 | ||
| 3 | char *rcs_luastx = "$Id: lua.stx,v 3.15 1994/12/27 20:04:29 celes Exp celes $"; | 3 | char *rcs_luastx = "$Id: lua.stx,v 3.16 1994/12/27 20:41:11 celes Exp roberto $"; |
| 4 | 4 | ||
| 5 | #include <stdio.h> | 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
| @@ -237,7 +237,7 @@ static void init_function (TreeNode *func) | |||
| 237 | if (lua_debug) | 237 | if (lua_debug) |
| 238 | { | 238 | { |
| 239 | code_byte(SETFUNCTION); | 239 | code_byte(SETFUNCTION); |
| 240 | code_code((Byte *)strdup(lua_file[lua_nfile-1])); | 240 | code_code((Byte *)luaI_strdup(lua_file[lua_nfile-1])); |
| 241 | code_word(luaI_findconstant(func)); | 241 | code_word(luaI_findconstant(func)); |
| 242 | } | 242 | } |
| 243 | } | 243 | } |
| @@ -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.2 1994/11/16 18:09:11 roberto Stab $"; | 6 | char *rcs_mem = "$Id: mem.c,v 1.3 1994/12/20 21:20:36 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | 9 | ||
| @@ -34,3 +34,10 @@ void *luaI_realloc (void *oldblock, unsigned long size) | |||
| 34 | return block; | 34 | return block; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | |||
| 38 | char *luaI_strdup (char *str) | ||
| 39 | { | ||
| 40 | char *newstr = luaI_malloc(strlen(str)+1); | ||
| 41 | strcpy(newstr, str); | ||
| 42 | return newstr; | ||
| 43 | } | ||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** mem.c | 2 | ** mem.c |
| 3 | ** memory manager for lua | 3 | ** memory manager for lua |
| 4 | ** $Id: $ | 4 | ** $Id: mem.h,v 1.1 1994/11/16 17:38:08 roberto Stab roberto $ |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #ifndef mem_h | 7 | #ifndef mem_h |
| @@ -15,6 +15,8 @@ void luaI_free (void *block); | |||
| 15 | void *luaI_malloc (unsigned long size); | 15 | void *luaI_malloc (unsigned long size); |
| 16 | void *luaI_realloc (void *oldblock, unsigned long size); | 16 | void *luaI_realloc (void *oldblock, unsigned long size); |
| 17 | 17 | ||
| 18 | char *luaI_strdup (char *str); | ||
| 19 | |||
| 18 | #define new(s) ((s *)luaI_malloc(sizeof(s))) | 20 | #define new(s) ((s *)luaI_malloc(sizeof(s))) |
| 19 | #define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) | 21 | #define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) |
| 20 | #define growvector(old,n,s) ((s *)luaI_realloc(old,(n)*sizeof(s))) | 22 | #define growvector(old,n,s) ((s *)luaI_realloc(old,(n)*sizeof(s))) |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** String library to LUA | 3 | ** String library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_strlib="$Id: strlib.c,v 1.7 1994/12/16 15:53:57 roberto Exp roberto $"; | 6 | char *rcs_strlib="$Id: strlib.c,v 1.8 1995/01/06 20:31:10 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | #include <ctype.h> | 9 | #include <ctype.h> |
| @@ -109,7 +109,7 @@ static void str_lower (void) | |||
| 109 | lua_Object o = lua_getparam (1); | 109 | lua_Object o = lua_getparam (1); |
| 110 | if (!lua_isstring(o)) | 110 | if (!lua_isstring(o)) |
| 111 | lua_error ("incorrect arguments to function `strlower'"); | 111 | lua_error ("incorrect arguments to function `strlower'"); |
| 112 | c = s = strdup(lua_getstring(o)); | 112 | c = s = luaI_strdup(lua_getstring(o)); |
| 113 | while (*c != 0) | 113 | while (*c != 0) |
| 114 | { | 114 | { |
| 115 | *c = tolower(*c); | 115 | *c = tolower(*c); |
| @@ -131,7 +131,7 @@ static void str_upper (void) | |||
| 131 | lua_Object o = lua_getparam (1); | 131 | lua_Object o = lua_getparam (1); |
| 132 | if (!lua_isstring(o)) | 132 | if (!lua_isstring(o)) |
| 133 | lua_error ("incorrect arguments to function `strlower'"); | 133 | lua_error ("incorrect arguments to function `strlower'"); |
| 134 | c = s = strdup(lua_getstring(o)); | 134 | c = s = luaI_strdup(lua_getstring(o)); |
| 135 | while (*c != 0) | 135 | while (*c != 0) |
| 136 | { | 136 | { |
| 137 | *c = toupper(*c); | 137 | *c = toupper(*c); |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Module to control static tables | 3 | ** Module to control static tables |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_table="$Id: table.c,v 2.25 1994/12/20 21:20:36 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.26 1995/01/12 14:19:04 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | 9 | ||
| @@ -197,7 +197,7 @@ char *lua_addfile (char *fn) | |||
| 197 | { | 197 | { |
| 198 | if (lua_nfile >= MAXFILE) | 198 | if (lua_nfile >= MAXFILE) |
| 199 | return "too many files"; | 199 | return "too many files"; |
| 200 | if ((lua_file[lua_nfile++] = strdup (fn)) == NULL) | 200 | if ((lua_file[lua_nfile++] = luaI_strdup (fn)) == NULL) |
| 201 | return "not enough memory"; | 201 | return "not enough memory"; |
| 202 | return NULL; | 202 | return NULL; |
| 203 | } | 203 | } |
