Debian Codegraph @

lib/proc/proc_cast.c

raw symbols SCIP
1 /*
2 Copyright(C) 2018 Horimoto Yasuhiro <[email protected]>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "../grn_proc.h"cxx . . $ `<file>/lib/grn_proc.h`/
20 #include "../grn_expr.h"cxx . . $ `<file>/lib/grn_expr.h`/
21
22 #include <groonga/plugin.h>cxx . . $ `<file>/include/groonga/plugin.h`/
23
24 static grn_objcxx . . $ grn_obj# *
25 func_cast_loosecxx . . $ func_cast_loose(fd082858389c8bb0).(grn_ctxcxx . . $ grn_ctx# *ctx, int nargs, grn_objcxx . . $ grn_obj# **args, grn_user_datacxx . . $ grn_user_data# *user_data)
26 {
27 grn_objcxx . . $ grn_obj# *type;
28 grn_objcxx . . $ grn_obj# *value;
29 grn_objcxx . . $ grn_obj# *default_value;
30 grn_idcxx . . $ grn_id# type_id;
31 grn_rccxx . . $ grn_rc# rc;
32 grn_objcxx . . $ grn_obj# *casted_value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
33
34 if (nargs != 3) {
35 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, GRN_INVALID_ARGUMENT,
36 "cast_loose(): wrong number of arguments (%d for 3)",
37 nargs);
38 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
39 }
40
41 type = args[0];
42 if (!grn_obj_is_typecxx . . $ grn_obj_is_type(a5760e5c319a06ee).(ctx, type)) {
43 grn_objcxx . . $ grn_obj# inspected;
44 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&inspected, 0);
45 grn_inspectcxx . . $ grn_inspect(88456f97fe0d41a).(ctx, &inspected, type);
46 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, GRN_INVALID_ARGUMENT,
47 "cast_loose(): the first argument must be type: <%.*s>",
48 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&inspected),
49 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&inspected));
50 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &inspected);
51 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
52 }
53 type_id = grn_obj_idcxx . . $ grn_obj_id(8dd58acc9865e889).(ctx, type);
54
55 value = args[1];
56 default_value = args[2];
57
58 casted_value = grn_plugin_proc_alloccxx . . $ grn_plugin_proc_alloc(acb267eca6702fc).(ctx, user_data, type_id, 0);
59 if (!casted_value) {
60 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
61 }
62
63 rc = grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, value, casted_value, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
64 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
65 rc = grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, default_value, casted_value, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
66 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
67 char type_name[GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!];
68 int type_name_size;
69 grn_objcxx . . $ grn_obj# inspected;
70 type_name_size = grn_obj_namecxx . . $ grn_obj_name(a51d1bff955f2f21).(ctx, type, type_name, sizeof(type_name));
71 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&inspected, 0);
72 grn_inspectcxx . . $ grn_inspect(88456f97fe0d41a).(ctx, &inspected, default_value);
73 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, GRN_INVALID_ARGUMENT,
74 "cast_loose(): failed to set the default value: "
75 "<%.*s>: <%.*s>",
76 type_name_size,
77 type_name,
78 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&inspected),
79 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&inspected));
80 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &inspected);
81 }
82 }
83
84 return casted_value;
85 }
86
87 void
88 grn_proc_init_cast_loosecxx . . $ grn_proc_init_cast_loose(b578cd6e53d5fe91).(grn_ctxcxx . . $ grn_ctx# *ctx)
89 {
90 grn_proc_createcxx . . $ grn_proc_create(195df001e5324f57).(ctx, "cast_loose", -1, GRN_PROC_FUNCTIONcxx . . $ GRN_PROC_FUNCTION.,
91 func_cast_loosecxx . . $ func_cast_loose(fd082858389c8bb0)., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
92 }