mirror of
git://projects.qi-hardware.com/wernermisc.git
synced 2024-11-15 05:53:09 +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:
parent
8d453d77c2
commit
bbf9c42bc8
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
SHELL = /bin/bash
|
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_rbtest = rbtest.o jrb.o
|
||||||
OBJS = $(OBJS_qpkg) $(OBJS_rbtest)
|
OBJS = $(OBJS_qpkg) $(OBJS_rbtest)
|
||||||
|
|
||||||
|
@ -12,8 +12,10 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "jrb.h"
|
#include "jrb.h"
|
||||||
|
|
||||||
|
#include "pkg.h"
|
||||||
#include "qpkg.h"
|
#include "qpkg.h"
|
||||||
#include "fixup.h"
|
#include "fixup.h"
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "id.h"
|
#include "id.h"
|
||||||
|
#include "pkg.h"
|
||||||
#include "qpkg.h"
|
#include "qpkg.h"
|
||||||
#include "gobble.h"
|
#include "gobble.h"
|
||||||
|
|
||||||
@ -123,8 +124,7 @@ static void finish_pkg(struct pkg *new, struct jrb *jrb)
|
|||||||
compact:
|
compact:
|
||||||
jrb->val = new->more;
|
jrb->val = new->more;
|
||||||
old->flags |= new->flags;
|
old->flags |= new->flags;
|
||||||
/* @@@ we may leak a little */
|
free_pkg(new);
|
||||||
free(new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -302,17 +302,8 @@ package:
|
|||||||
finish_pkg(pkg, jrb);
|
finish_pkg(pkg, jrb);
|
||||||
|
|
||||||
WHITESPACE;
|
WHITESPACE;
|
||||||
pkg = alloc_type(struct pkg);
|
|
||||||
jrb = ID(packages);
|
jrb = ID(packages);
|
||||||
pkg->id = jrb->key;
|
pkg = new_pkg(jrb);
|
||||||
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;
|
|
||||||
goto eol;
|
goto eol;
|
||||||
|
|
||||||
version:
|
version:
|
||||||
|
59
qpkg/pkg.c
Normal file
59
qpkg/pkg.c
Normal 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
60
qpkg/pkg.h
Normal 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 */
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "id.h"
|
#include "id.h"
|
||||||
|
#include "pkg.h"
|
||||||
#include "qpkg.h"
|
#include "qpkg.h"
|
||||||
#include "prereq.h"
|
#include "prereq.h"
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "prereq.h"
|
#include "prereq.h"
|
||||||
#include "gobble.h"
|
#include "gobble.h"
|
||||||
#include "fixup.h"
|
#include "fixup.h"
|
||||||
|
#include "pkg.h"
|
||||||
#include "qpkg.h"
|
#include "qpkg.h"
|
||||||
|
|
||||||
|
|
||||||
|
36
qpkg/qpkg.h
36
qpkg/qpkg.h
@ -16,42 +16,6 @@
|
|||||||
#include "id.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 tree *packages;
|
struct tree *packages;
|
||||||
struct tree *versions;
|
struct tree *versions;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user