aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mageia.org>2013-01-20 21:08:04 +0000
committerThierry Vignaud <tv@mageia.org>2013-01-20 21:08:04 +0000
commitb622efbf507d05404cdc76d20d0f04830b5b1742 (patch)
treebeb919357be538b792aaec158e68fdd319513cf8
parent0eacdf9a90f9288c7670d263d523098044f6abbc (diff)
downloadperl-URPM-b622efbf507d05404cdc76d20d0f04830b5b1742.tar
perl-URPM-b622efbf507d05404cdc76d20d0f04830b5b1742.tar.gz
perl-URPM-b622efbf507d05404cdc76d20d0f04830b5b1742.tar.bz2
perl-URPM-b622efbf507d05404cdc76d20d0f04830b5b1742.tar.xz
perl-URPM-b622efbf507d05404cdc76d20d0f04830b5b1742.zip
(push_in_depslist) factorize common code for adding a package to {depslist}
-rw-r--r--URPM.xs47
1 files changed, 18 insertions, 29 deletions
diff --git a/URPM.xs b/URPM.xs
index 3f1166d..e553153 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -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)));