Procházet zdrojové kódy

libdpkg: Refactor PKGPFIELD and FILEFFIELD into new STRUCTFIELD

Guillem Jover před 13 roky
rodič
revize
9f8a2e2b6a
3 změnil soubory, kde provedl 12 přidání a 12 odebrání
  1. 6 5
      lib/dpkg/dump.c
  2. 4 4
      lib/dpkg/fields.c
  3. 2 3
      lib/dpkg/parsedump.h

+ 6 - 5
lib/dpkg/dump.c

@@ -121,7 +121,7 @@ w_charfield(struct varbuf *vb,
             const struct pkginfo *pkg, const struct pkgbin *pkgbin,
             enum fwriteflags flags, const struct fieldinfo *fip)
 {
-  const char *value = PKGPFIELD(pkgbin, fip->integer, const char *);
+  const char *value = STRUCTFIELD(pkgbin, fip->integer, const char *);
 
   if (str_is_unset(value))
     return;
@@ -144,7 +144,8 @@ w_filecharf(struct varbuf *vb,
   if (pkgbin != &pkg->available)
     return;
   fdp = pkg->files;
-  if (!fdp || !FILEFFIELD(fdp,fip->integer,const char*)) return;
+  if (!fdp || !STRUCTFIELD(fdp, fip->integer, const char *))
+    return;
 
   if (flags&fw_printheader) {
     varbuf_add_str(vb, fip->name);
@@ -153,7 +154,7 @@ w_filecharf(struct varbuf *vb,
 
   while (fdp) {
     varbuf_add_char(vb, ' ');
-    varbuf_add_str(vb, FILEFFIELD(fdp, fip->integer, const char *));
+    varbuf_add_str(vb, STRUCTFIELD(fdp, fip->integer, const char *));
     fdp= fdp->next;
   }
 
@@ -166,7 +167,7 @@ w_booleandefno(struct varbuf *vb,
                const struct pkginfo *pkg, const struct pkgbin *pkgbin,
                enum fwriteflags flags, const struct fieldinfo *fip)
 {
-  bool value = PKGPFIELD(pkgbin, fip->integer, bool);
+  bool value = STRUCTFIELD(pkgbin, fip->integer, bool);
 
   if ((flags & fw_printheader) && !value)
     return;
@@ -187,7 +188,7 @@ w_multiarch(struct varbuf *vb,
             const struct pkginfo *pkg, const struct pkgbin *pkgbin,
             enum fwriteflags flags, const struct fieldinfo *fip)
 {
-  int value = PKGPFIELD(pkgbin, fip->integer, int);
+  int value = STRUCTFIELD(pkgbin, fip->integer, int);
 
   if ((flags & fw_printheader) && !value)
     return;

+ 4 - 4
lib/dpkg/fields.c

@@ -129,7 +129,7 @@ f_filecharf(struct pkginfo *pkg, struct pkgbin *pkgbin,
       fdp->name= fdp->msdosname= fdp->size= fdp->md5sum= NULL;
       *fdpp= fdp;
     }
-    FILEFFIELD(fdp,fip->integer,const char*)= cpos;
+    STRUCTFIELD(fdp, fip->integer, const char *) = cpos;
     fdpp= &fdp->next;
     while (*space && isspace(*space)) space++;
     cpos= space;
@@ -146,7 +146,7 @@ f_charfield(struct pkginfo *pkg, struct pkgbin *pkgbin,
             const char *value, const struct fieldinfo *fip)
 {
   if (*value)
-    PKGPFIELD(pkgbin, fip->integer, char *) = nfstrsave(value);
+    STRUCTFIELD(pkgbin, fip->integer, char *) = nfstrsave(value);
 }
 
 void
@@ -161,7 +161,7 @@ f_boolean(struct pkginfo *pkg, struct pkgbin *pkgbin,
 
   boolean = parse_nv_last(ps, _("yes/no in boolean field"),
                           booleaninfos, value);
-  PKGPFIELD(pkgbin, fip->integer, bool) = boolean;
+  STRUCTFIELD(pkgbin, fip->integer, bool) = boolean;
 }
 
 void
@@ -176,7 +176,7 @@ f_multiarch(struct pkginfo *pkg, struct pkgbin *pkgbin,
 
   multiarch = parse_nv_last(ps, _("foreign/allowed/same/no in quadstate field"),
                             multiarchinfos, value);
-  PKGPFIELD(pkgbin, fip->integer, int) = multiarch;
+  STRUCTFIELD(pkgbin, fip->integer, int) = multiarch;
 }
 
 void

+ 2 - 3
lib/dpkg/parsedump.h

@@ -76,11 +76,10 @@ typedef void parse_field_func(struct parsedb_state *ps, struct field_state *fs,
 bool parse_stanza(struct parsedb_state *ps, struct field_state *fs,
                   parse_field_func *parse_field, void *parse_obj);
 
-#define PKGIFPOFF(f) (offsetof(struct pkgbin, f))
-#define PKGPFIELD(pkgbin, of, type) (*(type *)((char *)(pkgbin) + (of)))
+#define STRUCTFIELD(klass, off, type) (*(type *)((char *)(klass) + (off)))
 
+#define PKGIFPOFF(f) (offsetof(struct pkgbin, f))
 #define FILEFOFF(f) (offsetof(struct filedetails, f))
-#define FILEFFIELD(filedetail,of,type) (*(type*)((char*)(filedetail)+(of)))
 
 typedef void freadfunction(struct pkginfo *pkg, struct pkgbin *pkgbin,
                            struct parsedb_state *ps,