mirror of
https://github.com/lua/lua
synced 2025-04-24 06:23:00 +03:00
strdup is done via mem.c to control its memory allocation
This commit is contained in:
parent
8faf4d1de2
commit
f4591397da
4
lua.stx
4
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 <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -237,7 +237,7 @@ static void init_function (TreeNode *func)
|
|||||||
if (lua_debug)
|
if (lua_debug)
|
||||||
{
|
{
|
||||||
code_byte(SETFUNCTION);
|
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));
|
code_word(luaI_findconstant(func));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
luamem.c
9
luamem.c
@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** 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>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -34,3 +34,10 @@ void *luaI_realloc (void *oldblock, unsigned long size)
|
|||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *luaI_strdup (char *str)
|
||||||
|
{
|
||||||
|
char *newstr = luaI_malloc(strlen(str)+1);
|
||||||
|
strcpy(newstr, str);
|
||||||
|
return newstr;
|
||||||
|
}
|
||||||
|
4
luamem.h
4
luamem.h
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** mem.c
|
** mem.c
|
||||||
** memory manager for lua
|
** memory manager for lua
|
||||||
** $Id: $
|
** $Id: mem.h,v 1.1 1994/11/16 17:38:08 roberto Stab roberto $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef mem_h
|
#ifndef mem_h
|
||||||
@ -15,6 +15,8 @@ void luaI_free (void *block);
|
|||||||
void *luaI_malloc (unsigned long size);
|
void *luaI_malloc (unsigned long size);
|
||||||
void *luaI_realloc (void *oldblock, 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 new(s) ((s *)luaI_malloc(sizeof(s)))
|
||||||
#define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s)))
|
#define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s)))
|
||||||
#define growvector(old,n,s) ((s *)luaI_realloc(old,(n)*sizeof(s)))
|
#define growvector(old,n,s) ((s *)luaI_realloc(old,(n)*sizeof(s)))
|
||||||
|
6
strlib.c
6
strlib.c
@ -3,7 +3,7 @@
|
|||||||
** String library to LUA
|
** 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 <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -109,7 +109,7 @@ static void str_lower (void)
|
|||||||
lua_Object o = lua_getparam (1);
|
lua_Object o = lua_getparam (1);
|
||||||
if (!lua_isstring(o))
|
if (!lua_isstring(o))
|
||||||
lua_error ("incorrect arguments to function `strlower'");
|
lua_error ("incorrect arguments to function `strlower'");
|
||||||
c = s = strdup(lua_getstring(o));
|
c = s = luaI_strdup(lua_getstring(o));
|
||||||
while (*c != 0)
|
while (*c != 0)
|
||||||
{
|
{
|
||||||
*c = tolower(*c);
|
*c = tolower(*c);
|
||||||
@ -131,7 +131,7 @@ static void str_upper (void)
|
|||||||
lua_Object o = lua_getparam (1);
|
lua_Object o = lua_getparam (1);
|
||||||
if (!lua_isstring(o))
|
if (!lua_isstring(o))
|
||||||
lua_error ("incorrect arguments to function `strlower'");
|
lua_error ("incorrect arguments to function `strlower'");
|
||||||
c = s = strdup(lua_getstring(o));
|
c = s = luaI_strdup(lua_getstring(o));
|
||||||
while (*c != 0)
|
while (*c != 0)
|
||||||
{
|
{
|
||||||
*c = toupper(*c);
|
*c = toupper(*c);
|
||||||
|
4
table.c
4
table.c
@ -3,7 +3,7 @@
|
|||||||
** Module to control static tables
|
** 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>
|
#include <string.h>
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ char *lua_addfile (char *fn)
|
|||||||
{
|
{
|
||||||
if (lua_nfile >= MAXFILE)
|
if (lua_nfile >= MAXFILE)
|
||||||
return "too many files";
|
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 "not enough memory";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user