diff options
author | Thierry Vignaud <tv@mageia.org> | 2012-06-14 18:23:50 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mageia.org> | 2012-06-14 18:23:50 +0000 |
commit | dc65c01ee09b29731b1623a6c54734847c07d5af (patch) | |
tree | adb17f096e4330d5751dbdbda49fb72869d04f63 /URPM.xs | |
parent | d0f685de3ac9ca8fd93311f06695f0c03b7299d7 (diff) | |
download | perl-URPM-dc65c01ee09b29731b1623a6c54734847c07d5af.tar perl-URPM-dc65c01ee09b29731b1623a6c54734847c07d5af.tar.gz perl-URPM-dc65c01ee09b29731b1623a6c54734847c07d5af.tar.bz2 perl-URPM-dc65c01ee09b29731b1623a6c54734847c07d5af.tar.xz perl-URPM-dc65c01ee09b29731b1623a6c54734847c07d5af.zip |
(_run_cb_while_traversing) introduce this helper
Diffstat (limited to 'URPM.xs')
-rw-r--r-- | URPM.xs | 63 |
1 files changed, 21 insertions, 42 deletions
@@ -113,6 +113,24 @@ static int rpmError_callback() { return RPMLOG_DEFAULT; } +static inline int _run_cb_while_traversing(SV *callback, Header header) { + dSP; + URPM__Package pkg = calloc(1, sizeof(struct s_Package)); + + pkg->flag = FLAG_ID_INVALID | FLAG_NO_HEADER_FREE; + pkg->h = header; + + PUSHMARK(SP); + mXPUSHs(sv_setref_pv(newSVpvs(""), "URPM::Package", pkg)); + PUTBACK; + + int count = call_sv(callback, G_SCALAR); + + SPAGAIN; + pkg->h = NULL; /* avoid using it anymore, in case it has been copied inside callback */ + return count; +} + static inline void _header_free(URPM__Package pkg) { if (pkg->h && !(pkg->flag & FLAG_NO_HEADER_FREE)) pkg->h = headerFree(pkg->h); @@ -2530,20 +2548,7 @@ Db_traverse(db,callback) mi = rpmtsInitIterator(db->ts, RPMDBI_PACKAGES, NULL, 0); while ((header = rpmdbNextIterator(mi))) { if (SvROK(callback)) { - dSP; - URPM__Package pkg = calloc(1, sizeof(struct s_Package)); - - pkg->flag = FLAG_ID_INVALID | FLAG_NO_HEADER_FREE; - pkg->h = header; - - PUSHMARK(SP); - mXPUSHs(sv_setref_pv(newSVpvs(""), "URPM::Package", pkg)); - PUTBACK; - - call_sv(callback, G_DISCARD | G_SCALAR); - - SPAGAIN; - pkg->h = NULL; /* avoid using it anymore, in case it has been copied inside callback */ + _run_cb_while_traversing(callback, header); } ++count; } @@ -2583,20 +2588,7 @@ Db_traverse_tag(db,tag,names,callback) mi = rpmtsInitIterator(db->ts, rpmtag, name, str_len); while ((header = rpmdbNextIterator(mi))) { if (SvROK(callback)) { - dSP; - URPM__Package pkg = calloc(1, sizeof(struct s_Package)); - - pkg->flag = FLAG_ID_INVALID | FLAG_NO_HEADER_FREE; - pkg->h = header; - - PUSHMARK(SP); - mXPUSHs(sv_setref_pv(newSVpvs(""), "URPM::Package", pkg)); - PUTBACK; - - call_sv(callback, G_DISCARD | G_SCALAR); - - SPAGAIN; - pkg->h = NULL; /* avoid using it anymore, in case it has been copied inside callback */ + _run_cb_while_traversing(callback, header); } ++count; } @@ -2626,20 +2618,7 @@ Db_traverse_tag_find(db,tag,name,callback) ovsflags = ts_nosignature(db->ts); mi = rpmtsInitIterator(db->ts, rpmtag, name, 0); while ((header = rpmdbNextIterator(mi))) { - dSP; - URPM__Package pkg = calloc(1, sizeof(struct s_Package)); - - pkg->flag = FLAG_ID_INVALID | FLAG_NO_HEADER_FREE; - pkg->h = header; - - PUSHMARK(SP); - mXPUSHs(sv_setref_pv(newSVpvs(""), "URPM::Package", pkg)); - PUTBACK; - - int count = call_sv(callback, G_SCALAR); - - SPAGAIN; - pkg->h = NULL; /* avoid using it anymore, in case it has been copied inside callback */ + int count = _run_cb_while_traversing(callback, header); if (count == 1 && POPi) { found = 1; |