-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_pool.c
More file actions
59 lines (48 loc) · 1.09 KB
/
string_pool.c
File metadata and controls
59 lines (48 loc) · 1.09 KB
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
#include <stdio.h>
#include <string.h>
#include "MEM.h"
#include "DBG.h"
#include "crowbar.h"
static CRB_String *
alloc_crb_string(CRB_Interpreter *inter, char *str, CRB_Boolean is_literal)
{
CRB_String *ret;
ret = MEM_malloc(sizeof(CRB_String));
ret->ref_count = 0;
ret->is_literal = is_literal;
ret->string = str;
return ret;
}
CRB_String *
crb_literal_to_crb_string(CRB_Interpreter *inter, char *str)
{
CRB_String *ret;
ret = alloc_crb_string(inter, str, CRB_TRUE);
ret->ref_count = 1;
return ret;
}
void
crb_refer_string(CRB_String *str)
{
str->ref_count++;
}
void
crb_release_string(CRB_String *str)
{
str->ref_count--;
DBG_assert(str->ref_count >= 0, ("str->ref_count..%d\n",
str->ref_count));
if (str->ref_count == 0) {
if (!str->is_literal) {
MEM_free(str->string);
}
MEM_free(str);
}
}
CRB_String *
crb_create_crowbar_string(CRB_Interpreter *inter, char *str)
{
CRB_String *ret = alloc_crb_string(inter, str, CRB_FALSE);
ret->ref_count = 1;
return ret;
}