diff options
-rw-r--r-- | URPM.xs | 47 |
1 files changed, 18 insertions, 29 deletions
@@ -1010,6 +1010,21 @@ call_package_callback(SV *urpm, SV *sv_pkg, SV *callback) { return sv_pkg != NULL; } +static void +push_in_depslist(struct s_Package *_pkg, SV *urpm, AV *depslist, SV *callback, HV *provides, HV *obsoletes, int packing) { + // leak if callback ever returns 1 ! (never happen) + SV *sv_pkg = sv_setref_pv(newSVpvs(""), "URPM::Package", _pkg); + if (call_package_callback(urpm, sv_pkg, callback)) { + if (provides) { + update_provides(_pkg, provides); + update_provides_files(_pkg, provides); + } + if (obsoletes) update_obsoletes(_pkg, obsoletes); + if (packing) pack_header(_pkg); + av_push(depslist, sv_pkg); + } +} + static int parse_line(AV *depslist, HV *provides, HV *obsoletes, URPM__Package pkg, char *buff, SV *urpm, SV *callback) { char *tag, *data; @@ -1024,12 +1039,7 @@ parse_line(AV *depslist, HV *provides, HV *obsoletes, URPM__Package pkg, char *b pkg->flag &= ~FLAG_ID_MASK; pkg->flag |= 1 + av_len(depslist); URPM__Package _pkg = memcpy(malloc(sizeof(struct s_Package)), pkg, sizeof(struct s_Package)); - SV *sv_pkg = sv_setref_pv(newSVpvs(""), "URPM::Package", _pkg); - if (call_package_callback(urpm, sv_pkg, callback)) { - if (provides) update_provides(_pkg, provides); - if (obsoletes) update_obsoletes(_pkg, obsoletes); - av_push(depslist, sv_pkg); - } + push_in_depslist(_pkg, urpm, depslist, callback, provides, obsoletes, 0); // reset package, next line will be for another one memset(pkg, 0, sizeof(struct s_Package)); } else if (!strcmp(tag, "filesize")) @@ -2926,21 +2936,10 @@ Urpm_parse_hdlist__XS(urpm, filename, ...) header = headerRead(fd, HEADER_MAGIC_YES); if (header != NULL) { struct s_Package *_pkg; - SV *sv_pkg; - _pkg = calloc(1, sizeof(struct s_Package)); _pkg->flag = 1 + av_len(depslist); _pkg->h = header; - sv_pkg = sv_setref_pv(newSVpvs(""), "URPM::Package", _pkg); - if (call_package_callback(urpm, sv_pkg, callback)) { - if (provides) { - update_provides(_pkg, provides); - update_provides_files(_pkg, provides); - } - if (obsoletes) update_obsoletes(_pkg, obsoletes); - if (packing) pack_header(_pkg); - av_push(depslist, sv_pkg); - } + push_in_depslist(_pkg, urpm, depslist, callback, provides, obsoletes, packing); } } while (header != NULL); @@ -2976,7 +2975,6 @@ Urpm_parse_rpm(urpm, filename, ...) if (depslist != NULL) { struct s_Package *_pkg; - SV *sv_pkg; int packing = 0; int keep_all_tags = 0; SV *callback = NULL; @@ -3020,16 +3018,7 @@ Urpm_parse_rpm(urpm, filename, ...) _pkg->flag = 1 + av_len(depslist); if (update_header(filename, _pkg, keep_all_tags, vsflags)) { - sv_pkg = sv_setref_pv(newSVpvs(""), "URPM::Package", _pkg); - if (call_package_callback(urpm, sv_pkg, callback)) { - if (provides) { - update_provides(_pkg, provides); - update_provides_files(_pkg, provides); - } - if (obsoletes) update_obsoletes(_pkg, obsoletes); - if (packing) pack_header(_pkg); - av_push(depslist, sv_pkg); - } + push_in_depslist(_pkg, urpm, depslist, callback, provides, obsoletes, packing); SPAGAIN; /* only one element read */ mXPUSHs(newSViv(av_len(depslist))); |