-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.c
42 lines (36 loc) · 875 Bytes
/
object.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
#include <stdio.h>
#include <stdlib.h>
#include "object.h"
#include "server.h"
Object* createStringObject(char *str) {
Object *obj = malloc(sizeof(Object));
if(!obj) {
perror("createStringObject (malloc)");
return NULL;
}
obj->type = OBJ_STRING;
obj->ptr = str;
obj->ttl_idx = 0;
return obj;
}
Object* createZSetObject(ZSet *zset) {
Object *obj = malloc(sizeof(Object));
if(!obj) {
perror("createZSetObject (malloc)");
return NULL;
}
obj->type = OBJ_ZSET;
obj->ptr = zset;
obj->ttl_idx = 0;
return obj;
}
void freeObject(void *_obj) {
Object *obj = _obj;
switch(obj->type) {
case OBJ_STRING: free(obj->ptr); break;
case OBJ_ZSET: zset_free(obj->ptr); break;
}
if(obj->ttl_idx)
bheap_delete(state.ttl_heap, obj->ttl_idx - 1);
free(obj);
}