Browse Source

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

Roberto Ierusalimschy 31 years ago
parent
commit
f4591397da
5 changed files with 18 additions and 9 deletions
  1. 2 2
      lua.stx
  2. 8 1
      luamem.c
  3. 3 1
      luamem.h
  4. 3 3
      strlib.c
  5. 2 2
      table.c

+ 2 - 2
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));
   }
 }

+ 8 - 1
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;
+}

+ 3 - 1
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)))

+ 3 - 3
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);

+ 2 - 2
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;
 }