xs/main_xsgen.cc

filter: Statementstmt 54.1% 39 / 72 Branchbran 26.6% 24 / 90 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 38.8% 63 / 162 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/xs/uri/router.h ↑ Summary xs/main.xs »
1 /*
2 * This file was generated automatically by XS::Install::FrozenShit::ParseXS version 3.57 from the
3 * contents of main.xs. Do not edit this file, edit main.xs instead.
4 *
5 * ANY CHANGES MADE HERE WILL BE LOST!
6 *
7 */
8  
9 #line 1 "xs/main.xs"
10 #include <xs/export.h>
11 #include <xs/typemap.h>
12 #include <xs/uri/router.h>
13 #include <regex>
14  
15 using namespace xs;
16 using namespace xs::uri;
17 using namespace panda;
18 using namespace panda::uri;
19 using namespace panda::uri::router;
20  
21 static void router_add (SvRouter* r, const Scalar& sv_path, const Scalar& value) {
22 auto copy = Scalar::create();
23 SvSetSV_nosteal(copy, value);
24 auto path = xs::in<string>(sv_path);
25 if (SvRXOK(sv_path)) {
26 if (path.find("(?^") == 0) {
27 static std::regex rere("^\\(\\?\\^[a-z]*:");
28 auto re = regex_replace(std::string(path.data(), path.length()), rere, "");
29 path = string(re.data(), re.length()-1);
30 }
31 r->add({Regex(path), copy});
32 } else {
33 r->add({path, copy});
34 }
35 }
36  
37 #line 38 "xs/main_xsgen.cc"
38 #ifndef PERL_UNUSED_VAR
39 # define PERL_UNUSED_VAR(var) if (0) var = var
40 #endif
41  
42 #ifndef dVAR
43 # define dVAR dNOOP
44 #endif
45  
46  
47 /* This stuff is not part of the API! You have been warned. */
48 #ifndef PERL_VERSION_DECIMAL
49 # define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
50 #endif
51 #ifndef PERL_DECIMAL_VERSION
52 # define PERL_DECIMAL_VERSION \
53 PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
54 #endif
55 #ifndef PERL_VERSION_GE
56 # define PERL_VERSION_GE(r,v,s) \
57 (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
58 #endif
59 #ifndef PERL_VERSION_LE
60 # define PERL_VERSION_LE(r,v,s) \
61 (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
62 #endif
63  
64 /* XS_INTERNAL is the explicit static-linkage variant of the default
65 * XS macro.
66 *
67 * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
68 * "STATIC", ie. it exports XSUB symbols. You probably don't want that
69 * for anything but the BOOT XSUB.
70 *
71 * See XSUB.h in core!
72 */
73  
74  
75 /* TODO: This might be compatible further back than 5.10.0. */
76 #if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
77 # undef XS_EXTERNAL
78 # undef XS_INTERNAL
79 # if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
80 # define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
81 # define XS_INTERNAL(name) STATIC XSPROTO(name)
82 # endif
83 # if defined(__SYMBIAN32__)
84 # define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
85 # define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
86 # endif
87 # ifndef XS_EXTERNAL
88 # if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
89 # define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
90 # define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
91 # else
92 # ifdef __cplusplus
93 # define XS_EXTERNAL(name) extern "C" XSPROTO(name)
94 # define XS_INTERNAL(name) static XSPROTO(name)
95 # else
96 # define XS_EXTERNAL(name) XSPROTO(name)
97 # define XS_INTERNAL(name) STATIC XSPROTO(name)
98 # endif
99 # endif
100 # endif
101 #endif
102  
103 /* perl >= 5.10.0 && perl <= 5.15.1 */
104  
105  
106 /* The XS_EXTERNAL macro is used for functions that must not be static
107 * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
108 * macro defined, the best we can do is assume XS is the same.
109 * Dito for XS_INTERNAL.
110 */
111 #ifndef XS_EXTERNAL
112 # define XS_EXTERNAL(name) XS(name)
113 #endif
114 #ifndef XS_INTERNAL
115 # define XS_INTERNAL(name) XS(name)
116 #endif
117  
118 /* Now, finally, after all this mess, we want an XS::Install::FrozenShit::ParseXS
119 * internal macro that we're free to redefine for varying linkage due
120 * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
121 * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
122 */
123  
124 #undef XS_EUPXS
125 #if defined(PERL_EUPXS_ALWAYS_EXPORT)
126 # define XS_EUPXS(name) XS_EXTERNAL(name)
127 #else
128 /* default to internal */
129 # define XS_EUPXS(name) XS_INTERNAL(name)
130 #endif
131  
132 #ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
133 #define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)
134  
135 /* prototype to pass -Wmissing-prototypes */
136 STATIC void
137 S_croak_xs_usage(const CV *const cv, const char *const params);
138  
139 STATIC void
140 S_croak_xs_usage(const CV *const cv, const char *const params)
141 {
142 const GV *const gv = CvGV(cv);
143  
144 PERL_ARGS_ASSERT_CROAK_XS_USAGE;
145  
146 if (gv) {
147 const char *const gvname = GvNAME(gv);
148 const HV *const stash = GvSTASH(gv);
149 const char *const hvname = stash ? HvNAME(stash) : NULL;
150  
151 if (hvname)
152 Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
153 else
154 Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
155 } else {
156 /* Pants. I don't think that it should be possible to get here. */
157 Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
158 }
159 }
160 #undef PERL_ARGS_ASSERT_CROAK_XS_USAGE
161  
162 #define croak_xs_usage S_croak_xs_usage
163  
164 #endif
165  
166 /* NOTE: the prototype of newXSproto() is different in versions of perls,
167 * so we define a portable version of newXSproto()
168 */
169 #ifdef newXS_flags
170 #define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
171 #else
172 #define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
173 #endif /* !defined(newXS_flags) */
174  
175 #if PERL_VERSION_LE(5, 21, 5)
176 # define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
177 #else
178 # define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
179 #endif
180  
181 /* simple backcompat versions of the TARGx() macros with no optimisation */
182 #ifndef TARGi
183 # define TARGi(iv, do_taint) sv_setiv_mg(TARG, iv)
184 # define TARGu(uv, do_taint) sv_setuv_mg(TARG, uv)
185 # define TARGn(nv, do_taint) sv_setnv_mg(TARG, nv)
186 #endif
187  
188 #line 189 "xs/main_xsgen.cc"
189  
190  
191 12 ▶XS_EUPXS(XS_URI__Router_new) { xs::throw_guard(cv, [=]()
Branch: 1 branch
BranchTrueFalseTotal
XS_EUPXS(XS_URI__Router_new) { xs::throw_guard(cv, [=]() 6 0 6
192 {
193 6 dVAR; dXSARGS;
194 6 ▶ if (items < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items < 1) 0 6 6
195 0 croak_xs_usage(cv, "CLASS, ...");
196 {
197 SvRouter * RETVAL;
198 6 SV* CLASS = ST(0)
199 ;
200 #line 49 "xs/main.xs"
201 xs::Sv PROTO; PERL_UNUSED_VAR(PROTO);
202 PROTO = CLASS;
203 RETVAL = new SvRouter();
204 for (I32 i = 1; i < items - 1; i += 2) {
205 router_add(RETVAL, ST(i), ST(i+1));
206 }
207 #line 208 "xs/main_xsgen.cc"
208 {
209 SV * RETVALSV;
210 6 ▶ RETVALSV = xs::out(RETVAL, PROTO).detach();
Branch: 1 branch
BranchTrueFalseTotal
RETVALSV = xs::out(RETVAL, PROTO).detach(); 6 0 6
211 6 ▶ RETVALSV = sv_2mortal(RETVALSV);
Branch: 1 branch
BranchTrueFalseTotal
RETVALSV = sv_2mortal(RETVALSV); 6 0 6
212 6 ST(0) = RETVALSV;
213 }
214 6 }
215 6 XSRETURN(1);
216 6 }); }
217  
218  
219  
220 0 ▶XS_EUPXS(XS_URI__Router_add) { xs::throw_guard(cv, [=]()
Branch: 1 branch
BranchTrueFalseTotal
XS_EUPXS(XS_URI__Router_add) { xs::throw_guard(cv, [=]() 0 0 0
221 {
222 0 dVAR; dXSARGS;
223 0 ▶ if (items != 3)
Branch: 1 branch
BranchTrueFalseTotal
if (items != 3) 0 0 0
224 0 croak_xs_usage(cv, "THIS, path, value");
225 PERL_UNUSED_VAR(ax); /* -Wall */
226 0 SP -= items;
227 {
228 0 ▶ SvRouter* THIS = xs::in<SvRouter *>(ST(0)); if (!SvOK(ST(0))) throw "undef not allowed as THIS";
Branch: 2 branches
BranchTrueFalseTotal
SvRouter* THIS = xs::in<SvRouter *>(ST(0)); if (!SvOK(ST(0))) throw "undef not allowed as THIS"; 0 0 0
SvRouter* THIS = xs::in<SvRouter *>(ST(0)); if (!SvOK(ST(0))) throw "undef not allowed as THIS"; 0 0 0
229 ;
230 0 ▶ Scalar path = ST(1);
Branch: 1 branch
BranchTrueFalseTotal
Scalar path = ST(1); 0 0 0
231 0 ▶ if (!path && SvOK(ST(1))) throw "arg is not a 'Scalar' value"
Branch: 3 branches
BranchTrueFalseTotal
if (!path && SvOK(ST(1))) throw "arg is not a 'Scalar' value" 0 0 0
if (!path && SvOK(ST(1))) throw "arg is not a 'Scalar' value" 0 0 0
if (!path && SvOK(ST(1))) throw "arg is not a 'Scalar' value" 0 0 0
232 ;
233 0 ▶ Scalar value = ST(2);
Branch: 1 branch
BranchTrueFalseTotal
Scalar value = ST(2); 0 0 0
234 0 ▶ if (!value && SvOK(ST(2))) throw "arg is not a 'Scalar' value"
Branch: 3 branches
BranchTrueFalseTotal
if (!value && SvOK(ST(2))) throw "arg is not a 'Scalar' value" 0 0 0
if (!value && SvOK(ST(2))) throw "arg is not a 'Scalar' value" 0 0 0
if (!value && SvOK(ST(2))) throw "arg is not a 'Scalar' value" 0 0 0
235 ;
236 #line 56 "xs/main.xs"
237 router_add(THIS, path, value);
238 #line 239 "xs/main_xsgen.cc"
239 0 PUTBACK;
240 0 return;
241 0 }
242 0 }); }
243  
244  
245  
246 100 ▶XS_EUPXS(XS_URI__Router_route) { xs::throw_guard(cv, [=]()
Branch: 1 branch
BranchTrueFalseTotal
XS_EUPXS(XS_URI__Router_route) { xs::throw_guard(cv, [=]() 50 0 50
247 {
248 50 dVAR; dXSARGS;
249 50 ▶ if (items < 2 || items > 3)
Branch: 2 branches
BranchTrueFalseTotal
if (items < 2 || items > 3) 50 0 50
if (items < 2 || items > 3) 0 50 50
250 0 croak_xs_usage(cv, "THIS, path, sv_method= Sv()");
251 PERL_UNUSED_VAR(ax); /* -Wall */
252 50 SP -= items;
253 {
254 50 ▶ SvRouter* THIS = xs::in<SvRouter *>(ST(0)); if (!SvOK(ST(0))) throw "undef not allowed as THIS";
Branch: 2 branches
BranchTrueFalseTotal
SvRouter* THIS = xs::in<SvRouter *>(ST(0)); if (!SvOK(ST(0))) throw "undef not allowed as THIS"; 50 0 50
SvRouter* THIS = xs::in<SvRouter *>(ST(0)); if (!SvOK(ST(0))) throw "undef not allowed as THIS"; 0 50 50
255 ;
256 50 string_view path;
257 50 Sv sv_method;
258  
259 { STRLEN __path_len;
260 50 const char* __path_buf = SvPV(ST(1), __path_len);
261 50 path = decltype(path)(__path_buf, __path_len); }
262 ;
263  
264 50 ▶ if (items < 3)
Branch: 1 branch
BranchTrueFalseTotal
if (items < 3) 34 16 50
265 34 sv_method = Sv();
266 else {
267 16 ▶ sv_method = ST(2)
Branch: 1 branch
BranchTrueFalseTotal
sv_method = ST(2) 16 0 16
268 ;
269 }
270 #line 60 "xs/main.xs"
271 Method method = sv_method ? Method(SvIV(sv_method)) : Method::Get;
272 auto opt = THIS->route(path, method);
273 if (!opt) XSRETURN_UNDEF;
274 auto& res = *opt;
275  
276 if (GIMME_V != G_ARRAY) {
277 XPUSHs(res.value);
278 XSRETURN(1);
279 }
280 else {
281 I32 nret = res.captures.size() + 1;
282 EXTEND(SP, nret);
283 XPUSHs(res.value);
284 for (auto& s : res.captures) mXPUSHs(xs::out(s).detach());
285 XSRETURN(nret);
286 }
287 #line 288 "xs/main_xsgen.cc"
288 PUTBACK;
289 return;
290 50 }
291 50 }); }
292  
293  
294  
295 0 ▶XS_EUPXS(XS_URI__Router_bench) { xs::throw_guard(cv, [=]()
Branch: 1 branch
BranchTrueFalseTotal
XS_EUPXS(XS_URI__Router_bench) { xs::throw_guard(cv, [=]() 0 0 0
296 {
297 0 dVAR; dXSARGS;
298 0 ▶ if (items != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items != 2) 0 0 0
299 0 croak_xs_usage(cv, "THIS, path");
300 {
301 uint64_t RETVAL;
302 0 ▶ dXSTARG;
Branch: 2 branches
BranchTrueFalseTotal
dXSTARG; 0 0 0
dXSTARG; 0 0 0
303 0 ▶ SvRouter* THIS = xs::in<SvRouter *>(ST(0)); if (!SvOK(ST(0))) throw "undef not allowed as THIS";
Branch: 2 branches
BranchTrueFalseTotal
SvRouter* THIS = xs::in<SvRouter *>(ST(0)); if (!SvOK(ST(0))) throw "undef not allowed as THIS"; 0 0 0
SvRouter* THIS = xs::in<SvRouter *>(ST(0)); if (!SvOK(ST(0))) throw "undef not allowed as THIS"; 0 0 0
304 ;
305 0 string_view path;
306  
307 { STRLEN __path_len;
308 0 const char* __path_buf = SvPV(ST(1), __path_len);
309 0 path = decltype(path)(__path_buf, __path_len); }
310 ;
311 #line 79 "xs/main.xs"
312 RETVAL = 0;
313 for (int i = 0; i < 1000; ++i) {
314 auto opt = THIS->route(path);
315 if (opt) ++RETVAL;
316 }
317 #line 318 "xs/main_xsgen.cc"
318 0 ▶ TARGu((UV)RETVAL, 1);
Branch: 2 branches
BranchTrueFalseTotal
TARGu((UV)RETVAL, 1); 0 0 0
TARGu((UV)RETVAL, 1); 0 0 0
319 0 ST(0) = TARG;
320 }
321 0 XSRETURN(1);
322 0 }); }
323  
324 #ifdef __cplusplus
325 extern "C" {
326 #endif
327  
328 12 ▶XS_EXTERNAL(boot_URI__Router) { xs::throw_guard(cv, [=]() mutable
Branch: 1 branch
BranchTrueFalseTotal
XS_EXTERNAL(boot_URI__Router) { xs::throw_guard(cv, [=]() mutable 6 0 6
329 {
330 #if PERL_VERSION_LE(5, 21, 5)
331 dVAR; dXSARGS;
332 #else
333 6 dVAR; dXSBOOTARGSXSAPIVERCHK;
334 #endif
335 #if PERL_VERSION_LE(5, 8, 999) /* PERL_VERSION_LT is 5.33+ */
336 char* file = __FILE__;
337 #else
338 6 const char* file = __FILE__;
339 #endif
340  
341 PERL_UNUSED_VAR(file);
342  
343 PERL_UNUSED_VAR(cv); /* -W */
344 PERL_UNUSED_VAR(items); /* -W */
345 #if PERL_VERSION_LE(5, 21, 5)
346 XS_VERSION_BOOTCHECK;
347 # ifdef XS_APIVERSION_BOOTCHECK
348 XS_APIVERSION_BOOTCHECK;
349 # endif
350 #endif
351  
352 6 newXS_deffile("URI::Router::new", XS_URI__Router_new);
353 6 newXS_deffile("URI::Router::add", XS_URI__Router_add);
354 6 newXS_deffile("URI::Router::route", XS_URI__Router_route);
355 6 newXS_deffile("URI::Router::bench", XS_URI__Router_bench);
356  
357 /* Initialisation Section */
358  
359 #line 31 "xs/main.xs"
360 {
361 using M = Method;
362 Stash s("URI::Router");
363 xs::exp::create_constants(s, {
364 {"METHOD_UNSPECIFIED", int(M::Unspecified)},
365 {"METHOD_OPTIONS", int(M::Options) },
366 {"METHOD_GET", int(M::Get) },
367 {"METHOD_HEAD", int(M::Head) },
368 {"METHOD_POST", int(M::Post) },
369 {"METHOD_PUT", int(M::Put) },
370 {"METHOD_DELETE", int(M::Delete) },
371 {"METHOD_TRACE", int(M::Trace) },
372 {"METHOD_CONNECT", int(M::Connect) },
373 });
374 xs::exp::autoexport(s);
375 }
376  
377 #line 378 "xs/main_xsgen.cc"
378  
379 /* End of Initialisation Section */
380  
381 #if PERL_VERSION_LE(5, 21, 5)
382 # if PERL_VERSION_GE(5, 9, 0)
383 if (PL_unitcheckav)
384 call_list(PL_scopestack_ix, PL_unitcheckav);
385 # endif
386 XSRETURN_YES;
387 #else
388 6 Perl_xs_boot_epilog(aTHX_ ax);
389 #endif
390 24 ▶}); }
Branch: 13 branches
BranchTrueFalseTotal
}); } 6 0 6
}); } 6 0 6
}); } 6 0 6
}); } 6 0 6
}); } 6 0 6
}); } 6 0 6
}); } 6 0 6
}); } 6 0 6
}); } 6 0 6
}); } 6 0 6
}); } 6 0 6
}); } 0 0 0
}); } 0 0 0
391  
392 #ifdef __cplusplus
393 }
394 #endif
« src/xs/uri/router.h ↑ Summary xs/main.xs »