The following commit has been merged in the master branch:
commit 7c7ce899094c4694776314ab356f4db38eece217
Author: Guillem Jover <[email protected]>
Date:   Thu Dec 1 03:33:38 2011 +0100

    libdpkg: Add new arch_empty special architecture
    
    This will allow to easily distinguish an empty architecture value, while
    always having an initialized architecture variable.

diff --git a/lib/dpkg/arch.c b/lib/dpkg/arch.c
index 19a19fd..a5fbf8a 100644
--- a/lib/dpkg/arch.c
+++ b/lib/dpkg/arch.c
@@ -75,6 +75,11 @@ static struct dpkg_arch arch_item_none = {
        .type = arch_none,
        .next = NULL,
 };
+static struct dpkg_arch arch_item_empty = {
+       .name = "",
+       .type = arch_empty,
+       .next = NULL,
+};
 
 static struct dpkg_arch arch_item_any = {
        .name = "any",
@@ -122,8 +127,10 @@ dpkg_arch_find(const char *name)
        struct dpkg_arch *arch, *last_arch = NULL;
        enum dpkg_arch_type type;
 
-       if (name == NULL || name[0] == '\0')
+       if (name == NULL)
                return &arch_item_none;
+       if (name[0] == '\0')
+               return &arch_item_empty;
 
        for (arch = arch_list; arch; arch = arch->next) {
                if (strcmp(arch->name, name) == 0)
@@ -154,6 +161,8 @@ dpkg_arch_get(enum dpkg_arch_type type)
        switch (type) {
        case arch_none:
                return &arch_item_none;
+       case arch_empty:
+               return &arch_item_empty;
        case arch_wildcard:
                return &arch_item_any;
        case arch_all:
diff --git a/lib/dpkg/arch.h b/lib/dpkg/arch.h
index 384bb0d..fbb9268 100644
--- a/lib/dpkg/arch.h
+++ b/lib/dpkg/arch.h
@@ -30,6 +30,7 @@ DPKG_BEGIN_DECLS
 
 enum dpkg_arch_type {
        arch_none,
+       arch_empty,
        arch_illegal,
        arch_wildcard,
        arch_all,
diff --git a/lib/dpkg/fields.c b/lib/dpkg/fields.c
index 32e99b6..cc827d3 100644
--- a/lib/dpkg/fields.c
+++ b/lib/dpkg/fields.c
@@ -181,9 +181,6 @@ f_architecture(struct pkginfo *pigp, struct pkgbin *pifp,
                struct parsedb_state *ps,
                const char *value, const struct fieldinfo *fip)
 {
-  if (!*value)
-    return;
-
   pifp->arch = dpkg_arch_find(value);
   if (pifp->arch->type == arch_illegal)
     parse_warn(ps, _("'%s' is not a valid architecture name: %s"),
diff --git a/lib/dpkg/parse.c b/lib/dpkg/parse.c
index 2926788..f15c135 100644
--- a/lib/dpkg/parse.c
+++ b/lib/dpkg/parse.c
@@ -195,12 +195,12 @@ pkg_parse_verify(struct parsedb_state *ps,
     /* We always want usable architecture information (as long as the package
      * is in such a state that it make sense), so that it can be used safely
      * on string comparisons and the like. */
-    if (pkgbin->arch == NULL)
+    if (pkgbin->arch->type == arch_none)
       parse_warn(ps, _("missing %s"), "architecture");
-    else if (pkgbin->arch->type == arch_none)
+    else if (pkgbin->arch->type == arch_empty)
       parse_warn(ps, _("empty value for %s"), "architecture");
   }
-  if (pkgbin->arch == NULL)
+  if (pkgbin->arch->type == arch_empty)
     pkgbin->arch = dpkg_arch_get(arch_none);
 
   if (pkgbin->arch->type == arch_all && pkgbin->multiarch == multiarch_same)
diff --git a/lib/dpkg/pkg.c b/lib/dpkg/pkg.c
index 49c27c0..f554653 100644
--- a/lib/dpkg/pkg.c
+++ b/lib/dpkg/pkg.c
@@ -39,7 +39,7 @@ pkgbin_blank(struct pkgbin *pkgbin)
        pkgbin->installedsize = NULL;
        pkgbin->bugs = NULL;
        pkgbin->origin = NULL;
-       pkgbin->arch = NULL;
+       pkgbin->arch = dpkg_arch_get(arch_none);
        blankversion(&pkgbin->version);
        pkgbin->conffiles = NULL;
        pkgbin->arbs = NULL;
diff --git a/lib/dpkg/test/t-arch.c b/lib/dpkg/test/t-arch.c
index c70f1d6..89bd6d5 100644
--- a/lib/dpkg/test/t-arch.c
+++ b/lib/dpkg/test/t-arch.c
@@ -90,13 +90,16 @@ test_dpkg_arch_find(void)
        test_pass(arch->type == arch_wildcard);
        test_pass(dpkg_arch_get(arch_wildcard) == arch);
 
-       /* Empty architectures are marked none. */
+       /* Test missing architecture. */
        arch = dpkg_arch_find(NULL);
        test_pass(arch->type == arch_none);
        test_pass(dpkg_arch_get(arch_none) == arch);
        test_str(arch->name, ==, "");
+
+       /* Test empty architectures. */
        arch = dpkg_arch_find("");
-       test_pass(arch->type == arch_none);
+       test_pass(arch->type == arch_empty);
+       test_pass(dpkg_arch_get(arch_empty) == arch);
        test_str(arch->name, ==, "");
 
        /* Test for an unknown type. */

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to