comparison src/paranormal/libcalc/dict.c @ 1181:2f3397e53b05 trunk

[svn] - memory cleanups, purify-assisted.
author nenolod
date Sat, 09 Jun 2007 06:16:03 -0700
parents e9b2d21cf078
children 6d749f573b3b
comparison
equal deleted inserted replaced
1180:cc6df5de72a6 1181:2f3397e53b05
33 static void more_variables (symbol_dict_t *dict) { 33 static void more_variables (symbol_dict_t *dict) {
34 var_t *new_var; 34 var_t *new_var;
35 35
36 dict->v_space += V_SPACE_INCR; 36 dict->v_space += V_SPACE_INCR;
37 37
38 new_var = (var_t *)g_malloc (dict->v_space * sizeof(var_t)); 38 new_var = g_new(var_t, dict->v_space + 1);
39
40 memcpy (new_var, dict->variables, dict->v_count * sizeof(var_t)); 39 memcpy (new_var, dict->variables, dict->v_count * sizeof(var_t));
41 g_free (dict->variables); 40 g_free (dict->variables);
42 41
43 dict->variables = new_var; 42 dict->variables = new_var;
44 } 43 }
63 if (global_dict_initialized != 1) { 62 if (global_dict_initialized != 1) {
64 int i; 63 int i;
65 64
66 global_dict.v_count = 0; 65 global_dict.v_count = 0;
67 global_dict.v_space = V_SPACE_INIT; 66 global_dict.v_space = V_SPACE_INIT;
68 global_dict.variables = (var_t *) g_new(var_t, global_dict.v_space); 67 global_dict.variables = (var_t *) g_new(var_t, global_dict.v_space + 1);
69 global_dict_initialized = 1; 68 global_dict_initialized = 1;
70 69
71 for (i = 0; i < 100; i++) { 70 for (i = 0; i < 100; i++) {
72 gchar tmpbuf[40]; 71 gchar tmpbuf[40];
73 snprintf(tmpbuf, 40, "global_reg%d", i); 72 snprintf(tmpbuf, 40, "global_reg%d", i);
78 dict = g_new(symbol_dict_t, 1); 77 dict = g_new(symbol_dict_t, 1);
79 78
80 /* Allocate space for variables. */ 79 /* Allocate space for variables. */
81 dict->v_count = 0; 80 dict->v_count = 0;
82 dict->v_space = V_SPACE_INIT; 81 dict->v_space = V_SPACE_INIT;
83 dict->variables = (var_t *) g_new (var_t, dict->v_space); 82 dict->variables = (var_t *) g_new (var_t, dict->v_space + 1);
84 83
85 return dict; 84 return dict;
86 } 85 }
87 86
88 void dict_free (symbol_dict_t *dict) { 87 void dict_free (symbol_dict_t *dict) {