The old behavior of returning NULL if called without an active pool
caused more fuss than it saved.
- Unit tests
- Resourcification of more libucw objects.
- More exceptions
-- Do we want to allow res_alloc() when no pool is active?
{
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;
{
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;
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));
/**
* 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;
}