]> mj.ucw.cz Git - libucw.git/commitdiff
Resources: res_new() requires an active pool
authorMartin Mares <mj@ucw.cz>
Tue, 19 Apr 2011 13:16:33 +0000 (15:16 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 19 Apr 2011 13:16:33 +0000 (15:16 +0200)
The old behavior of returning NULL if called without an active pool
caused more fuss than it saved.

ucw/doc/trans.txt
ucw/res-mem.c
ucw/res-subpool.c
ucw/respool.c
ucw/respool.h

index 1e45d5d8684af52535dfaab9d367dd585d269d6a..fb3445f5bbec758186613c757e200aedc276ee2d 100644 (file)
@@ -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?
index 10cb1d4b33f5ad02e79399c21e953a1eeecfb5f2..16aba180fa78f21520b7ecaa1e9039259ad81a38 100644 (file)
@@ -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;
index 5b4271308b31e288e75a55c2a4b14b302ce38e2d..e224ae2c8cf42dfb5a8d9fd96bbde09585abbe5d 100644 (file)
@@ -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;
index 09b8953fa276da861f3050c2d752606591f4789c..64f9a2fc643f14abcbf7d85edbabdb8643aba8a2 100644 (file)
@@ -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));
index 56955707a2f9fb07d3180a4d0f3f3a5a7818fc0a..d05e9d0796adf33095efdc6be11fc9941f74e51c 100644 (file)
@@ -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;
 }