GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_functions.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 72 105 68.6%
Functions: 18 27 66.7%
Branches: 8 14 57.1%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/functions.hpp"
30 #include "gate/memalloc.hpp"
31 #include "gate/exceptions.hpp"
32
33
34 namespace gate
35 {
36 2 FunctionArgument::FunctionArgument() noexcept
37 {
38 2 Mem::clear(impl);
39 2 impl.arg_type = GATE_FUNCTION_ARG_NONE;
40 2 }
41 1 FunctionArgument::FunctionArgument(unsigned char const& u_char) noexcept
42 {
43 1 impl.arg_value.u_chr = u_char;
44 1 impl.arg_type = GATE_FUNCTION_ARG_UCHAR;
45 1 }
46 FunctionArgument::FunctionArgument(signed char const& s_char) noexcept
47 {
48 impl.arg_value.s_chr = s_char;
49 impl.arg_type = GATE_FUNCTION_ARG_SCHAR;
50 }
51 1 FunctionArgument::FunctionArgument(unsigned short const& u_short) noexcept
52 {
53 1 impl.arg_value.u_short = u_short;
54 1 impl.arg_type = GATE_FUNCTION_ARG_USHORT;
55 1 }
56 1 FunctionArgument::FunctionArgument(signed short const& s_short) noexcept
57 {
58 1 impl.arg_value.s_short = s_short;
59 1 impl.arg_type = GATE_FUNCTION_ARG_SSHORT;
60 1 }
61 1 FunctionArgument::FunctionArgument(unsigned int const& u_int) noexcept
62 {
63 1 impl.arg_value.u_int = u_int;
64 1 impl.arg_type = GATE_FUNCTION_ARG_UINT;
65 1 }
66 2 FunctionArgument::FunctionArgument(signed int const& s_int) noexcept
67 {
68 2 impl.arg_value.s_int = s_int;
69 2 impl.arg_type = GATE_FUNCTION_ARG_SINT;
70 2 }
71 1 FunctionArgument::FunctionArgument(unsigned long const& u_long) noexcept
72 {
73 1 impl.arg_value.u_long = u_long;
74 1 impl.arg_type = GATE_FUNCTION_ARG_ULONG;
75 1 }
76 1 FunctionArgument::FunctionArgument(signed long const& s_long) noexcept
77 {
78 1 impl.arg_value.s_long = s_long;
79 1 impl.arg_type = GATE_FUNCTION_ARG_SLONG;
80 1 }
81 1 FunctionArgument::FunctionArgument(gate_unsigned_long_long_t const& u_long_long) noexcept
82 {
83 1 impl.arg_value.u_long_long = u_long_long;
84 1 impl.arg_type = GATE_FUNCTION_ARG_ULONGLONG;
85 1 }
86 1 FunctionArgument::FunctionArgument(gate_signed_long_long_t const& s_long_long) noexcept
87 {
88 1 impl.arg_value.s_long_long = s_long_long;
89 1 impl.arg_type = GATE_FUNCTION_ARG_SLONGLONG;
90 1 }
91 FunctionArgument::FunctionArgument(float const& flt) noexcept
92 {
93 impl.arg_value.flt = flt;
94 impl.arg_type = GATE_FUNCTION_ARG_FLOAT;
95 }
96 FunctionArgument::FunctionArgument(double const& dbl) noexcept
97 {
98 impl.arg_value.dbl = dbl;
99 impl.arg_type = GATE_FUNCTION_ARG_DOUBLE;
100 }
101 FunctionArgument::FunctionArgument(long double const& ldbl) noexcept
102 {
103 impl.arg_value.ldbl = ldbl;
104 impl.arg_type = GATE_FUNCTION_ARG_LONGDOUBLE;
105 }
106 FunctionArgument::FunctionArgument(void* ptr) noexcept
107 {
108 impl.arg_value.ptr = ptr;
109 impl.arg_type = GATE_FUNCTION_ARG_POINTER;
110 }
111 FunctionArgument::FunctionArgument(void* ptr, unsigned int length) noexcept
112 {
113 impl.arg_value.blob.blob_ptr = ptr;
114 impl.arg_value.blob.blob_size = length;
115 impl.arg_type = GATE_FUNCTION_ARG_BLOB;
116 }
117
118 FunctionArgument::FunctionArgument(FunctionArgument const& src) noexcept
119 {
120 Mem::copy(this->impl, src.impl);
121 }
122 FunctionArgument& FunctionArgument::operator=(FunctionArgument const& src) noexcept
123 {
124 Mem::copy(this->impl, src.impl);
125 return *this;
126 }
127 12 FunctionArgument::~FunctionArgument() noexcept
128 {
129 12 }
130
131 4 gate_function_argument_t* FunctionArgument::c_impl() noexcept
132 {
133 4 return &this->impl;
134 }
135 gate_function_argument_t const* FunctionArgument::c_impl() const noexcept
136 {
137 return &this->impl;
138 }
139
140 2 FunctionArgument::TypeEnum FunctionArgument::getType() const
141 {
142 2 return static_cast<TypeEnum>(this->impl.arg_type);
143 }
144
145 2 void const* FunctionArgument::getValuePtr() const
146 {
147 2 return static_cast<void const*>(&this->impl.arg_value.ptr);
148 }
149
150
151
152
153
154
155
156
157 2 FunctionArgument Function::invokeGeneric(gate_funcptr_t funcPtr, uint32_t flags,
158 FunctionArgument* args, size_t argcount)
159 {
160 2 FunctionArgument retVal;
161
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 gate_function_argument* first_arg = (argcount == 0) ? NULL : args->c_impl();
162
163
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 result_t result = gate_function_invoke_generic(funcPtr, flags, first_arg, argcount, retVal.c_impl());
164
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
165
166 2 return retVal;
167 }
168
169
170 3 void Function::invokeGuarded(gate_entrypoint_t entryPoint, void* entryParam,
171 gate_function_fault_handler_t faultHandler, void* faultParam)
172 {
173 3 result_t result = gate_function_invoke_guarded(entryPoint, entryParam, faultHandler, faultParam);
174
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 GATEXX_CHECK_EXCEPTION(result);
175 1 }
176
177 3 static gate_result_t runnable_dispatcher(void* param)
178 {
179 3 result_t result = results::Ok;
180 3 IRunnable* runnable = static_cast<IRunnable*>(param);
181
182
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (runnable)
183 {
184 try
185 {
186
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
3 runnable->run();
187 1 result = results::Ok;
188 }
189 2 catch (Throwable const& xcpt)
190 {
191 1 result = xcpt.getResult();
192 }
193 1 catch (...)
194 {
195 1 result = results::UnknownException;
196 }
197 }
198 3 return result;
199 }
200
201
202 3 void Function::invokeGuarded(IRunnable& runnable)
203 {
204 3 Function::invokeGuarded(&runnable_dispatcher, &runnable);
205 1 }
206
207
208
209 } // end of namespace gate
210