| 1 |
|
| #include <xs/basic.h> |
| 2 |
|
| #include <thread> |
| 3 |
|
| #include <vector> |
| 4 |
|
| #include <xs/Sub.h> |
| 5 |
|
| #include <xs/Simple.h> |
| 6 |
|
| #include <panda/string.h> |
| 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 |
|
| static std::vector<panda::function<void()>> end_cbs; |
| 19 |
|
| static const auto mt_id = std::this_thread::get_id(); |
| 20 |
|
| |
| 21 |
0 |
| void at_perl_destroy (const panda::function<void()>& f) { |
| 22 |
0 |
| end_cbs.push_back(f); |
| 23 |
0 |
| } |
| 24 |
|
| |
| 25 |
37 |
| void __call_at_perl_destroy () { |
| 26 |
37 |
▶ | for (auto& f : end_cbs) f(); |
Branch: 2 branches
| Branch | True | False | Total |
| for (auto& f : end_cbs) f(); |
0 |
0 |
0 |
| for (auto& f : end_cbs) f(); |
0 |
37 |
37 |
|
| 27 |
37 |
| Sv::__at_perl_destroy(); |
| 28 |
37 |
| Scalar::__at_perl_destroy(); |
| 29 |
37 |
| Simple::__at_perl_destroy(); |
| 30 |
37 |
| } |
| 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 |
140 |
| void __boot_module (const char* rawmod, void (*bootfunc)(pTHX_ CV*), const char* version, const char* file) { |
| 39 |
140 |
| string bs("::bootstrap"); |
| 40 |
140 |
▶ | string module(strlen(rawmod) + bs.length() + 1); |
Branch: 1 branch
| Branch | True | False | Total |
| string module(strlen(rawmod) + bs.length() + 1); |
140 |
0 |
140 |
|
| 41 |
140 |
▶ | module.assign(rawmod); |
Branch: 1 branch
| Branch | True | False | Total |
| module.assign(rawmod); |
140 |
0 |
140 |
|
| 42 |
|
| |
| 43 |
140 |
| auto len = module.length(); |
| 44 |
140 |
▶ | auto ptr = module.buf(); |
Branch: 1 branch
| Branch | True | False | Total |
| auto ptr = module.buf(); |
140 |
0 |
140 |
|
| 45 |
2485 |
▶ | for (size_t i = 0; i < len; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < len; ++i) { |
2345 |
140 |
2485 |
|
| 46 |
2345 |
▶ | if (ptr[i] != '_' || i >= len - 1 || ptr[i+1] != '_') continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (ptr[i] != '_' || i >= len - 1 || ptr[i+1] != '_') continue; |
210 |
2135 |
2345 |
| if (ptr[i] != '_' || i >= len - 1 || ptr[i+1] != '_') continue; |
210 |
0 |
210 |
| if (ptr[i] != '_' || i >= len - 1 || ptr[i+1] != '_') continue; |
0 |
210 |
210 |
|
| 47 |
210 |
| ptr[i] = ':'; |
| 48 |
210 |
| ptr[i+1] = ':'; |
| 49 |
210 |
| ++i; |
| 50 |
|
| } |
| 51 |
|
| |
| 52 |
140 |
▶ | auto xsname = module + bs; |
Branch: 1 branch
| Branch | True | False | Total |
| auto xsname = module + bs; |
140 |
0 |
140 |
|
| 53 |
|
| |
| 54 |
140 |
▶ | Sub sub = newXS(xsname.c_str(), bootfunc, file); |
Branch: 3 branches
| Branch | True | False | Total |
| Sub sub = newXS(xsname.c_str(), bootfunc, file); |
140 |
0 |
140 |
| Sub sub = newXS(xsname.c_str(), bootfunc, file); |
140 |
0 |
140 |
| Sub sub = newXS(xsname.c_str(), bootfunc, file); |
140 |
0 |
140 |
|
| 55 |
140 |
▶ | sub.call<void>(Simple(module), Simple(version)); |
Branch: 3 branches
| Branch | True | False | Total |
| sub.call<void>(Simple(module), Simple(version)); |
140 |
0 |
140 |
| sub.call<void>(Simple(module), Simple(version)); |
140 |
0 |
140 |
| sub.call<void>(Simple(module), Simple(version)); |
140 |
0 |
140 |
|
| 56 |
140 |
| } |
| 57 |
|
| |
| 58 |
0 |
| bool is_perl_thread () { |
| 59 |
0 |
▶ | if (std::this_thread::get_id() == mt_id) return true; |
Branch: 1 branch
| Branch | True | False | Total |
| if (std::this_thread::get_id() == mt_id) return true; |
0 |
0 |
0 |
|
| 60 |
|
| #ifndef PERL_IMPLICIT_CONTEXT |
| 61 |
0 |
| return false; |
| 62 |
|
| #else |
| 63 |
|
| return (PerlInterpreter*)my_perl; |
| 64 |
|
| #endif |
| 65 |
|
| } |
| 66 |
|
| |
| 67 |
|
| } |