aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-01-14 13:40:26 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1995-01-14 13:40:26 -0200
commitf4591397da8444d1917a67a34cb6a6ac8137385e (patch)
tree749a23af6964bee4a373aecf13f3cdfcda8656f0
parent8faf4d1de2cbda61ae871fc23091deff3672e0fc (diff)
downloadlua-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.stx4
-rw-r--r--luamem.c9
-rw-r--r--luamem.h4
-rw-r--r--strlib.c6
-rw-r--r--table.c4
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 @@
1%{ 1%{
2 2
3char *rcs_luastx = "$Id: lua.stx,v 3.15 1994/12/27 20:04:29 celes Exp celes $"; 3char *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}
diff --git a/luamem.c b/luamem.c
index 8c3582c5..a970712e 100644
--- a/luamem.c
+++ b/luamem.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_mem = "$Id: mem.c,v 1.2 1994/11/16 18:09:11 roberto Stab $"; 6char *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
38char *luaI_strdup (char *str)
39{
40 char *newstr = luaI_malloc(strlen(str)+1);
41 strcpy(newstr, str);
42 return newstr;
43}
diff --git a/luamem.h b/luamem.h
index c75dd211..168a09d0 100644
--- a/luamem.h
+++ b/luamem.h
@@ -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);
15void *luaI_malloc (unsigned long size); 15void *luaI_malloc (unsigned long size);
16void *luaI_realloc (void *oldblock, unsigned long size); 16void *luaI_realloc (void *oldblock, unsigned long size);
17 17
18char *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)))
diff --git a/strlib.c b/strlib.c
index 6067e1be..f3d2f41d 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
3** String library to LUA 3** String library to LUA
4*/ 4*/
5 5
6char *rcs_strlib="$Id: strlib.c,v 1.7 1994/12/16 15:53:57 roberto Exp roberto $"; 6char *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);
diff --git a/table.c b/table.c
index 85311b21..1eec2913 100644
--- a/table.c
+++ b/table.c
@@ -3,7 +3,7 @@
3** Module to control static tables 3** Module to control static tables
4*/ 4*/
5 5
6char *rcs_table="$Id: table.c,v 2.25 1994/12/20 21:20:36 roberto Exp roberto $"; 6char *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}