Преглед на файлове

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 преди 14 години
родител
ревизия
7c7ce89909
променени са 6 файла, в които са добавени 20 реда и са изтрити 10 реда
  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,
 	.type = arch_none,
 	.next = NULL,
 	.next = NULL,
 };
 };
+static struct dpkg_arch arch_item_empty = {
+	.name = "",
+	.type = arch_empty,
+	.next = NULL,
+};
 
 
 static struct dpkg_arch arch_item_any = {
 static struct dpkg_arch arch_item_any = {
 	.name = "any",
 	.name = "any",
@@ -122,8 +127,10 @@ dpkg_arch_find(const char *name)
 	struct dpkg_arch *arch, *last_arch = NULL;
 	struct dpkg_arch *arch, *last_arch = NULL;
 	enum dpkg_arch_type type;
 	enum dpkg_arch_type type;
 
 
-	if (name == NULL || name[0] == '\0')
+	if (name == NULL)
 		return &arch_item_none;
 		return &arch_item_none;
+	if (name[0] == '\0')
+		return &arch_item_empty;
 
 
 	for (arch = arch_list; arch; arch = arch->next) {
 	for (arch = arch_list; arch; arch = arch->next) {
 		if (strcmp(arch->name, name) == 0)
 		if (strcmp(arch->name, name) == 0)
@@ -154,6 +161,8 @@ dpkg_arch_get(enum dpkg_arch_type type)
 	switch (type) {
 	switch (type) {
 	case arch_none:
 	case arch_none:
 		return &arch_item_none;
 		return &arch_item_none;
+	case arch_empty:
+		return &arch_item_empty;
 	case arch_wildcard:
 	case arch_wildcard:
 		return &arch_item_any;
 		return &arch_item_any;
 	case arch_all:
 	case arch_all:

+ 1 - 0
lib/dpkg/arch.h

@@ -30,6 +30,7 @@ DPKG_BEGIN_DECLS
 
 
 enum dpkg_arch_type {
 enum dpkg_arch_type {
 	arch_none,
 	arch_none,
+	arch_empty,
 	arch_illegal,
 	arch_illegal,
 	arch_wildcard,
 	arch_wildcard,
 	arch_all,
 	arch_all,

+ 0 - 3
lib/dpkg/fields.c

@@ -181,9 +181,6 @@ f_architecture(struct pkginfo *pigp, struct pkgbin *pifp,
                struct parsedb_state *ps,
                struct parsedb_state *ps,
                const char *value, const struct fieldinfo *fip)
                const char *value, const struct fieldinfo *fip)
 {
 {
-  if (!*value)
-    return;
-
   pifp->arch = dpkg_arch_find(value);
   pifp->arch = dpkg_arch_find(value);
   if (pifp->arch->type == arch_illegal)
   if (pifp->arch->type == arch_illegal)
     parse_warn(ps, _("'%s' is not a valid architecture name: %s"),
     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
     /* 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
      * is in such a state that it make sense), so that it can be used safely
      * on string comparisons and the like. */
      * on string comparisons and the like. */
-    if (pkgbin->arch == NULL)
+    if (pkgbin->arch->type == arch_none)
       parse_warn(ps, _("missing %s"), "architecture");
       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");
       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);
     pkgbin->arch = dpkg_arch_get(arch_none);
 
 
   if (pkgbin->arch->type == arch_all && pkgbin->multiarch == multiarch_same)
   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->installedsize = NULL;
 	pkgbin->bugs = NULL;
 	pkgbin->bugs = NULL;
 	pkgbin->origin = NULL;
 	pkgbin->origin = NULL;
-	pkgbin->arch = NULL;
+	pkgbin->arch = dpkg_arch_get(arch_none);
 	blankversion(&pkgbin->version);
 	blankversion(&pkgbin->version);
 	pkgbin->conffiles = NULL;
 	pkgbin->conffiles = NULL;
 	pkgbin->arbs = 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(arch->type == arch_wildcard);
 	test_pass(dpkg_arch_get(arch_wildcard) == arch);
 	test_pass(dpkg_arch_get(arch_wildcard) == arch);
 
 
-	/* Empty architectures are marked none. */
+	/* Test missing architecture. */
 	arch = dpkg_arch_find(NULL);
 	arch = dpkg_arch_find(NULL);
 	test_pass(arch->type == arch_none);
 	test_pass(arch->type == arch_none);
 	test_pass(dpkg_arch_get(arch_none) == arch);
 	test_pass(dpkg_arch_get(arch_none) == arch);
 	test_str(arch->name, ==, "");
 	test_str(arch->name, ==, "");
+
+	/* Test empty architectures. */
 	arch = dpkg_arch_find("");
 	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_str(arch->name, ==, "");
 
 
 	/* Test for an unknown type. */
 	/* Test for an unknown type. */