Parcourir la source

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.
Guillem Jover il y a 14 ans
Parent
commit
6f4ebe26f5
9 fichiers modifiés avec 51 ajouts et 31 suppressions
  1. 23 3
      lib/dpkg/arch.c
  2. 13 10
      lib/dpkg/arch.h
  3. 2 2
      lib/dpkg/depcon.c
  4. 1 1
      lib/dpkg/fields.c
  5. 1 1
      lib/dpkg/libdpkg.Versions
  6. 1 1
      lib/dpkg/parse.c
  7. 8 11
      lib/dpkg/test/t-arch.c
  8. 1 1
      src/enquiry.c
  9. 1 1
      src/processarc.c

+ 23 - 3
lib/dpkg/arch.c

@@ -4,6 +4,7 @@
  *
  * Copyright © 2011 Linaro Limited
  * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
+ * Copyright © 2011 Guillem Jover <guillem@debian.org>
  *
  * 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;
+	}
 }
 
 /**

+ 13 - 10
lib/dpkg/arch.h

@@ -4,6 +4,7 @@
  *
  * Copyright © 2011 Linaro Limited
  * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
+ * Copyright © 2011 Guillem Jover <guillem@debian.org>
  *
  * 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);
 

+ 2 - 2
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);
 }

+ 1 - 1
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

+ 1 - 1
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;
 

+ 1 - 1
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"),

+ 8 - 11
lib/dpkg/test/t-arch.c

@@ -4,6 +4,7 @@
  *
  * Copyright © 2011 Linaro Limited
  * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
+ * Copyright © 2011 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -56,16 +57,6 @@ test_dpkg_arch_name_is_illegal(void)
 	test_pass(dpkg_arch_name_is_illegal("sparc") == NULL);
 }
 
-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)
 {
@@ -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();

+ 1 - 1
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>"));
 

+ 1 - 1
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;