1 |
From c67ab063cf82306067f3a0ebdbf4f7d6dff94a2a Mon Sep 17 00:00:00 2001 |
2 |
From: Nikias Bassen <nikias@gmx.li> |
3 |
Date: Thu, 19 Jan 2017 15:52:41 +0100 |
4 |
Subject: [PATCH] bplist: Mass-rename 'dict_size' and 'param_dict_size' to more |
5 |
appropriate 'ref_size' |
6 |
|
7 |
--- |
8 |
src/bplist.c | 60 ++++++++++++++++++++++++++++++------------------------------ |
9 |
1 file changed, 30 insertions(+), 30 deletions(-) |
10 |
|
11 |
diff --git a/src/bplist.c b/src/bplist.c |
12 |
index 29900e8..7ab9380 100644 |
13 |
--- a/src/bplist.c |
14 |
+++ b/src/bplist.c |
15 |
@@ -194,7 +194,7 @@ struct bplist_data { |
16 |
const char* data; |
17 |
uint64_t size; |
18 |
uint64_t num_objects; |
19 |
- uint8_t dict_size; |
20 |
+ uint8_t ref_size; |
21 |
uint8_t offset_size; |
22 |
const char* offset_table; |
23 |
uint32_t level; |
24 |
@@ -400,19 +400,19 @@ static plist_t parse_dict_node(struct bplist_data *bplist, const char** bnode, u |
25 |
plist_t node = node_create(NULL, data); |
26 |
|
27 |
for (j = 0; j < data->length; j++) { |
28 |
- str_i = j * bplist->dict_size; |
29 |
- str_j = (j + size) * bplist->dict_size; |
30 |
+ str_i = j * bplist->ref_size; |
31 |
+ str_j = (j + size) * bplist->ref_size; |
32 |
index1_ptr = (*bnode) + str_i; |
33 |
index2_ptr = (*bnode) + str_j; |
34 |
|
35 |
- if ((index1_ptr < bplist->data || index1_ptr + bplist->dict_size >= end_data) || |
36 |
- (index2_ptr < bplist->data || index2_ptr + bplist->dict_size >= end_data)) { |
37 |
+ if ((index1_ptr < bplist->data || index1_ptr + bplist->ref_size >= end_data) || |
38 |
+ (index2_ptr < bplist->data || index2_ptr + bplist->ref_size >= end_data)) { |
39 |
plist_free(node); |
40 |
return NULL; |
41 |
} |
42 |
|
43 |
- index1 = UINT_TO_HOST(index1_ptr, bplist->dict_size); |
44 |
- index2 = UINT_TO_HOST(index2_ptr, bplist->dict_size); |
45 |
+ index1 = UINT_TO_HOST(index1_ptr, bplist->ref_size); |
46 |
+ index2 = UINT_TO_HOST(index2_ptr, bplist->ref_size); |
47 |
|
48 |
if (index1 >= bplist->num_objects) { |
49 |
plist_free(node); |
50 |
@@ -474,8 +474,8 @@ static plist_t parse_array_node(struct bplist_data *bplist, const char** bnode, |
51 |
plist_t node = node_create(NULL, data); |
52 |
|
53 |
for (j = 0; j < data->length; j++) { |
54 |
- str_j = j * bplist->dict_size; |
55 |
- index1 = UINT_TO_HOST((*bnode) + str_j, bplist->dict_size); |
56 |
+ str_j = j * bplist->ref_size; |
57 |
+ index1 = UINT_TO_HOST((*bnode) + str_j, bplist->ref_size); |
58 |
|
59 |
if (index1 >= bplist->num_objects) { |
60 |
plist_free(node); |
61 |
@@ -743,7 +743,7 @@ PLIST_API void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * |
62 |
bplist.data = plist_bin; |
63 |
bplist.size = length; |
64 |
bplist.num_objects = num_objects; |
65 |
- bplist.dict_size = ref_size; |
66 |
+ bplist.ref_size = ref_size; |
67 |
bplist.offset_size = offset_size; |
68 |
bplist.offset_table = offset_table; |
69 |
bplist.level = 0; |
70 |
@@ -950,7 +950,7 @@ static void write_unicode(bytearray_t * bplist, uint16_t * val, uint64_t size) |
71 |
free(buff); |
72 |
} |
73 |
|
74 |
-static void write_array(bytearray_t * bplist, node_t* node, hashtable_t* ref_table, uint8_t dict_param_size) |
75 |
+static void write_array(bytearray_t * bplist, node_t* node, hashtable_t* ref_table, uint8_t ref_size) |
76 |
{ |
77 |
uint64_t idx = 0; |
78 |
uint8_t *buff = NULL; |
79 |
@@ -969,25 +969,25 @@ static void write_array(bytearray_t * bplist, node_t* node, hashtable_t* ref_tab |
80 |
byte_array_free(int_buff); |
81 |
} |
82 |
|
83 |
- buff = (uint8_t *) malloc(size * dict_param_size); |
84 |
+ buff = (uint8_t *) malloc(size * ref_size); |
85 |
|
86 |
for (i = 0, cur = node_first_child(node); cur && i < size; cur = node_next_sibling(cur), i++) |
87 |
{ |
88 |
idx = *(uint64_t *) (hash_table_lookup(ref_table, cur)); |
89 |
#ifdef __BIG_ENDIAN__ |
90 |
- idx = idx << ((sizeof(uint64_t) - dict_param_size) * 8); |
91 |
+ idx = idx << ((sizeof(uint64_t) - ref_size) * 8); |
92 |
#endif |
93 |
- memcpy(buff + i * dict_param_size, &idx, dict_param_size); |
94 |
- byte_convert(buff + i * dict_param_size, dict_param_size); |
95 |
+ memcpy(buff + i * ref_size, &idx, ref_size); |
96 |
+ byte_convert(buff + i * ref_size, ref_size); |
97 |
} |
98 |
|
99 |
//now append to bplist |
100 |
- byte_array_append(bplist, buff, size * dict_param_size); |
101 |
+ byte_array_append(bplist, buff, size * ref_size); |
102 |
free(buff); |
103 |
|
104 |
} |
105 |
|
106 |
-static void write_dict(bytearray_t * bplist, node_t* node, hashtable_t* ref_table, uint8_t dict_param_size) |
107 |
+static void write_dict(bytearray_t * bplist, node_t* node, hashtable_t* ref_table, uint8_t ref_size) |
108 |
{ |
109 |
uint64_t idx1 = 0; |
110 |
uint64_t idx2 = 0; |
111 |
@@ -1007,26 +1007,26 @@ static void write_dict(bytearray_t * bplist, node_t* node, hashtable_t* ref_tabl |
112 |
byte_array_free(int_buff); |
113 |
} |
114 |
|
115 |
- buff = (uint8_t *) malloc(size * 2 * dict_param_size); |
116 |
+ buff = (uint8_t *) malloc(size * 2 * ref_size); |
117 |
for (i = 0, cur = node_first_child(node); cur && i < size; cur = node_next_sibling(node_next_sibling(cur)), i++) |
118 |
{ |
119 |
idx1 = *(uint64_t *) (hash_table_lookup(ref_table, cur)); |
120 |
#ifdef __BIG_ENDIAN__ |
121 |
- idx1 = idx1 << ((sizeof(uint64_t) - dict_param_size) * 8); |
122 |
+ idx1 = idx1 << ((sizeof(uint64_t) - ref_size) * 8); |
123 |
#endif |
124 |
- memcpy(buff + i * dict_param_size, &idx1, dict_param_size); |
125 |
- byte_convert(buff + i * dict_param_size, dict_param_size); |
126 |
+ memcpy(buff + i * ref_size, &idx1, ref_size); |
127 |
+ byte_convert(buff + i * ref_size, ref_size); |
128 |
|
129 |
idx2 = *(uint64_t *) (hash_table_lookup(ref_table, cur->next)); |
130 |
#ifdef __BIG_ENDIAN__ |
131 |
- idx2 = idx2 << ((sizeof(uint64_t) - dict_param_size) * 8); |
132 |
+ idx2 = idx2 << ((sizeof(uint64_t) - ref_size) * 8); |
133 |
#endif |
134 |
- memcpy(buff + (i + size) * dict_param_size, &idx2, dict_param_size); |
135 |
- byte_convert(buff + (i + size) * dict_param_size, dict_param_size); |
136 |
+ memcpy(buff + (i + size) * ref_size, &idx2, ref_size); |
137 |
+ byte_convert(buff + (i + size) * ref_size, ref_size); |
138 |
} |
139 |
|
140 |
//now append to bplist |
141 |
- byte_array_append(bplist, buff, size * 2 * dict_param_size); |
142 |
+ byte_array_append(bplist, buff, size * 2 * ref_size); |
143 |
free(buff); |
144 |
|
145 |
} |
146 |
@@ -1125,7 +1125,7 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) |
147 |
hashtable_t* ref_table = NULL; |
148 |
struct serialize_s ser_s; |
149 |
uint8_t offset_size = 0; |
150 |
- uint8_t dict_param_size = 0; |
151 |
+ uint8_t ref_size = 0; |
152 |
uint64_t num_objects = 0; |
153 |
uint64_t root_object = 0; |
154 |
uint64_t offset_table_index = 0; |
155 |
@@ -1159,7 +1159,7 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) |
156 |
//now stream to output buffer |
157 |
offset_size = 0; //unknown yet |
158 |
objects_len = objects->len; |
159 |
- dict_param_size = get_needed_bytes(objects_len); |
160 |
+ ref_size = get_needed_bytes(objects_len); |
161 |
num_objects = objects->len; |
162 |
root_object = 0; //root is first in list |
163 |
offset_table_index = 0; //unknown yet |
164 |
@@ -1217,10 +1217,10 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) |
165 |
case PLIST_DATA: |
166 |
write_data(bplist_buff, data->buff, data->length); |
167 |
case PLIST_ARRAY: |
168 |
- write_array(bplist_buff, ptr_array_index(objects, i), ref_table, dict_param_size); |
169 |
+ write_array(bplist_buff, ptr_array_index(objects, i), ref_table, ref_size); |
170 |
break; |
171 |
case PLIST_DICT: |
172 |
- write_dict(bplist_buff, ptr_array_index(objects, i), ref_table, dict_param_size); |
173 |
+ write_dict(bplist_buff, ptr_array_index(objects, i), ref_table, ref_size); |
174 |
break; |
175 |
case PLIST_DATE: |
176 |
write_date(bplist_buff, data->realval); |
177 |
@@ -1258,7 +1258,7 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) |
178 |
//setup trailer |
179 |
memset(trailer.unused, '\0', sizeof(trailer.unused)); |
180 |
trailer.offset_size = offset_size; |
181 |
- trailer.ref_size = dict_param_size; |
182 |
+ trailer.ref_size = ref_size; |
183 |
trailer.num_objects = be64toh(num_objects); |
184 |
trailer.root_object_index = be64toh(root_object); |
185 |
trailer.offset_table_offset = be64toh(offset_table_index); |