xs/loop.xs

filter: Statementstmt 92.9% 79 / 85 Branchbran 57.5% 84 / 146 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 70.5% 163 / 231 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Loop.c ↑ Summary include/dbil_abi_impl.h »
1 MODULE = DBIx::Loop PACKAGE = DBIx::Loop
2  
3 PROTOTYPES: DISABLE
4  
5 # _capability($driver_name) -> 'native' | 'pool' (the probe; internal)
6 SV *
7 _capability(driver_name)
8 SV *driver_name
9 CODE:
10 5 ▶ RETVAL = newSVpv(dbil_capability(aTHX_ SvOK(driver_name) ? driver_name : NULL), 0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpv(dbil_capability(aTHX_ SvOK(driver_name) ? driver_name : NULL), 0); 5 0 5
11 OUTPUT:
12 RETVAL
13  
14 # DBIx::Loop->new(dbh => $dbh, loop => $loop)
15 SV *
16 new(class, ...)
17 SV *class
18 CODE:
19 {
20 21 SV *dbh = NULL, *loop = NULL;
21 21 SV *dsn = NULL, *user = NULL, *pass = NULL, *attr = NULL;
22 21 int nworkers = 4;
23 21 int max_queue = 0;
24 int i;
25 0 ▶ const char *cls = (SvROK(class) && SvOBJECT(SvRV(class)))
Branch: 1 branch
BranchTrueFalseTotal
const char *cls = (SvROK(class) && SvOBJECT(SvRV(class))) 0 0 0
26 42 ▶ ? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class);
Branch: 7 branches
BranchTrueFalseTotal
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 21 21
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
27 147 ▶ for (i = 1; i + 1 < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i + 1 < items; i += 2) { 126 21 147
28 126 STRLEN kl; const char *k = SvPV_const(ST(i), kl);
29 126 ▶ if (kl == 3 && memEQ(k, "dbh", 3)) dbh = ST(i + 1);
Branch: 2 branches
BranchTrueFalseTotal
if (kl == 3 && memEQ(k, "dbh", 3)) dbh = ST(i + 1); 38 88 126
if (kl == 3 && memEQ(k, "dbh", 3)) dbh = ST(i + 1); 21 17 38
30 105 ▶ else if (kl == 4 && memEQ(k, "loop", 4)) loop = ST(i + 1);
Branch: 2 branches
BranchTrueFalseTotal
else if (kl == 4 && memEQ(k, "loop", 4)) loop = ST(i + 1); 71 34 105
else if (kl == 4 && memEQ(k, "loop", 4)) loop = ST(i + 1); 20 51 71
31 85 ▶ else if (kl == 3 && memEQ(k, "dsn", 3)) dsn = ST(i + 1);
Branch: 2 branches
BranchTrueFalseTotal
else if (kl == 3 && memEQ(k, "dsn", 3)) dsn = ST(i + 1); 17 68 85
else if (kl == 3 && memEQ(k, "dsn", 3)) dsn = ST(i + 1); 17 0 17
32 68 ▶ else if (kl == 4 && memEQ(k, "user", 4)) user = ST(i + 1);
Branch: 2 branches
BranchTrueFalseTotal
else if (kl == 4 && memEQ(k, "user", 4)) user = ST(i + 1); 51 17 68
else if (kl == 4 && memEQ(k, "user", 4)) user = ST(i + 1); 17 34 51
33 51 ▶ else if (kl == 4 && memEQ(k, "pass", 4)) pass = ST(i + 1);
Branch: 2 branches
BranchTrueFalseTotal
else if (kl == 4 && memEQ(k, "pass", 4)) pass = ST(i + 1); 34 17 51
else if (kl == 4 && memEQ(k, "pass", 4)) pass = ST(i + 1); 17 17 34
34 34 ▶ else if (kl == 4 && memEQ(k, "attr", 4)) attr = ST(i + 1);
Branch: 2 branches
BranchTrueFalseTotal
else if (kl == 4 && memEQ(k, "attr", 4)) attr = ST(i + 1); 17 17 34
else if (kl == 4 && memEQ(k, "attr", 4)) attr = ST(i + 1); 17 0 17
35 17 ▶ else if (kl == 7 && memEQ(k, "workers", 7))
Branch: 2 branches
BranchTrueFalseTotal
else if (kl == 7 && memEQ(k, "workers", 7)) 16 1 17
else if (kl == 7 && memEQ(k, "workers", 7)) 16 0 16
36 16 ▶ nworkers = SvIV(ST(i + 1)) > 0 ? (int)SvIV(ST(i + 1)) : 1;
Branch: 1 branch
BranchTrueFalseTotal
nworkers = SvIV(ST(i + 1)) > 0 ? (int)SvIV(ST(i + 1)) : 1; 16 0 16
37 1 ▶ else if (kl == 9 && memEQ(k, "max_queue", 9))
Branch: 2 branches
BranchTrueFalseTotal
else if (kl == 9 && memEQ(k, "max_queue", 9)) 1 0 1
else if (kl == 9 && memEQ(k, "max_queue", 9)) 1 0 1
38 1 ▶ max_queue = SvIV(ST(i + 1)) > 0 ? (int)SvIV(ST(i + 1)) : 0;
Branch: 1 branch
BranchTrueFalseTotal
max_queue = SvIV(ST(i + 1)) > 0 ? (int)SvIV(ST(i + 1)) : 0; 1 0 1
39 /* other options (backend, ...) reserved for later phases */
40 }
41 21 RETVAL = dbil_new(aTHX_ cls, dbh, loop, dsn, user, pass, attr,
42 nworkers, max_queue);
43 }
44 OUTPUT:
45 RETVAL
46  
47 # $db->query($sql, @bind) -> future
48 SV *
49 query(self, sql, ...)
50 SV *self
51 SV *sql
52 CODE:
53 {
54 98 AV *bind = (AV *)sv_2mortal((SV *)newAV());
55 int i;
56 122 ▶ for (i = 2; i < items; i++) av_push(bind, newSVsv(ST(i)));
Branch: 1 branch
BranchTrueFalseTotal
for (i = 2; i < items; i++) av_push(bind, newSVsv(ST(i))); 24 98 122
57 98 RETVAL = dbil_exec(aTHX_ self, 1, sql, bind);
58 }
59 OUTPUT:
60 RETVAL
61  
62 # $db->do($sql, @bind) -> future
63 SV *
64 do(self, sql, ...)
65 SV *self
66 SV *sql
67 CODE:
68 {
69 574 AV *bind = (AV *)sv_2mortal((SV *)newAV());
70 int i;
71 2172 ▶ for (i = 2; i < items; i++) av_push(bind, newSVsv(ST(i)));
Branch: 1 branch
BranchTrueFalseTotal
for (i = 2; i < items; i++) av_push(bind, newSVsv(ST(i))); 1598 574 2172
72 574 RETVAL = dbil_exec(aTHX_ self, 0, sql, bind);
73 }
74 OUTPUT:
75 RETVAL
76  
77 # The DBI select* family. Each is query() plus one fixed reshape of the result,
78 # so the reshape is a builtin continuation rather than a Perl closure: no
79 # closure is compiled per call and no Perl frame runs when the result lands.
80 # selectall_hashref takes its key field before the bind values, as DBI does.
81 SV *
82 selectall_arrayref(self, sql, ...)
83 SV *self
84 SV *sql
85 ALIAS:
86 selectall_arrayref = 1
87 selectrow_arrayref = 2
88 selectrow_array = 3
89 selectrow_hashref = 4
90 selectcol_arrayref = 5
91 selectall_hashref = 6
92 selectall_rowhash = 7
93 CODE:
94 {
95 24 AV *bind = (AV *)sv_2mortal((SV *)newAV());
96 24 SV *key = NULL;
97 SV *qf, *next;
98 24 int i = 2;
99 24 ▶ if (ix == DBIL_T_ALL_HASHREF) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == DBIL_T_ALL_HASHREF) { 3 21 24
100 3 ▶ if (items < 3)
Branch: 1 branch
BranchTrueFalseTotal
if (items < 3) 1 2 3
101 1 croak("DBIx::Loop->selectall_hashref: a key field is required");
102 2 key = ST(2);
103 2 i = 3;
104 }
105 30 ▶ for (; i < items; i++) av_push(bind, newSVsv(ST(i)));
Branch: 1 branch
BranchTrueFalseTotal
for (; i < items; i++) av_push(bind, newSVsv(ST(i))); 7 23 30
106 23 qf = sv_2mortal(dbil_exec(aTHX_ self, 1, sql, bind));
107 23 next = dbil_future_new(aTHX_ "DBIx::Loop::Future");
108 23 dbil_then_attach4(aTHX_ qf, next, sv_2mortal(newSViv((IV)ix)),
109 NULL, key);
110 23 RETVAL = next;
111 }
112 OUTPUT:
113 RETVAL
114  
115 SV *
116 capability(self)
117 SV *self
118 CODE:
119 {
120 5 SV *v = dbil_field(aTHX_ self, "capability", 10);
121 5 ▶ RETVAL = v ? newSVsv(v) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = v ? newSVsv(v) : &PL_sv_undef; 5 0 5
122 }
123 OUTPUT:
124 RETVAL
125  
126 SV *
127 loop(self)
128 SV *self
129 CODE:
130 {
131 3 SV *v = dbil_field(aTHX_ self, "loop", 4);
132 3 ▶ RETVAL = v ? newSVsv(v) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = v ? newSVsv(v) : &PL_sv_undef; 3 0 3
133 }
134 OUTPUT:
135 RETVAL
136  
137 SV *
138 dbh(self)
139 SV *self
140 CODE:
141 {
142 0 SV *v = dbil_field(aTHX_ self, "dbh", 3);
143 0 ▶ RETVAL = v ? newSVsv(v) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = v ? newSVsv(v) : &PL_sv_undef; 0 0 0
144 }
145 OUTPUT:
146 RETVAL
147  
148 void
149 disconnect(self)
150 SV *self
151 CODE:
152 {
153 12 ▶ HV *h = (SvROK(self) && SvTYPE(SvRV(self)) == SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
HV *h = (SvROK(self) && SvTYPE(SvRV(self)) == SVt_PVHV) 12 0 12
154 24 ▶ ? (HV *)SvRV(self) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(self) : NULL; 12 0 12
155 12 SV *dbh = dbil_field(aTHX_ self, "dbh", 3);
156 /* tear the pool down deterministically here (reap workers, drop fds)
157 * rather than at global destruction */
158 12 ▶ if (h) {
Branch: 1 branch
BranchTrueFalseTotal
if (h) { 12 0 12
159 12 SV **pp = hv_fetchs(h, "_pool", 0);
160 12 SV **np = hv_fetchs(h, "_native", 0);
161 12 ▶ if (pp && *pp && SvIOK(*pp)) {
Branch: 3 branches
BranchTrueFalseTotal
if (pp && *pp && SvIOK(*pp)) { 11 1 12
if (pp && *pp && SvIOK(*pp)) { 11 0 11
if (pp && *pp && SvIOK(*pp)) { 11 0 11
162 11 dbil_pool_free(aTHX_ INT2PTR(dbil_pool *, SvIV(*pp)));
163 11 (void)hv_delete(h, "_pool", 5, G_DISCARD);
164 }
165 12 ▶ if (np && *np && SvIOK(*np)) {
Branch: 3 branches
BranchTrueFalseTotal
if (np && *np && SvIOK(*np)) { 1 11 12
if (np && *np && SvIOK(*np)) { 1 0 1
if (np && *np && SvIOK(*np)) { 1 0 1
166 1 dbil_native_free(aTHX_ INT2PTR(dbil_native *, SvIV(*np)));
167 1 (void)hv_delete(h, "_native", 7, G_DISCARD);
168 }
169 }
170 12 ▶ if (dbh && SvROK(dbh)) {
Branch: 2 branches
BranchTrueFalseTotal
if (dbh && SvROK(dbh)) { 12 0 12
if (dbh && SvROK(dbh)) { 12 0 12
171 12 dSP;
172 12 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 12 12
173 12 ▶ EXTEND(SP, 1); PUSHs(dbh); PUTBACK;
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); PUSHs(dbh); PUTBACK; 0 12 12
174 12 call_method("disconnect", G_VOID | G_DISCARD | G_EVAL);
175 12 ▶ SPAGAIN; PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
SPAGAIN; PUTBACK; FREETMPS; LEAVE; 12 0 12
176 }
177 }
178  
179 # $db->txn(sub { my $tx = shift; ... }) -> future of the block's result.
180 # Acquires a slot (waits when saturated), BEGINs, runs the block with a pinned
181 # DBIx::Loop::Txn handle, COMMITs on success / ROLLBACKs on a die or failed
182 # block-future, releases the slot. Pool backend only for now: a native (Pg)
183 # transaction needs the native connection pool.
184 SV *
185 txn(self, block)
186 SV *self
187 SV *block
188 CODE:
189 {
190 14 SV *cap = dbil_field(aTHX_ self, "capability", 10);
191 14 SV *cargs = dbil_field(aTHX_ self, "connect_args", 12);
192 14 ▶ if (!SvROK(block) || SvTYPE(SvRV(block)) != SVt_PVCV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(block) || SvTYPE(SvRV(block)) != SVt_PVCV) 14 0 14
if (!SvROK(block) || SvTYPE(SvRV(block)) != SVt_PVCV) 0 14 14
193 0 croak("DBIx::Loop->txn: need a coderef");
194 14 ▶ if (!(cap && SvPOK(cap) && strEQ(SvPVX(cap), "pool")
Branch: 3 branches
BranchTrueFalseTotal
if (!(cap && SvPOK(cap) && strEQ(SvPVX(cap), "pool") 14 0 14
if (!(cap && SvPOK(cap) && strEQ(SvPVX(cap), "pool") 14 0 14
if (!(cap && SvPOK(cap) && strEQ(SvPVX(cap), "pool") 14 0 14
195 14 ▶ && cargs && SvROK(cargs)))
Branch: 2 branches
BranchTrueFalseTotal
&& cargs && SvROK(cargs))) 14 0 14
&& cargs && SvROK(cargs))) 0 14 14
196 0 croak("DBIx::Loop->txn: transactions need the pool backend "
197 "(connect() with a dsn); native-backend transactions arrive "
198 "with the native connection pool");
199 14 RETVAL = dbil_txn_start(aTHX_ self, block,
200 dbil_pool_of(aTHX_ self, cargs));
201 }
202 OUTPUT:
203 RETVAL
204  
205 # worker pids of the live pool (test/introspection aid)
206 void
207 _worker_pids(self)
208 SV *self
209 PPCODE:
210 {
211 16 ▶ if (SvROK(self) && SvTYPE(SvRV(self)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(self) && SvTYPE(SvRV(self)) == SVt_PVHV) { 16 0 16
if (SvROK(self) && SvTYPE(SvRV(self)) == SVt_PVHV) { 16 0 16
212 16 SV **pp = hv_fetchs((HV *)SvRV(self), "_pool", 0);
213 16 ▶ if (pp && *pp && SvIOK(*pp)) {
Branch: 3 branches
BranchTrueFalseTotal
if (pp && *pp && SvIOK(*pp)) { 16 0 16
if (pp && *pp && SvIOK(*pp)) { 16 0 16
if (pp && *pp && SvIOK(*pp)) { 16 0 16
214 16 dbil_pool *p = INT2PTR(dbil_pool *, SvIV(*pp));
215 int i;
216 16 ▶ EXTEND(SP, p->nw);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, p->nw); 16 0 16
EXTEND(SP, p->nw); 0 16 16
217 52 ▶ for (i = 0; i < p->nw; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < p->nw; i++) 36 16 52
218 36 mPUSHi((IV)p->w[i].pid);
219 }
220 }
221 }
222  
223 void
224 DESTROY(self)
225 SV *self
226 CODE:
227 {
228 21 ▶ if (SvROK(self) && SvTYPE(SvRV(self)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(self) && SvTYPE(SvRV(self)) == SVt_PVHV) { 21 0 21
if (SvROK(self) && SvTYPE(SvRV(self)) == SVt_PVHV) { 21 0 21
229 21 SV **pp = hv_fetchs((HV *)SvRV(self), "_pool", 0);
230 21 SV **np = hv_fetchs((HV *)SvRV(self), "_native", 0);
231 21 ▶ if (pp && *pp && SvIOK(*pp))
Branch: 3 branches
BranchTrueFalseTotal
if (pp && *pp && SvIOK(*pp)) 7 14 21
if (pp && *pp && SvIOK(*pp)) 7 0 7
if (pp && *pp && SvIOK(*pp)) 7 0 7
232 7 dbil_pool_free(aTHX_ INT2PTR(dbil_pool *, SvIV(*pp)));
233 21 ▶ if (np && *np && SvIOK(*np))
Branch: 3 branches
BranchTrueFalseTotal
if (np && *np && SvIOK(*np)) 0 21 21
if (np && *np && SvIOK(*np)) 0 0 0
if (np && *np && SvIOK(*np)) 0 0 0
234 0 dbil_native_free(aTHX_ INT2PTR(dbil_native *, SvIV(*np)));
235 }
236 }
« Loop.c ↑ Summary include/dbil_abi_impl.h »