Beispiel #1
0
/*
 * Simple stub for umem_cache_alloc(). The nofail callback isn't expected to return.
 */
void *umem_cache_alloc(umem_cache_t *cache, int flags)
{
	void *buf = malloc(cache->bufsize);
	if(buf == NULL) {
		if(!(flags & UMEM_NOFAIL))
			return NULL;

		if(nofail_cb != NULL)
			nofail_cb();
		abort();
	}

	if(cache->constructor != NULL) {
		if(cache->constructor(buf, cache->callback_data, flags) != 0) {
			free(buf);
			if(!(flags & UMEM_NOFAIL))
				return NULL;

			if(nofail_cb != NULL)
				nofail_cb();
			abort();
		}
	}

	return buf;
}
Beispiel #2
0
/*
 * Simple stub for umem_cache_alloc(). The nofail callback isn't expected to return.
 */
void *umem_cache_alloc(umem_cache_t *cache, int flags)
{
    void *buf = malloc(cache->bufsize);
    if(buf == NULL) {
        if(!(flags & UMEM_NOFAIL))
            return NULL;

        if(nofail_cb != NULL)
            nofail_cb();
        abort();
    }

    if(cache->constructor != NULL) {
        /* XXX NetBSD pool cache costructor has switched arguments. */
        if(cache->constructor(cache->callback_data, buf, flags) != 0) {
            free(buf);
            if(!(flags & UMEM_NOFAIL))
                return NULL;

            if(nofail_cb != NULL)
                nofail_cb();
            abort();
        }
    }

    return buf;
}
Beispiel #3
0
/*
 * Simple stub for umem_zalloc().
 */
void *umem_zalloc(size_t size, int flags)
{
	assert(flags == UMEM_DEFAULT || flags == UMEM_NOFAIL);

	if(size == 0)
		return NULL;

	void *ret = calloc(1, size);
	if(ret == NULL) {
		if(!(flags & UMEM_NOFAIL))
			return NULL;

		if(nofail_cb != NULL)
			nofail_cb();
		abort();
	}

	return ret;
}