The following commit has been merged in the master branch:
commit 6f4ebe26f5ed2e301d88436db34efcc69e0b2d3d
Author: Guillem Jover <[email protected]>
Date:   Thu Dec 1 03:32:37 2011 +0100

    libdpkg: Add new dpkg_arch_get() to retrieve special architectures
    
    Switch dpkg_arch_get_native() to dpkg_arch_get(arch_native), and
    dpkg_arch_find() calls to direct dpkg_arch_get() ones.

diff --git a/lib/dpkg/arch.c b/lib/dpkg/arch.c
index 3a77e17..19a19fd 100644
--- a/lib/dpkg/arch.c
+++ b/lib/dpkg/arch.c
@@ -4,6 +4,7 @@
  *
  * Copyright © 2011 Linaro Limited
  * Copyright © 2011 Raphaël Hertzog <[email protected]>
+ * Copyright © 2011 Guillem Jover <[email protected]>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -142,12 +143,31 @@ dpkg_arch_find(const char *name)
 }
 
 /**
- * Return the struct dpkg_arch corresponding to the native architecture.
+ * Return the struct dpkg_arch corresponding to the architecture type.
+ *
+ * The function only returns instances for types which are unique. For
+ * forward-compatibility any unknown type will return NULL.
  */
 struct dpkg_arch *
-dpkg_arch_get_native(void)
+dpkg_arch_get(enum dpkg_arch_type type)
 {
-       return &arch_item_native;
+       switch (type) {
+       case arch_none:
+               return &arch_item_none;
+       case arch_wildcard:
+               return &arch_item_any;
+       case arch_all:
+               return &arch_item_all;
+       case arch_native:
+               return &arch_item_native;
+       case arch_illegal:
+       case arch_foreign:
+       case arch_unknown:
+               internerr("architecture type %d is not unique", type);
+       default:
+               /* Ignore unknown types for forward-compatibility. */
+               return NULL;
+       }
 }
 
 /**
diff --git a/lib/dpkg/arch.h b/lib/dpkg/arch.h
index 047bd27..384bb0d 100644
--- a/lib/dpkg/arch.h
+++ b/lib/dpkg/arch.h
@@ -4,6 +4,7 @@
  *
  * Copyright © 2011 Linaro Limited
  * Copyright © 2011 Raphaël Hertzog <[email protected]>
+ * Copyright © 2011 Guillem Jover <[email protected]>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -27,23 +28,25 @@
 
 DPKG_BEGIN_DECLS
 
+enum dpkg_arch_type {
+       arch_none,
+       arch_illegal,
+       arch_wildcard,
+       arch_all,
+       arch_native,
+       arch_foreign,
+       arch_unknown,
+};
+
 struct dpkg_arch {
        struct dpkg_arch *next;
        const char *name;
-       enum dpkg_arch_type {
-               arch_none,
-               arch_all,
-               arch_native,
-               arch_foreign,
-               arch_wildcard,
-               arch_unknown,
-               arch_illegal,
-       } type;
+       enum dpkg_arch_type type;
 };
 
 const char *dpkg_arch_name_is_illegal(const char *name) DPKG_ATTR_NONNULL(1);
 struct dpkg_arch *dpkg_arch_find(const char *name);
-struct dpkg_arch *dpkg_arch_get_native(void);
+struct dpkg_arch *dpkg_arch_get(enum dpkg_arch_type type);
 struct dpkg_arch *dpkg_arch_get_list(void);
 void dpkg_arch_reset_list(void);
 
diff --git a/lib/dpkg/depcon.c b/lib/dpkg/depcon.c
index 6f96890..2c51006 100644
--- a/lib/dpkg/depcon.c
+++ b/lib/dpkg/depcon.c
@@ -67,9 +67,9 @@ archsatisfied(struct pkgbin *it, struct deppossi *against)
 
        pkg_arch = it->arch;
        if (dep_arch->type == arch_none || dep_arch->type == arch_all)
-               dep_arch = dpkg_arch_get_native();
+               dep_arch = dpkg_arch_get(arch_native);
        if (pkg_arch->type == arch_none || pkg_arch->type == arch_all)
-               pkg_arch = dpkg_arch_get_native();
+               pkg_arch = dpkg_arch_get(arch_native);
 
        return (dep_arch == pkg_arch);
 }
diff --git a/lib/dpkg/fields.c b/lib/dpkg/fields.c
index 506b618..32e99b6 100644
--- a/lib/dpkg/fields.c
+++ b/lib/dpkg/fields.c
@@ -455,7 +455,7 @@ f_dependency(struct pkginfo *pigp, struct pkgbin *pifp,
                  fip->integer == dep_replaces) {
         /* Conflics/Breaks/Replaces get an implicit "any" arch qualifier. */
         dop->arch_is_implicit = true;
-        dop->arch = dpkg_arch_find("any");
+        dop->arch = dpkg_arch_get(arch_wildcard);
       } else {
         /* Otherwise use the pkgbin architecture, which will be assigned to
          * later on by parse.c, once we can guarantee we have parsed it from
diff --git a/lib/dpkg/libdpkg.Versions b/lib/dpkg/libdpkg.Versions
index 5542909..cefaba4 100644
--- a/lib/dpkg/libdpkg.Versions
+++ b/lib/dpkg/libdpkg.Versions
@@ -180,7 +180,7 @@ LIBDPKG_PRIVATE {
        # Architecture database
        dpkg_arch_name_is_illegal;
        dpkg_arch_find;
-       dpkg_arch_get_native;
+       dpkg_arch_get;
        dpkg_arch_get_list;
        dpkg_arch_reset_list;
 
diff --git a/lib/dpkg/parse.c b/lib/dpkg/parse.c
index 412de49..2926788 100644
--- a/lib/dpkg/parse.c
+++ b/lib/dpkg/parse.c
@@ -201,7 +201,7 @@ pkg_parse_verify(struct parsedb_state *ps,
       parse_warn(ps, _("empty value for %s"), "architecture");
   }
   if (pkgbin->arch == NULL)
-    pkgbin->arch = dpkg_arch_find(NULL);
+    pkgbin->arch = dpkg_arch_get(arch_none);
 
   if (pkgbin->arch->type == arch_all && pkgbin->multiarch == multiarch_same)
     parse_error(ps, _("package has field '%s' but is architecture all"),
diff --git a/lib/dpkg/test/t-arch.c b/lib/dpkg/test/t-arch.c
index 127dbb6..c70f1d6 100644
--- a/lib/dpkg/test/t-arch.c
+++ b/lib/dpkg/test/t-arch.c
@@ -4,6 +4,7 @@
  *
  * Copyright © 2011 Linaro Limited
  * Copyright © 2011 Raphaël Hertzog <[email protected]>
+ * Copyright © 2011 Guillem Jover <[email protected]>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -57,16 +58,6 @@ test_dpkg_arch_name_is_illegal(void)
 }
 
 static void
-test_dpkg_arch_get_native(void)
-{
-       struct dpkg_arch *arch;
-
-       arch = dpkg_arch_get_native();
-       test_str(arch->name, ==, ARCHITECTURE);
-       test_pass(arch->type == arch_native);
-}
-
-static void
 test_dpkg_arch_get_list(void)
 {
        struct dpkg_arch *arch;
@@ -91,19 +82,26 @@ test_dpkg_arch_find(void)
        /* Test existence and initial values of default architectures. */
        arch = dpkg_arch_find("all");
        test_pass(arch->type == arch_all);
+       test_pass(dpkg_arch_get(arch_all) == arch);
        arch = dpkg_arch_find(ARCHITECTURE);
        test_pass(arch->type == arch_native);
+       test_pass(dpkg_arch_get(arch_native) == arch);
        arch = dpkg_arch_find("any");
        test_pass(arch->type == arch_wildcard);
+       test_pass(dpkg_arch_get(arch_wildcard) == arch);
 
        /* Empty architectures are marked none. */
        arch = dpkg_arch_find(NULL);
        test_pass(arch->type == arch_none);
+       test_pass(dpkg_arch_get(arch_none) == arch);
        test_str(arch->name, ==, "");
        arch = dpkg_arch_find("");
        test_pass(arch->type == arch_none);
        test_str(arch->name, ==, "");
 
+       /* Test for an unknown type. */
+       test_pass(dpkg_arch_get(1000) == NULL);
+
        /* New valid architectures are marked unknown. */
        arch = dpkg_arch_find("foobar");
        test_pass(arch->type == arch_unknown);
@@ -127,7 +125,6 @@ void
 test(void)
 {
        test_dpkg_arch_name_is_illegal();
-       test_dpkg_arch_get_native();
        test_dpkg_arch_get_list();
        test_dpkg_arch_find();
        test_dpkg_arch_reset_list();
diff --git a/src/enquiry.c b/src/enquiry.c
index 1d7326f..0eebf11 100644
--- a/src/enquiry.c
+++ b/src/enquiry.c
@@ -461,7 +461,7 @@ printarch(const char *const *argv)
   if (*argv)
     badusage(_("--%s takes no arguments"), cipaction->olong);
 
-  printf("%s\n", dpkg_arch_get_native()->name);
+  printf("%s\n", dpkg_arch_get(arch_native)->name);
 
   m_output(stdout, _("<standard output>"));
 
diff --git a/src/processarc.c b/src/processarc.c
index f8bfb1f..fc96368 100644
--- a/src/processarc.c
+++ b/src/processarc.c
@@ -475,7 +475,7 @@ void process_archive(const char *filename) {
       pkg->available.arch->type != arch_native)
     forcibleerr(fc_architecture,
                 _("package architecture (%s) does not match system (%s)"),
-                pkg->available.arch->name, dpkg_arch_get_native()->name);
+                pkg->available.arch->name, dpkg_arch_get(arch_native)->name);
 
   for (deconpil= deconfigure;
        deconpil;

-- 
dpkg's main repository


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

Reply via email to