Coro.build

filter: Statementstmt 35.7% 15 / 42 Branchbran 28.0% 14 / 50 Conditioncond 20.0% 4 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 66.6% 2 / 3 Podpod 0.0% 0 / 2 totaltotal 27.3% 35 / 128 CC 34 SCAR 61.0
CC
34
Cov
29%
get_coro_defines_string
474.1
have_inc
2.0
BEGIN
1.0
CRAP 447.9
↑ Summary Coro.pm »
1 # Copyright (c) 2023 Yuki Kimoto
2 # MIT License
3  
4 2 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶sub get_coro_defines_string {
Subroutine get_coro_defines_string: called CC=34 SCAR=61.6
Pod undocumented
7 # Copied from Coro/Makefile.PL
8 0 ▶ sub have_inc($) {
Subroutine have_inc: not called CC=1 SCAR=6.9
Pod undocumented
9 scalar grep -r "$_/$_[0]", $Config{usrinc}, split / /, $Config{incpth}
10 0 }
11 2 my $iface;
12  
13 2 my $LIBS = [];
14
15 # default to assembly on x86 and x86_64 sometimes
16 2 ▶ my $iface_asm = $Config{archname} =~ /^(i[3456]86|amd64|x86_64|MSWin32-x64)-/ ? "a" : undef;
Branch: 1 branch
BranchTrueFalseTotal
$SPVM::Builder::Config::Util::Config{'archname'} =~ /^(i[3456]86|amd64|x86_64|MSWin32-x64)-/ ? : 2 0 2
17
18 # detect whether this perl is threaded, for those broken operating
19 # systems that need it.
20
21 my $pthread = $Config{libs} =~ /-lpthread/
22 || $Config{ldflags} =~ /-pthread/
23 2 ▶ || $Config{archname} =~ /-thread/;
Condition33%2/6
$SPVM::Builder::Config::Util::Config{'libs'} =~ /-lpthread/ || $SPVM::Builder::Config::Util::Config{'ldflags'} =~ /-pthread/ || $SPVM::Builder::Config::Util::Config{'archname'} =~ /-thread/
l!l&&r!l&&!r
200
$SPVM::Builder::Config::Util::Config{"libs"} =~ /-lpthread/ or $SPVM::Builder::Config::Util::Config{"ldflags"} =~ /-pthread/
l!l&&r!l&&!r
200
MC/DC0%0/3
$SPVM::Builder::Config::Util::Config{'libs'} =~ /-lpthread/ || $SPVM::Builder::Config::Util::Config{'ldflags'} =~ /-pthread/ || $SPVM::Builder::Config::Util::Config{'archname'} =~ /-thread/
$SPVM::Builder::Config::Util::Config{"libs"} =~ /-lpthread/ $SPVM::Builder::Config::Util::Config{"ldflags"} =~ /-pthread/ $SPVM::Builder::Config::Util::Config{'archname'} =~ /-thread/
Truth table25%1/4
A or B || C
A= $SPVM::Builder::Config::Util::Config{"libs"} =~ /-lpthread/B= $SPVM::Builder::Config::Util::Config{"ldflags"} =~ /-pthread/C= $SPVM::Builder::Config::Util::Config{'archname'} =~ /-thread/
ABCresult
1XX1
01X1
0011
0000
24
25 2 ▶ if (exists $ENV{CORO_INTERFACE}) {
Branch: 12 branches
BranchTrueFalseTotal
if (exists $ENV{'CORO_INTERFACE'}) { } 0 2 2
elsif ($^O =~ /mswin32/i) { } 0 2 2
elsif ($^O =~ /cygwin/) { } 0 2 2
elsif ($^O =~ /irix/) { } 0 2 2
elsif ($^O =~ /linux/) { } 2 0 2
elsif ($^O =~ /freebsd/) { } 0 0 0
elsif ($^O =~ /netbsd/) { } 0 0 0
elsif ($^O =~ /(openbsd|mirbsd)/) { } 0 0 0
elsif ($^O =~ /solaris/) { } 0 0 0
elsif ($^O =~ /darwin/) { } 0 0 0
elsif ($^O =~ /dragonfly/) { } 0 0 0
elsif (&have_inc('ucontext.h')) { } 0 0 0
26 0 $iface = $ENV{CORO_INTERFACE};
27
28 } elsif ($^O =~ /mswin32/i) {
29 # nothing works, really, without deep hacks
30 0 $iface = "f";
31
32 } elsif ($^O =~ /cygwin/) {
33 # cygwin true to its form, be an order of magnitutde slower,
34 # while using twice the amount of ram. but it works! yeah!
35 0 $iface = "p";
36
37 } elsif ($^O =~ /irix/) {
38 # sigaltstack works like sigstack, i.e. expects stack pointer, not stack base
39 # but wikipeida lists it as 100% posix compliant. geeeee.
40 0 $iface = "i";
41
42 } elsif ($^O =~ /linux/) {
43 # everything "just works", as expected
44 2 ▶ $iface = $iface_asm || "s";
Condition50%1/2
$iface_asm || 's'
l!l
20
MC/DC0%0/1
$iface_asm || 's'
$iface_asm
Truth table50%1/2
A
A= $iface_asm
Aresult
11
00
45
46 } elsif ($^O =~ /freebsd/) {
47 # FreeBSD 4.x has ucontext.h but no makecontext et al. (see BUGS section of
48 # man context).
49 #
50 # FreeBSD 6.2 has marginally working ucontext, setjmp and asm, but
51 # some 5.8.8's barf when threaded due to broken threading.
52
53 0 ▶ $iface = $iface_asm || "s";
Condition0%0/2
$iface_asm || 's'
l!l
00
MC/DC0%0/1
$iface_asm || 's'
$iface_asm
Truth table0%0/2
A
A= $iface_asm
Aresult
11
00
54
55 } elsif ($^O =~ /netbsd/) {
56 # netbsd is totally broken (pthreads are incompatible with ucontext or
57 # other stack switching mechanisms) therefore, default to pthread -
58 # hey, it might actually work, with some hacks.
59 0 $iface = "p";
60
61 0 ▶ if (!$pthread) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pthread) 0 0 0
62 # ugh, pthreads need to be linked into the main program :/
63 0 ▶ $iface = $iface_asm || "s";
Condition0%0/2
$iface_asm || 's'
l!l
00
MC/DC0%0/1
$iface_asm || 's'
$iface_asm
Truth table0%0/2
A
A= $iface_asm
Aresult
11
00
64 }
65
66 } elsif ($^O =~ /(openbsd|mirbsd)/) {
67 # mirbsd seems to be bug-to-bug compatible openbsd fork,
68 # with the name change being the biggest difference.
69 0 ▶ if (!$pthread) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $pthread) { } 0 0 0
70 # asm seems to work, setjmp might, ucontext is missing,
71 # threads lets not talk about
72 # try setjmp/longjmp on 4.4, but pthread on earlier
73 0 ▶ $iface = $iface_asm || ($Config{osvers} >= 4.4 ? "s" : "p");
Branch: 1 branch
BranchTrueFalseTotal
$SPVM::Builder::Config::Util::Config{'osvers'} >= 4.4 ? : 0 0 0
Condition0%0/3
$iface_asm || ($SPVM::Builder::Config::Util::Config{'osvers'} >= 4.4 ? 's' : 'p')
l!l&&r!l&&!r
000
MC/DC0%0/2
$iface_asm || ($SPVM::Builder::Config::Util::Config{'osvers'} >= 4.4 ? 's' : 'p')
$iface_asm ($SPVM::Builder::Config::Util::Config{'osvers'} >= 4.4 ? 's' : 'p')
Truth table0%0/3
A || B
A= $iface_asmB= ($SPVM::Builder::Config::Util::Config{'osvers'} >= 4.4 ? 's' : 'p')
ABresult
1X1
011
000
74 } else {
75 # seems newer openbsd platforms have marginally working pthreads, but
76 # their pthreads break sigaltstack - reading the sigaltstack sources
77 # again shows how fundamentally clueless those people are (if no thread
78 # has ever been created, then the program is bound to a kernel-scheduled
79 # entity. get that? GET THAT?)
80 0 $iface = "p";
81 }
82
83 } elsif ($^O =~ /solaris/) {
84 # setjmp, ucontext seem to work, as well as asm
85 0 ▶ $iface = $iface_asm || "s";
Condition0%0/2
$iface_asm || 's'
l!l
00
MC/DC0%0/1
$iface_asm || 's'
$iface_asm
Truth table0%0/2
A
A= $iface_asm
Aresult
11
00
86
87 } elsif ($^O =~ /darwin/) {
88 # assembler doesn't support .type
89 # ucontext is of course totally broken (it just crashes)
90 # surprisingly, pthreads seem to work
91 0 $iface = "s";
92
93 } elsif ($^O =~ /dragonfly/) {
94 # ucontext is totally broken on dragonfly bsd:
95 # Fatal error 'siglongjmp()ing between thread contexts is undefined by POSIX 1003.1
96 0 $iface = "s";
97
98 } elsif (have_inc "ucontext.h") { # shame on this heuristic
99 0 $iface = "u";
100
101 } else {
102 0 $iface = "s";
103 }
104  
105 2 my $DEFINE;
106  
107 2 ▶ if ($iface eq "u") {
Branch: 8 branches
BranchTrueFalseTotal
if ($iface eq 'u') { } 0 2 2
elsif ($iface eq 's') { } 0 2 2
elsif ($iface eq 'l') { } 0 2 2
elsif ($iface eq 'i') { } 0 2 2
elsif ($iface eq 'w') { } 0 2 2
elsif ($iface eq 'f') { } 0 2 2
elsif ($iface eq 'a') { } 2 0 2
elsif ($iface eq 'p') { } 0 0 0
108 0 $DEFINE .= " -DCORO_UCONTEXT";
109 } elsif ($iface eq "s") {
110 0 $DEFINE .= " -D_FORTIFY_SOURCE=0";
111 0 $DEFINE .= " -DCORO_SJLJ";
112 } elsif ($iface eq "l") {
113 0 $DEFINE .= " -DCORO_LINUX";
114 } elsif ($iface eq "i") {
115 0 $DEFINE .= " -DCORO_IRIX";
116 } elsif ($iface eq "w") {
117 0 $DEFINE .= " -DCORO_LOSER";
118 } elsif ($iface eq "f") {
119 0 $DEFINE .= " -DCORO_FIBER";
120 } elsif ($iface eq "a") {
121 2 $DEFINE .= " -DCORO_ASM";
122 } elsif ($iface eq "p") {
123 0 $DEFINE .= " -DCORO_PTHREAD";
124 0 $LIBS = ["-lpthread"];
125 } else {
126 0 goto retry;
127 }
128
129 2 ▶ my $stacksize = $^O eq "linux" && $] < 5.008008 ? 128 * 1024 : 16384;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'linux' && $] < 5.008008 ? : 0 2 2
Condition33%1/3
$^O eq "linux" and $] < "5.008008"
!ll&&!rl&&r
020
MC/DC0%0/2
$^O eq "linux" and $] < "5.008008"
$^O eq "linux" $] < "5.008008"
Truth table33%1/3
A and B
A= $^O eq "linux"B= $] < "5.008008"
ABresult
0X0
100
111
130
131 2 $DEFINE .= " -DCORO_STACKSIZE=$stacksize";
132
133 2 return $DEFINE;
134 }
135  
136 my $config = SPVM::Builder::Config->new_c99;
137  
138 $config->is_resource(1);
139  
140 my $coro_defines_string = &get_coro_defines_string();
141  
142 my @coro_defines = grep { length } map { s/^-D//r } split(/\s+/, $coro_defines_string);
143  
144 $config->add_define(@coro_defines);
145  
146 my @source_files = qw(
147 coro.c
148 );
149  
150 $config->add_source_file(@source_files);
151  
152  
153 $config;
↑ Summary Coro.pm »