From f4591397da8444d1917a67a34cb6a6ac8137385e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Sat, 14 Jan 1995 13:40:26 -0200 Subject: strdup is done via mem.c to control its memory allocation --- lua.stx | 4 ++-- luamem.c | 9 ++++++++- luamem.h | 4 +++- strlib.c | 6 +++--- table.c | 4 ++-- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lua.stx b/lua.stx index 451532d5..6a900944 100644 --- 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 #include @@ -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 index 8c3582c5..a970712e 100644 --- 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 @@ -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 index c75dd211..168a09d0 100644 --- 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 index 6067e1be..f3d2f41d 100644 --- 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 #include @@ -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 index 85311b21..1eec2913 100644 --- 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 @@ -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; } -- cgit v1.2.3-55-g6feb