File Coverage

src/xs/basic.cc
Criterion Covered Total %
statement 24 32 75.0
branch 19 38 50.0
condition n/a
subroutine n/a
pod n/a
total 43 70 61.4


line stmt bran cond sub pod time code
1             #include
2             #include
3             #include
4             #include
5             #include
6             #include
7              
8             namespace xs {
9              
10             using panda::string;
11              
12             #ifdef PERL_IMPLICIT_CONTEXT
13             PerlInterpreter* my_perl_auto_t::main_interp = PERL_GET_THX;
14             #endif
15              
16             my_perl_auto_t my_perl;
17              
18 36           static std::vector> end_cbs;
19 36           static const auto mt_id = std::this_thread::get_id();
20              
21 0           void at_perl_destroy (const panda::function& f) {
22 0           end_cbs.push_back(f);
23 0           }
24              
25 36           void __call_at_perl_destroy () {
26 36 50         for (auto& f : end_cbs) f();
    0          
27 36           Sv::__at_perl_destroy();
28 36           Scalar::__at_perl_destroy();
29 36           Simple::__at_perl_destroy();
30 36           }
31              
32 0           void __call_at_thread_create () {
33             #ifdef PERL_IMPLICIT_CONTEXT
34             my_perl_auto_t::main_interp = nullptr;
35             #endif
36 0           }
37              
38 136           void __boot_module (const char* rawmod, void (*bootfunc)(pTHX_ CV*), const char* version, const char* file) {
39 272           string bs("::bootstrap");
40 272 50         string module(strlen(rawmod) + bs.length() + 1);
41 136 50         module.assign(rawmod);
42              
43 136           auto len = module.length();
44 136 50         auto ptr = module.buf();
45 2414 100         for (size_t i = 0; i < len; ++i) {
46 2278 100         if (ptr[i] != '_' || i >= len - 1 || ptr[i+1] != '_') continue;
    50          
    50          
47 204           ptr[i] = ':';
48 204           ptr[i+1] = ':';
49 204           ++i;
50             }
51              
52 272 50         auto xsname = module + bs;
53              
54 272 50         Sub sub = newXS(xsname.c_str(), bootfunc, file);
    50          
    50          
55 136 50         sub.call(Simple(module), Simple(version));
    50          
    50          
56 136           }
57              
58 0           bool is_perl_thread () {
59 0 0         if (std::this_thread::get_id() == mt_id) return true;
60             #ifndef PERL_IMPLICIT_CONTEXT
61 0           return false;
62             #else
63             return (PerlInterpreter*)my_perl;
64             #endif
65             }
66              
67 144 50         }
    50