Explorar el Código

libdpkg: Add new arch_empty special architecture

This will allow to easily distinguish an empty architecture value, while
always having an initialized architecture variable.
Guillem Jover hace 14 años
padre
commit
7c7ce89909
Se han modificado 6 ficheros con 20 adiciones y 10 borrados
  1. 10 1
      lib/dpkg/arch.c
  2. 1 0
      lib/dpkg/arch.h
  3. 0 3
      lib/dpkg/fields.c
  4. 3 3
      lib/dpkg/parse.c
  5. 1 1
      lib/dpkg/pkg.c
  6. 5 2
      lib/dpkg/test/t-arch.c

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

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

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

+ 3 - 3
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)

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

+ 5 - 2
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. */