1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-12-18 12:23:10 +02:00

qpkg: move "struct pkg" and its allocation from gobble.c and qpkg.h to pkg.[hc]

- Makefile (OBJS_qpkg): added pkg.o
- gobble.c (gobble_buf): moved "struct pkg" allocation to function new_pkg
  in pkg.c
- qpkg.h: moved "struct pkg" and subordinate structures to pkg.h
- pkg.h, pkg.c (new_pkg, free_pkg): provide package structure definition,
  allocation, and deallocation
- fixup.c, gobble.c, prereq.c, qpkg.c: include "pkg.h"
- gobble.c (finish_pkg): use free_pkg instead of just "free" to avoid
  leaking memory
This commit is contained in:
Werner Almesberger 2010-11-22 16:19:32 -03:00
parent 8d453d77c2
commit bbf9c42bc8
8 changed files with 127 additions and 49 deletions

View File

@ -12,7 +12,7 @@
SHELL = /bin/bash
OBJS_qpkg = fixup.o gobble.o id.o prereq.o qpkg.o jrb.o
OBJS_qpkg = fixup.o gobble.o id.o pkg.o prereq.o qpkg.o jrb.o
OBJS_rbtest = rbtest.o jrb.o
OBJS = $(OBJS_qpkg) $(OBJS_rbtest)

View File

@ -12,8 +12,10 @@
#include <stdio.h>
#include "jrb.h"
#include "pkg.h"
#include "qpkg.h"
#include "fixup.h"

View File

@ -21,6 +21,7 @@
#include "util.h"
#include "id.h"
#include "pkg.h"
#include "qpkg.h"
#include "gobble.h"
@ -123,8 +124,7 @@ static void finish_pkg(struct pkg *new, struct jrb *jrb)
compact:
jrb->val = new->more;
old->flags |= new->flags;
/* @@@ we may leak a little */
free(new);
free_pkg(new);
}
@ -302,17 +302,8 @@ package:
finish_pkg(pkg, jrb);
WHITESPACE;
pkg = alloc_type(struct pkg);
jrb = ID(packages);
pkg->id = jrb->key;
pkg->more = jrb->val;
jrb->val = pkg;
pkg->version = NULL;
pkg->arch = NULL;
pkg->conflicts = pkg->depends = NULL;
pkg->filename = NULL;
pkg->flags = 0;
pkg->mark = 0;
pkg = new_pkg(jrb);
goto eol;
version:

59
qpkg/pkg.c Normal file
View File

@ -0,0 +1,59 @@
/*
* pkg.c - Package structure and operations
*
* Written 2010 by Werner Almesberger
* Copyright 2010 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <stdlib.h>
#include "util.h"
#include "jrb.h"
#include "pkg.h"
struct pkg *new_pkg(struct jrb *jrb)
{
struct pkg *pkg;
pkg = alloc_type(struct pkg);
pkg->id = jrb->key;
pkg->more = jrb->val;
jrb->val = pkg;
pkg->version = NULL;
pkg->arch = NULL;
pkg->conflicts = pkg->depends = NULL;
pkg->filename = NULL;
pkg->flags = 0;
pkg->mark = 0;
return pkg;
}
static void free_refs(struct ref *refs)
{
struct ref *next;
while (refs) {
next = refs->next;
free(refs);
refs = next;
}
}
void free_pkg(struct pkg *pkg)
{
free_refs(pkg->conflicts);
free_refs(pkg->depends);
free(pkg);
}

60
qpkg/pkg.h Normal file
View File

@ -0,0 +1,60 @@
/*
* pkg.h - Package structure and operations
*
* Written 2010 by Werner Almesberger
* Copyright 2010 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#ifndef PKG_H
#define PKG_H
#include "jrb.h"
#include "id.h"
enum flags {
/* parse-time flags */
QPKG_INSTALLED = 1 << 0, /* installed on target */
/* run-time flags */
QPKG_ADDING = 1 << 10, /* resolving dependencies */
};
enum relop {
rel_eq,
rel_ge,
rel_lt,
};
struct pkg;
struct ref {
struct id *pkg;
struct id *version;
enum relop relop; /* undefined if version == NULL */
struct ref *next;
};
struct pkg {
struct id *id;
struct id *version;
const char *arch;
struct ref *conflicts;
struct ref *depends;
const char *filename;
int flags; /* see enum flags */
struct pkg *more;
int mark;
};
struct pkg *new_pkg(struct jrb *jrb);
void free_pkg(struct pkg *pkg);
#endif /* !PKG_H */

View File

@ -18,6 +18,7 @@
#include "util.h"
#include "id.h"
#include "pkg.h"
#include "qpkg.h"
#include "prereq.h"

View File

@ -21,6 +21,7 @@
#include "prereq.h"
#include "gobble.h"
#include "fixup.h"
#include "pkg.h"
#include "qpkg.h"

View File

@ -16,42 +16,6 @@
#include "id.h"
enum flags {
/* parse-time flags */
QPKG_INSTALLED = 1 << 0, /* installed on target */
/* run-time flags */
QPKG_ADDING = 1 << 10, /* resolving dependencies */
};
enum relop {
rel_eq,
rel_ge,
rel_lt,
};
struct pkg;
struct ref {
struct id *pkg;
struct id *version;
enum relop relop; /* undefined if version == NULL */
struct ref *next;
};
struct pkg {
struct id *id;
struct id *version;
const char *arch;
struct ref *conflicts;
struct ref *depends;
const char *filename;
int flags; /* see enum flags */
struct pkg *more;
int mark;
};
struct tree *packages;
struct tree *versions;