-
Notifications
You must be signed in to change notification settings - Fork 1
/
class.c
84 lines (68 loc) · 1.58 KB
/
class.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "std.h"
#include "lpc_incl.h"
#ifdef CLASS_STATS
int num_classes;
int total_class_size;
#endif
void dealloc_class (array_t * p) {
int i;
#ifdef CLASS_STATS
num_classes--;
total_class_size -= sizeof(array_t) + sizeof(svalue_t) * (p->size - 1);
#endif
for (i = p->size; i--;)
free_svalue(&p->item[i], "dealloc_class");
FREE((char *) p);
}
void free_class (array_t * p)
{
if (--(p->ref) > 0)
return;
dealloc_class(p);
}
array_t *allocate_class (class_def_t * cld, int has_values) {
array_t *p;
int n = cld->size;
if(!n)
n++;
#ifdef CLASS_STATS
num_classes++;
total_class_size += sizeof(array_t) + sizeof(svalue_t) * (n - 1);
#endif
p = (array_t *)DXALLOC(sizeof(array_t) + sizeof(svalue_t) * (n - 1), TAG_CLASS, "allocate_class");
n = cld->size;
p->ref = 1;
p->size = n;
if (has_values) {
while (n--)
p->item[n] = *sp--;
} else {
while (n--)
p->item[n] = const0;
}
return p;
}
array_t *allocate_class_by_size (int size) {
array_t *p;
#ifdef CLASS_STATS
num_classes++;
total_class_size += sizeof(array_t) + sizeof(svalue_t) * (size - 1);
#endif
p = (array_t *)DXALLOC(sizeof(array_t) + sizeof(svalue_t) * (size - 1), TAG_CLASS, "allocate_class");
p->ref = 1;
p->size = size;
while (size--)
p->item[size] = const0;
return p;
}
array_t *allocate_empty_class_by_size (int size) {
array_t *p;
#ifdef CLASS_STATS
num_classes++;
total_class_size += sizeof(array_t) + sizeof(svalue_t) * (size - 1);
#endif
p = (array_t *)DXALLOC(sizeof(array_t) + sizeof(svalue_t) * (size - 1), TAG_CLASS, "allocate_class");
p->ref = 1;
p->size = size;
return p;
}