Branch Coverage

CDB_File.xs
Criterion Covered Total %
branch 183 272 67.2


line true false branch
164 0 215 if (newpos < len) { errno = ENOMEM; return -1; }
173 34 9 if (!head || (head->num >= CDB_HPLIST)) {
0 34 if (!head || (head->num >= CDB_HPLIST)) {
183 0 43 if (posplus(c, 8) == -1) return -1;
184 0 43 if (posplus(c, keylen) == -1) return -1;
185 0 43 if (posplus(c, datalen) == -1) return -1;
197 672 183 while (len) {
234 2284 1 if (c->map) {
235 2284 0 if ((pos > c->size) || (c->size - pos < len)) {
0 2284 if ((pos > c->size) || (c->size - pos < len)) {
244 0 1 if (PerlIO_seek(c->fh, pos, SEEK_SET) == -1) return -1;
245 1 0 while (len > 0) {
249 0 1 while ((r == -1) && (errno == EINTR));
0 0 while ((r == -1) && (errno == EINTR));
250 0 1 if (r == -1) return -1;
251 1 0 if (r == 0) {
265 140 140 while (len > 0) {
267 140 0 if (n > len) n = len;
268 0 140 if (cdb_read(c, buf, n, pos) == -1) return -1;
269 0 140 if (memcmp(buf, key, n)) return 0;
285 140 18 if (!c->loop) {
287 1 139 if (cdb_read(c,buf,8,(u << 3) & 2047) == -1) return -1;
289 6 133 if (!c->hslots) return 0;
298 151 0 while (c->loop < c->hslots) {
299 0 151 if (cdb_read(c,buf,8,c->kpos) == -1) return -1;
301 11 140 if (!pos) return 0;
304 116 24 if (c->kpos == c->hpos + (c->hslots << 3)) c->kpos = c->hpos;
306 140 0 if (u == c->khash) {
307 0 140 if (cdb_read(c,buf,8,pos) == -1) return -1;
309 140 0 if (u == len)
333 0 52 if (cdb_read(c, buf, 4, 0) == -1) readerror();
343 407 44 if (c->curpos < c->end) {
344 0 407 if (cdb_read(c, buf, 8, c->curpos) == -1) readerror();
347 51 356 CDB_SET_PV(c->curkey, klen);
0 51 CDB_SET_PV(c->curkey, klen);
407 0 CDB_SET_PV(c->curkey, klen);
349 0 407 if (cdb_read(c, SvPVX(c->curkey), klen, c->curpos + 8) == -1) readerror();
359 0 400 if (cdb_read(c, buf, 8, c->curpos) == -1) readerror();
366 30 6 if (c->end != 0) {
438 1 12 if (!f) XSRETURN_NO;
446 12 0 if (fstat(fd, &st) == 0) {
447 12 0 if (st.st_size <= 0xffffffff) {
451 11 1 if (x != (char *)-1) {
477 1 166 if (!SvOK(k)) {
1 0 if (!SvOK(k)) {
1 0 if (!SvOK(k)) {
480 166 0 kp = SvPV(k, klen);
481 158 8 if (this->end && sv_eq(this->curkey, k)) {
156 2 if (this->end && sv_eq(this->curkey, k)) {
482 0 156 if (cdb_read(this, buf, 8, this->curpos) == -1) readerror();
485 126 30 if (this->fetch_advance) {
487 13 113 if (!iter_key(this)) iter_end(this);
493 9 1 if ((found != 0) && (found != 1)) readerror();
1 8 if ((found != 0) && (found != 1)) readerror();
496 164 1 if (found) {
499 164 0 SvUPGRADE(ST(0), SVt_PV);
502 164 0 CDB_SET_PV(ST(0), dlen);
164 0 CDB_SET_PV(ST(0), dlen);
164 0 CDB_SET_PV(ST(0), dlen);
504 0 164 if (cdb_read(this, SvPVX(ST(0)), dlen, cdb_datapos(this)) == -1) readerror();
523 110 11 while(iter_key(this)) {
525 110 0 kp = SvPV(this->curkey, klen);
527 110 0 if ((found != 0) && (found != 1)) readerror();
0 110 if ((found != 0) && (found != 1)) readerror();
533 110 0 CDB_SET_PV(keyvalue, dlen);
0 110 CDB_SET_PV(keyvalue, dlen);
110 0 CDB_SET_PV(keyvalue, dlen);
535 0 110 if (cdb_read(this, SvPVX(keyvalue), dlen, cdb_datapos(this)) == -1) readerror();
537 0 110 if (! hv_store_ent(RETVAL, this->curkey, keyvalue, 0)) {
564 0 12 if (!SvOK(k)) {
0 0 if (!SvOK(k)) {
0 0 if (!SvOK(k)) {
570 11 1 kp = SvPV(k, klen);
573 18 12 if ((found != 0) && (found != 1)) readerror();
0 18 if ((found != 0) && (found != 1)) readerror();
574 12 18 if (!found) break;
579 18 0 CDB_SET_PV(x, dlen);
0 18 CDB_SET_PV(x, dlen);
18 0 CDB_SET_PV(x, dlen);
581 0 18 if (cdb_read(this, SvPVX(x), dlen, cdb_datapos(this)) == -1) readerror();
598 1 8 if (!SvOK(k)) {
1 0 if (!SvOK(k)) {
1 0 if (!SvOK(k)) {
601 8 0 kp = SvPV(k, klen);
603 4 4 if (RETVAL != 0 && RETVAL != 1) readerror();
0 4 if (RETVAL != 0 && RETVAL != 1) readerror();
617 13 0 if (sv_isobject(db) && (SvTYPE(SvRV(db)) == SVt_PVMG) ) {
12 1 if (sv_isobject(db) && (SvTYPE(SvRV(db)) == SVt_PVMG) ) {
618 12 0 this = (cdb*)SvIV(SvRV(db));
622 11 1 if (this->map) {
641 20 1 if (iter_key(this)) {
660 0 164 if (!SvOK(k)) {
0 0 if (!SvOK(k)) {
0 0 if (!SvOK(k)) {
665 163 1 if (this->end == 0 || !sv_eq(this->curkey, k))
0 163 if (this->end == 0 || !sv_eq(this->curkey, k))
668 145 19 if (iter_key(this)) {
691 1 10 if (!cdbmake->f) XSRETURN_UNDEF;
693 0 10 if (cdb_make_start(cdbmake) < 0) XSRETURN_UNDEF;
718 10 0 if (sv_isobject(sv) && (SvTYPE(SvRV(sv)) == SVt_PVMG) ) {
10 0 if (sv_isobject(sv) && (SvTYPE(SvRV(sv)) == SVt_PVMG) ) {
719 10 0 this = (cdb_make*)SvIV(SvRV(sv));
720 0 10 if(this->f){PerlIO_close(this->f);}
737 43 42 for (x = 1; x < items; x += 2) {
740 32 11 kp = SvPV(k, klen); vp = SvPV(v, vlen);
40 3 kp = SvPV(k, klen); vp = SvPV(v, vlen);
744 0 43 if (PerlIO_write(this->f, packbuf, 8) < 8) writeerror();
747 0 43 if (PerlIO_write(this->f, kp, klen) < klen) writeerror();
748 0 43 if (PerlIO_write(this->f, vp, vlen) < vlen) writeerror();
750 0 43 if (cdb_make_addend(this, klen, vlen, h) == -1) nomem();
766 2560 10 for (i = 0; i < 256; ++i)
769 9 10 for (x = this->head; x; x = x->next) {
771 43 9 while (i--)
776 2560 10 for (i = 0; i < 256; ++i) {
778 9 2551 if (u > memsize)
785 0 10 if (memsize > u) { errno = ENOMEM; XSRETURN_UNDEF; }
787 0 10 New(0xCDB, this->split, memsize, struct cdb_hp);
792 2560 10 for (i = 0; i < 256; ++i) {
798 9 10 for (x = this->head; x; x = x->next) {
800 43 9 while (i--)
802 0 9 if (prev) Safefree(prev);
805 9 1 if (prev) Safefree(prev);
807 2560 10 for (i = 0; i < 256; ++i) {
814 86 2560 for (u = 0; u < len; ++u)
818 43 2560 for (u = 0; u < count; ++u) {
820 3 43 while (this->hash[where].p)
821 2 1 if (++where == len)
826 86 2560 for (u = 0; u < len; ++u) {
829 0 86 if (PerlIO_write(this->f, buf, 8) == -1) XSRETURN_UNDEF;
830 0 86 if (posplus(this, 8) == -1) XSRETURN_UNDEF;
836 0 10 if (PerlIO_flush(this->f) == EOF) writeerror();
839 0 10 if (PerlIO_write(this->f, this->final, sizeof this->final) < sizeof this->final) writeerror();
840 0 10 if (PerlIO_flush(this->f) == EOF) writeerror();
842 0 10 if (fsync(PerlIO_fileno(this->f)) == -1) XSRETURN_NO;
843 0 10 if (PerlIO_close(this->f) == EOF) XSRETURN_NO;
846 0 10 if (rename(this->fntemp, this->fn)) {