lua

A copy of the Lua development repository
Log | Files | Refs | README

commit f4591397da8444d1917a67a34cb6a6ac8137385e
parent 8faf4d1de2cbda61ae871fc23091deff3672e0fc
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Sat, 14 Jan 1995 13:40:07 -0200

strdup is done via mem.c to control its memory allocation

Diffstat:
Mlua.stx | 4++--
Mluamem.c | 9++++++++-
Mluamem.h | 4+++-
Mstrlib.c | 6+++---
Mtable.c | 4++--
5 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/lua.stx b/lua.stx @@ -1,6 +1,6 @@ %{ -char *rcs_luastx = "$Id: lua.stx,v 3.15 1994/12/27 20:04:29 celes Exp celes $"; +char *rcs_luastx = "$Id: lua.stx,v 3.16 1994/12/27 20:41:11 celes Exp roberto $"; #include <stdio.h> #include <stdlib.h> @@ -237,7 +237,7 @@ static void init_function (TreeNode *func) if (lua_debug) { code_byte(SETFUNCTION); - code_code((Byte *)strdup(lua_file[lua_nfile-1])); + code_code((Byte *)luaI_strdup(lua_file[lua_nfile-1])); code_word(luaI_findconstant(func)); } } diff --git a/luamem.c b/luamem.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_mem = "$Id: mem.c,v 1.2 1994/11/16 18:09:11 roberto Stab $"; +char *rcs_mem = "$Id: mem.c,v 1.3 1994/12/20 21:20:36 roberto Exp roberto $"; #include <stdlib.h> @@ -34,3 +34,10 @@ void *luaI_realloc (void *oldblock, unsigned long size) return block; } + +char *luaI_strdup (char *str) +{ + char *newstr = luaI_malloc(strlen(str)+1); + strcpy(newstr, str); + return newstr; +} diff --git a/luamem.h b/luamem.h @@ -1,7 +1,7 @@ /* ** mem.c ** memory manager for lua -** $Id: $ +** $Id: mem.h,v 1.1 1994/11/16 17:38:08 roberto Stab roberto $ */ #ifndef mem_h @@ -15,6 +15,8 @@ void luaI_free (void *block); void *luaI_malloc (unsigned long size); void *luaI_realloc (void *oldblock, unsigned long size); +char *luaI_strdup (char *str); + #define new(s) ((s *)luaI_malloc(sizeof(s))) #define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) #define growvector(old,n,s) ((s *)luaI_realloc(old,(n)*sizeof(s))) diff --git a/strlib.c b/strlib.c @@ -3,7 +3,7 @@ ** String library to LUA */ -char *rcs_strlib="$Id: strlib.c,v 1.7 1994/12/16 15:53:57 roberto Exp roberto $"; +char *rcs_strlib="$Id: strlib.c,v 1.8 1995/01/06 20:31:10 roberto Exp roberto $"; #include <string.h> #include <ctype.h> @@ -109,7 +109,7 @@ static void str_lower (void) lua_Object o = lua_getparam (1); if (!lua_isstring(o)) lua_error ("incorrect arguments to function `strlower'"); - c = s = strdup(lua_getstring(o)); + c = s = luaI_strdup(lua_getstring(o)); while (*c != 0) { *c = tolower(*c); @@ -131,7 +131,7 @@ static void str_upper (void) lua_Object o = lua_getparam (1); if (!lua_isstring(o)) lua_error ("incorrect arguments to function `strlower'"); - c = s = strdup(lua_getstring(o)); + c = s = luaI_strdup(lua_getstring(o)); while (*c != 0) { *c = toupper(*c); diff --git a/table.c b/table.c @@ -3,7 +3,7 @@ ** Module to control static tables */ -char *rcs_table="$Id: table.c,v 2.25 1994/12/20 21:20:36 roberto Exp roberto $"; +char *rcs_table="$Id: table.c,v 2.26 1995/01/12 14:19:04 roberto Exp roberto $"; #include <string.h> @@ -197,7 +197,7 @@ char *lua_addfile (char *fn) { if (lua_nfile >= MAXFILE) return "too many files"; - if ((lua_file[lua_nfile++] = strdup (fn)) == NULL) + if ((lua_file[lua_nfile++] = luaI_strdup (fn)) == NULL) return "not enough memory"; return NULL; }