aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-11 14:47:50 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-11 14:47:50 -0200
commit0ffc676ce7ea4764f3277ce87967ef14ad323933 (patch)
tree2582dabfc21f150b20c69a03ddfc9f896bc564d3
parent18fb3ddb897564178bebec44dbe04fabcebf39c5 (diff)
downloadlua-0ffc676ce7ea4764f3277ce87967ef14ad323933.tar.gz
lua-0ffc676ce7ea4764f3277ce87967ef14ad323933.tar.bz2
lua-0ffc676ce7ea4764f3277ce87967ef14ad323933.zip
details
-rw-r--r--lmem.c26
-rw-r--r--lobject.c9
2 files changed, 16 insertions, 19 deletions
diff --git a/lmem.c b/lmem.c
index 9841092a..bd6b58da 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.c,v 1.35 2000/08/04 19:38:35 roberto Exp roberto $ 2** $Id: lmem.c,v 1.36 2000/08/09 19:16:57 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -15,15 +15,6 @@
15#include "lstate.h" 15#include "lstate.h"
16 16
17 17
18/*
19** Real ISO (ANSI) systems do not need these tests;
20** but some systems (Sun OS) are not that ISO...
21*/
22#ifdef OLD_ANSI
23#define realloc(b,s) ((b) == NULL ? malloc(s) : (realloc)(b, s))
24#define free(b) if (b) (free)(b)
25#endif
26
27 18
28 19
29#ifdef DEBUG 20#ifdef DEBUG
@@ -38,11 +29,8 @@
38#include <limits.h> 29#include <limits.h>
39#include <string.h> 30#include <string.h>
40 31
41#undef realloc
42#undef malloc
43#undef free
44#define realloc(b, s) debug_realloc(b, s) 32#define realloc(b, s) debug_realloc(b, s)
45#define malloc(b) debug_realloc(NULL, 0) 33#define malloc(b) debug_realloc(NULL, b)
46#define free(b) debug_realloc(b, 0) 34#define free(b) debug_realloc(b, 0)
47 35
48 36
@@ -119,6 +107,16 @@ static void *debug_realloc (void *block, size_t size) {
119 107
120 108
121 109
110/*
111** Real ISO (ANSI) systems do not need these tests;
112** but some systems (Sun OS) are not that ISO...
113*/
114#ifdef OLD_ANSI
115#define realloc(b,s) ((b) == NULL ? malloc(s) : (realloc)(b, s))
116#define free(b) if (b) (free)(b)
117#endif
118
119
122void *luaM_growaux (lua_State *L, void *block, size_t nelems, 120void *luaM_growaux (lua_State *L, void *block, size_t nelems,
123 int inc, size_t size, const char *errormsg, size_t limit) { 121 int inc, size_t size, const char *errormsg, size_t limit) {
124 size_t newn = nelems+inc; 122 size_t newn = nelems+inc;
diff --git a/lobject.c b/lobject.c
index 4c06bf72..fd54eefd 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.52 2000/10/05 12:14:08 roberto Exp roberto $ 2** $Id: lobject.c,v 1.53 2000/10/09 13:47:32 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -87,16 +87,14 @@ void luaO_verror (lua_State *L, const char *fmt, ...) {
87} 87}
88 88
89 89
90#define EXTRALEN sizeof(" string \"s...\" ")
91
92void luaO_chunkid (char *out, const char *source, int bufflen) { 90void luaO_chunkid (char *out, const char *source, int bufflen) {
93 if (*source == '=') 91 if (*source == '=')
94 sprintf(out, "%.*s", bufflen, source+1); /* remove first char */ 92 sprintf(out, "%.*s", bufflen-1, source+1); /* remove first char */
95 else { 93 else {
96 bufflen -= EXTRALEN;
97 if (*source == '@') { 94 if (*source == '@') {
98 int l; 95 int l;
99 source++; /* skip the `@' */ 96 source++; /* skip the `@' */
97 bufflen -= sizeof("file `...%s'");
100 l = strlen(source); 98 l = strlen(source);
101 if (l>bufflen) { 99 if (l>bufflen) {
102 source += (l-bufflen); /* get last part of file name */ 100 source += (l-bufflen); /* get last part of file name */
@@ -107,6 +105,7 @@ void luaO_chunkid (char *out, const char *source, int bufflen) {
107 } 105 }
108 else { 106 else {
109 int len = strcspn(source, "\n"); /* stop at first newline */ 107 int len = strcspn(source, "\n"); /* stop at first newline */
108 bufflen -= sizeof("string \"%.*s...\"");
110 if (len > bufflen) len = bufflen; 109 if (len > bufflen) len = bufflen;
111 if (source[len] != '\0') /* must truncate? */ 110 if (source[len] != '\0') /* must truncate? */
112 sprintf(out, "string \"%.*s...\"", len, source); 111 sprintf(out, "string \"%.*s...\"", len, source);