From bfca2c42bc0e749f8611339568be502f22ac5e9c Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 19 Apr 2011 15:16:33 +0200 Subject: [PATCH] Resources: res_new() requires an active pool The old behavior of returning NULL if called without an active pool caused more fuss than it saved. --- ucw/doc/trans.txt | 1 - ucw/res-mem.c | 1 - ucw/res-subpool.c | 1 - ucw/respool.c | 3 +-- ucw/respool.h | 9 +++------ 5 files changed, 4 insertions(+), 11 deletions(-) diff --git a/ucw/doc/trans.txt b/ucw/doc/trans.txt index 1e45d5d8..fb3445f5 100644 --- a/ucw/doc/trans.txt +++ b/ucw/doc/trans.txt @@ -149,4 +149,3 @@ following exception types are defined: - Unit tests - Resourcification of more libucw objects. - More exceptions -- Do we want to allow res_alloc() when no pool is active? diff --git a/ucw/res-mem.c b/ucw/res-mem.c index 10cb1d4b..16aba180 100644 --- a/ucw/res-mem.c +++ b/ucw/res-mem.c @@ -44,7 +44,6 @@ res_malloc(size_t size, struct resource **ptr) { void *p = xmalloc(size); struct resource *r = res_new(&mem_res_class, p); - ASSERT(r); ((struct res_mem *) r) -> size = size; if (ptr) *ptr = r; diff --git a/ucw/res-subpool.c b/ucw/res-subpool.c index 5b427130..e224ae2c 100644 --- a/ucw/res-subpool.c +++ b/ucw/res-subpool.c @@ -46,7 +46,6 @@ res_subpool(struct respool *rp) { ASSERT(!rp->subpool_of); struct resource *r = res_new(&subpool_res_class, rp); - ASSERT(r); ASSERT(r->rpool != rp); // Avoid simple loops rp->subpool_of = r; return r; diff --git a/ucw/respool.c b/ucw/respool.c index 09b8953f..64f9a2fc 100644 --- a/ucw/respool.c +++ b/ucw/respool.c @@ -99,8 +99,7 @@ struct resource * res_alloc(const struct res_class *rc) { struct respool *rp = rp_current(); - if (!rp) - return NULL; + ASSERT(rp); uns size = (rc->res_size ? : sizeof(struct resource)); struct resource *r = (rp->mpool ? mp_alloc_fast(rp->mpool, size) : xmalloc(size)); diff --git a/ucw/respool.h b/ucw/respool.h index 56955707..d05e9d07 100644 --- a/ucw/respool.h +++ b/ucw/respool.h @@ -139,16 +139,13 @@ void res_drop(struct resource *r); /** * Creates a new resource of the specific class, setting its private data to @priv. - * Returns NULL if there is no resource pool active. + * Dies if no resource pool is active. **/ static inline struct resource *res_new(const struct res_class *rc, void *priv) { struct resource *r = res_alloc(rc); - if (r) - { - r->rclass = rc; - r->priv = priv; - } + r->rclass = rc; + r->priv = priv; return r; } -- 2.39.5