Debian Codegraph @

lib/type.c

raw symbols SCIP
1 /*
2 Copyright (C) 2009-2016 Brazil
3 Copyright (C) 2020-2025 Sutou Kouhei <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "grn_ctx_impl.h"cxx . . $ `<file>/lib/grn_ctx_impl.h`/
21 #include "grn_db.h"cxx . . $ `<file>/lib/grn_db.h`/
22 #include "grn_type.h"cxx . . $ `<file>/lib/grn_type.h`/
23
24 const char *
25 grn_type_id_to_string_builtincxx . . $ grn_type_id_to_string_builtin(7cd85086f4e96fc4).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_idcxx . . $ grn_id# id)
26 {
27 switch (id) {
28 case GRN_DB_OBJECTcxx . . $ GRN_DB_OBJECT.:
29 return "Object";
30 case GRN_DB_BOOLcxx . . $ GRN_DB_BOOL.:
31 return "Bool";
32 case GRN_DB_INT8cxx . . $ GRN_DB_INT8.:
33 return "Int8";
34 case GRN_DB_UINT8cxx . . $ GRN_DB_UINT8.:
35 return "UInt8";
36 case GRN_DB_INT16cxx . . $ GRN_DB_INT16.:
37 return "Int16";
38 case GRN_DB_UINT16cxx . . $ GRN_DB_UINT16.:
39 return "UInt16";
40 case GRN_DB_INT32cxx . . $ GRN_DB_INT32.:
41 return "Int32";
42 case GRN_DB_UINT32cxx . . $ GRN_DB_UINT32.:
43 return "UInt32";
44 case GRN_DB_INT64cxx . . $ GRN_DB_INT64.:
45 return "Int64";
46 case GRN_DB_UINT64cxx . . $ GRN_DB_UINT64.:
47 return "UInt64";
48 case GRN_DB_FLOATcxx . . $ GRN_DB_FLOAT.:
49 return "Float";
50 case GRN_DB_TIMEcxx . . $ GRN_DB_TIME.:
51 return "Time";
52 case GRN_DB_SHORT_TEXTcxx . . $ GRN_DB_SHORT_TEXT.:
53 return "ShortText";
54 case GRN_DB_TEXTcxx . . $ GRN_DB_TEXT.:
55 return "Text";
56 case GRN_DB_LONG_TEXTcxx . . $ GRN_DB_LONG_TEXT.:
57 return "LongText";
58 case GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT.:
59 return "TokyoGeoPoint";
60 case GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.:
61 return "TokyoWGS84GeoPoint";
62 case GRN_DB_FLOAT32cxx . . $ GRN_DB_FLOAT32.:
63 return "Float32";
64 case GRN_DB_BFLOAT16cxx . . $ GRN_DB_BFLOAT16.:
65 return "BFloat16";
66 case GRN_DB_SHORT_BINARYcxx . . $ GRN_DB_SHORT_BINARY.:
67 return "ShortBinary";
68 case GRN_DB_BINARYcxx . . $ GRN_DB_BINARY.:
69 return "Binary";
70 case GRN_DB_LONG_BINARYcxx . . $ GRN_DB_LONG_BINARY.:
71 return "LongBinary";
72 case GRN_DB_JSONcxx . . $ GRN_DB_JSON.:
73 return "JSON";
74 default:
75 return "not a builtin type";
76 }
77 }
78
79 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
80 grn_type_id_is_builtincxx . . $ grn_type_id_is_builtin(a2a496425acc5b40).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_idcxx . . $ grn_id# id)
81 {
82 return id >= GRN_DB_OBJECTcxx . . $ GRN_DB_OBJECT. && id <= GRN_DB_JSONcxx . . $ GRN_DB_JSON.;
83 }
84
85 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
86 grn_type_id_is_number_familycxx . . $ grn_type_id_is_number_family(a2a496425acc5b40).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_idcxx . . $ grn_id# id)
87 {
88 return (GRN_DB_INT8cxx . . $ GRN_DB_INT8. <= id && id <= GRN_DB_FLOATcxx . . $ GRN_DB_FLOAT.) || (id == GRN_DB_FLOAT32cxx . . $ GRN_DB_FLOAT32.) ||
89 (id == GRN_DB_BFLOAT16cxx . . $ GRN_DB_BFLOAT16.);
90 }
91
92 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
93 grn_type_id_is_float_familycxx . . $ grn_type_id_is_float_family(a2a496425acc5b40).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_idcxx . . $ grn_id# id)
94 {
95 switch (id) {
96 case GRN_DB_BFLOAT16cxx . . $ GRN_DB_BFLOAT16.:
97 case GRN_DB_FLOAT32cxx . . $ GRN_DB_FLOAT32.:
98 case GRN_DB_FLOATcxx . . $ GRN_DB_FLOAT.:
99 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
100 default:
101 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
102 }
103 }
104
105 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
106 grn_type_id_is_text_familycxx . . $ grn_type_id_is_text_family(a2a496425acc5b40).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_idcxx . . $ grn_id# id)
107 {
108 return GRN_DB_SHORT_TEXTcxx . . $ GRN_DB_SHORT_TEXT. <= id && id <= GRN_DB_LONG_TEXTcxx . . $ GRN_DB_LONG_TEXT.;
109 }
110
111 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
112 grn_type_id_is_binary_familycxx . . $ grn_type_id_is_binary_family(a2a496425acc5b40).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_idcxx . . $ grn_id# id)
113 {
114 return GRN_DB_SHORT_BINARYcxx . . $ GRN_DB_SHORT_BINARY. <= id && id <= GRN_DB_LONG_BINARYcxx . . $ GRN_DB_LONG_BINARY.;
115 }
116
117 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
118 grn_type_id_is_compatiblecxx . . $ grn_type_id_is_compatible(2d9c41d921b9b3d6).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_idcxx . . $ grn_id# id1, grn_idcxx . . $ grn_id# id2)
119 {
120 if (id1 == id2) {
121 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
122 }
123 if (grn_type_id_is_text_familycxx . . $ grn_type_id_is_text_family(a2a496425acc5b40).(ctx, id1) &&
124 grn_type_id_is_text_familycxx . . $ grn_type_id_is_text_family(a2a496425acc5b40).(ctx, id2)) {
125 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
126 }
127 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
128 }
129
130 size_t
131 grn_type_id_sizecxx . . $ grn_type_id_size(61b721372fe7e3e1).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_idcxx . . $ grn_id# id)
132 {
133 switch (id) {
134 case GRN_DB_BOOLcxx . . $ GRN_DB_BOOL.:
135 return sizeof(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!);
136 case GRN_DB_INT8cxx . . $ GRN_DB_INT8.:
137 return sizeof(int8_tcxx . . $ int8_t#);
138 case GRN_DB_UINT8cxx . . $ GRN_DB_UINT8.:
139 return sizeof(uint8_tcxx . . $ uint8_t#);
140 case GRN_DB_INT16cxx . . $ GRN_DB_INT16.:
141 return sizeof(int16_tcxx . . $ int16_t#);
142 case GRN_DB_UINT16cxx . . $ GRN_DB_UINT16.:
143 return sizeof(uint16_tcxx . . $ uint16_t#);
144 case GRN_DB_INT32cxx . . $ GRN_DB_INT32.:
145 return sizeof(int32_tcxx . . $ int32_t#);
146 case GRN_DB_UINT32cxx . . $ GRN_DB_UINT32.:
147 return sizeof(uint32_tcxx . . $ uint32_t#);
148 case GRN_DB_INT64cxx . . $ GRN_DB_INT64.:
149 return sizeof(int64_tcxx . . $ int64_t#);
150 case GRN_DB_UINT64cxx . . $ GRN_DB_UINT64.:
151 return sizeof(uint64_tcxx . . $ uint64_t#);
152 case GRN_DB_BFLOAT16cxx . . $ GRN_DB_BFLOAT16.:
153 #ifdef GRN_HAVE_BFLOAT16
154 return sizeof(grn_bfloat16);
155 #else
156 return sizeof(uint16_tcxx . . $ uint16_t#);
157 #endif
158 case GRN_DB_FLOAT32cxx . . $ GRN_DB_FLOAT32.:
159 return sizeof(float);
160 case GRN_DB_FLOATcxx . . $ GRN_DB_FLOAT.:
161 return sizeof(double);
162 case GRN_DB_TIMEcxx . . $ GRN_DB_TIME.:
163 return sizeof(int64_tcxx . . $ int64_t#);
164 case GRN_DB_SHORT_TEXTcxx . . $ GRN_DB_SHORT_TEXT.:
165 return GRN_TYPE_SHORT_TEXT_SIZEcxx . . $ `lib/grn_type.h:27:9`!;
166 case GRN_DB_TEXTcxx . . $ GRN_DB_TEXT.:
167 return GRN_TYPE_TEXT_SIZEcxx . . $ `lib/grn_type.h:28:9`!;
168 case GRN_DB_LONG_TEXTcxx . . $ GRN_DB_LONG_TEXT.:
169 return GRN_TYPE_LONG_TEXT_SIZEcxx . . $ `lib/grn_type.h:29:9`!;
170 case GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT.:
171 case GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.:
172 return sizeof(grn_geo_pointcxx . . $ grn_geo_point#);
173 case GRN_DB_SHORT_BINARYcxx . . $ GRN_DB_SHORT_BINARY.:
174 return GRN_TYPE_SHORT_BINARY_SIZEcxx . . $ `lib/grn_type.h:30:9`!;
175 case GRN_DB_BINARYcxx . . $ GRN_DB_BINARY.:
176 return GRN_TYPE_BINARY_SIZEcxx . . $ `lib/grn_type.h:31:9`!;
177 case GRN_DB_LONG_BINARYcxx . . $ GRN_DB_LONG_BINARY.:
178 return GRN_TYPE_LONG_BINARY_SIZEcxx . . $ `lib/grn_type.h:32:9`!;
179 case GRN_DB_JSONcxx . . $ GRN_DB_JSON.:
180 return GRN_TYPE_JSON_SIZEcxx . . $ `lib/grn_type.h:33:9`!;
181 default:
182 {
183 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
184 size_t size = 0;
185 if (grn_type_id_is_builtincxx . . $ grn_type_id_is_builtin(a2a496425acc5b40).(ctx, id)) {
186 grn_objcxx . . $ grn_obj# *obj = grn_ctx_atcxx . . $ grn_ctx_at(ac4544c8400954c9).(ctx, id);
187 if (grn_obj_is_typecxx . . $ grn_obj_is_type(a5760e5c319a06ee).(ctx, obj)) {
188 size = grn_type_sizecxx . . $ grn_type_size(8dd58acc9865e889).(ctx, obj);
189 }
190 grn_obj_unrefcxx . . $ grn_obj_unref(cda3a5f3c2e53c6b).(ctx, obj);
191 } else {
192 /*
193 We need to check the ID is a ID for table:
194
195 grn_obj *obj = grn_ctx_at(ctx, id);
196 if (grn_obj_is_table(ctx, obj)) {
197 size = sizeof(grn_id);
198 }
199 grn_obj_unref(ctx, obj);
200
201 But we want to reduce grn_ctx_at() call for performance.
202 So we assume the ID is a ID for table here.
203 */
204 size = sizeof(grn_idcxx . . $ grn_id#);
205 }
206 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(size);
207 }
208 }
209 }
210
211 grn_objcxx . . $ grn_obj# *
212 grn_type_createcxx . . $ grn_type_create(3e3f5eb745feb38e).(grn_ctxcxx . . $ grn_ctx# *ctx,
213 const char *name,
214 unsigned int name_size,
215 grn_obj_flagscxx . . $ grn_obj_flags# flags,
216 unsigned int size)
217 {
218 grn_objcxx . . $ grn_obj# *db;
219 if (!ctx || !ctx->implcxx . . $ _grn_ctx#impl. || !(db = ctx->implcxx . . $ _grn_ctx#impl.->dbcxx . . $ _grn_ctx_impl#db.)) {
220 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[type][create] DB is not initialized");
221 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
222 }
223 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
224 if (grn_db_check_namecxx . . $ grn_db_check_name(4388e0a4766c49a1).(ctx, name, name_size)) {
225 GRN_DB_CHECK_NAME_ERRcxx . . $ `lib/grn_db.h:610:9`!("[type][create]", name, name_size);
226 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
227 }
228 grn_idcxx . . $ grn_id# id = grn_obj_registercxx . . $ grn_obj_register(5739ee2245199e94).(ctx, db, name, name_size);
229 if (id == GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!) {
230 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
231 "[type][create] failed to register type: <%.*s>",
232 (int)name_size,
233 name);
234 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
235 }
236 grn_objcxx . . $ grn_obj# *type = grn_type_create_internalcxx . . $ grn_type_create_internal(57e84216b906e8d9).(ctx, id, flags, size);
237 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(type);
238 }
239
240 grn_objcxx . . $ grn_obj# *
241 grn_type_create_internalcxx . . $ grn_type_create_internal(57e84216b906e8d9).(grn_ctxcxx . . $ grn_ctx# *ctx,
242 grn_idcxx . . $ grn_id# id,
243 grn_obj_flagscxx . . $ grn_obj_flags# flags,
244 unsigned int size)
245 {
246 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
247 struct _grn_typecxx . . $ _grn_type# *type = GRN_CALLOCcxx . . $ `lib/grn_alloc.h:42:9`!(sizeof(grn_db_obj));
248 if (!type) {
249 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_NO_MEMORY_AVAILABLE,
250 "[type][init] failed to allocate type: <%u>",
251 id);
252 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
253 }
254 GRN_DB_OBJ_SET_TYPEcxx . . $ `lib/grn_ctx.h:195:9`!(type, GRN_TYPEcxx . . $ `include/groonga/groonga.h:892:9`!);
255 type->objcxx . . $ _grn_type#obj..headercxx . . $ $anonymous_type_4a7c1014017e4c5d_0#header..flagscxx . . $ _grn_obj_header#flags. = flags;
256 type->objcxx . . $ _grn_type#obj..headercxx . . $ $anonymous_type_4a7c1014017e4c5d_0#header..domaincxx . . $ _grn_obj_header#domain. = GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!;
257 GRN_TYPE_SIZEcxx . . $ `lib/grn_db.h:366:9`!(&(type->obj)) = size;
258 if (grn_db_obj_initcxx . . $ grn_db_obj_init(e57fea19a9dd2af9).(ctx, ctx->implcxx . . $ _grn_ctx#impl.->dbcxx . . $ _grn_ctx_impl#db., id, DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(type))) {
259 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(type);
260 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
261 }
262 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!((grn_obj *)type);
263 }
264
265 uint32_tcxx . . $ uint32_t#
266 grn_type_sizecxx . . $ grn_type_size(8dd58acc9865e889).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *type)
267 {
268 uint32_tcxx . . $ uint32_t# size;
269
270 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
271 if (!type) {
272 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[type][size] type is NULL");
273 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(0);
274 }
275 size = GRN_TYPE_SIZEcxx . . $ `lib/grn_db.h:366:9`!(DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(type));
276 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(size);
277 }