aboutsummaryrefslogtreecommitdiff
path: root/tree.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-16 15:39:16 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-16 15:39:16 -0200
commit2b5bc5d1a81579a76c13e638de2592e2c39c73f0 (patch)
tree8294278f9fbd2565d3a2cd11642fed41982824bd /tree.c
parent94686ce58554a80374eeff115ee5b87c184ed173 (diff)
downloadlua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.tar.gz
lua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.tar.bz2
lua-2b5bc5d1a81579a76c13e638de2592e2c39c73f0.zip
new module for memory allocation
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/tree.c b/tree.c
index eee5a204..6e1c0b2a 100644
--- a/tree.c
+++ b/tree.c
@@ -3,12 +3,12 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_tree="$Id: tree.c,v 1.4 1994/11/14 21:40:14 roberto Exp roberto $"; 6char *rcs_tree="$Id: tree.c,v 1.5 1994/11/16 16:03:48 roberto Exp roberto $";
7 7
8 8
9#include <stdlib.h>
10#include <string.h> 9#include <string.h>
11 10
11#include "mem.h"
12#include "lua.h" 12#include "lua.h"
13#include "tree.h" 13#include "tree.h"
14#include "table.h" 14#include "table.h"
@@ -27,9 +27,7 @@ static TreeNode *tree_create (TreeNode **node, char *str, int *created)
27{ 27{
28 if (*node == NULL) 28 if (*node == NULL)
29 { 29 {
30 *node = (TreeNode *) malloc (sizeof(TreeNode)+strlen(str)); 30 *node = (TreeNode *) luaI_malloc(sizeof(TreeNode)+strlen(str));
31 if (*node == NULL)
32 lua_error("not enough memory");
33 (*node)->left = (*node)->right = NULL; 31 (*node)->left = (*node)->right = NULL;
34 strcpy((*node)->str, str); 32 strcpy((*node)->str, str);
35 (*node)->varindex = (*node)->constindex = UNMARKED_STRING; 33 (*node)->varindex = (*node)->constindex = UNMARKED_STRING;
@@ -74,19 +72,19 @@ static TreeNode *lua_strfree (TreeNode *parent)
74{ 72{
75 if (parent->left == NULL && parent->right == NULL) /* no child */ 73 if (parent->left == NULL && parent->right == NULL) /* no child */
76 { 74 {
77 free (parent); 75 luaI_free(parent);
78 return NULL; 76 return NULL;
79 } 77 }
80 else if (parent->left == NULL) /* only right child */ 78 else if (parent->left == NULL) /* only right child */
81 { 79 {
82 TreeNode *p = parent->right; 80 TreeNode *p = parent->right;
83 free (parent); 81 luaI_free(parent);
84 return p; 82 return p;
85 } 83 }
86 else if (parent->right == NULL) /* only left child */ 84 else if (parent->right == NULL) /* only left child */
87 { 85 {
88 TreeNode *p = parent->left; 86 TreeNode *p = parent->left;
89 free (parent); 87 luaI_free(parent);
90 return p; 88 return p;
91 } 89 }
92 else /* two children */ 90 else /* two children */