X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fmempool.h;h=d16fa6e09162abe44b14dd771c42e2ad49ecb3a8;hb=cff818411879583e66b6985b4179be0e9d4c525c;hp=6058c5eefc9549de214660e3df2c7eea22805fb6;hpb=2771551e0dbfc9517ca6fd68f0db362434ceddbb;p=libucw.git diff --git a/lib/mempool.h b/lib/mempool.h index 6058c5ee..d16fa6e0 100644 --- a/lib/mempool.h +++ b/lib/mempool.h @@ -1,14 +1,14 @@ /* - * Sherlock Library -- Memory Pools + * UCW Library -- Memory Pools * - * (c) 1997--2004 Martin Mares + * (c) 1997--2005 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. */ -#ifndef _SHERLOCK_POOLS_H -#define _SHERLOCK_POOLS_H +#ifndef _UCW_POOLS_H +#define _UCW_POOLS_H #ifndef POOL_ALIGN #define POOL_ALIGN CPU_STRUCT_ALIGN @@ -24,12 +24,13 @@ struct mempool { struct mempool *mp_new(uns); void mp_delete(struct mempool *); void mp_flush(struct mempool *); -void *mp_alloc(struct mempool *, uns); -void *mp_alloc_zero(struct mempool *, uns); +void *mp_alloc(struct mempool *, uns) LIKE_MALLOC; +void *mp_alloc_zero(struct mempool *, uns) LIKE_MALLOC; -static inline void *mp_alloc_fast(struct mempool *p, uns l) +static inline void * LIKE_MALLOC +mp_alloc_fast(struct mempool *p, uns l) { - byte *f = (void *) (((uns) p->free + POOL_ALIGN - 1) & ~(POOL_ALIGN - 1)); + byte *f = (void *) (((uintptr_t) p->free + POOL_ALIGN - 1) & ~(uintptr_t)(POOL_ALIGN - 1)); byte *ee = f + l; if (ee > p->last) return mp_alloc(p, l); @@ -37,7 +38,7 @@ static inline void *mp_alloc_fast(struct mempool *p, uns l) return f; } -static inline void *mp_alloc_fast_noalign(struct mempool *p, uns l) +static inline void * LIKE_MALLOC mp_alloc_fast_noalign(struct mempool *p, uns l) { byte *f = p->free; byte *ee = f + l; @@ -60,14 +61,21 @@ mp_end_string(struct mempool *p, void *stop) p->free = stop; } -/* pool-str.c */ +/* mempool-str.c */ -char *mp_strdup(struct mempool *, char *); -char *mp_multicat(struct mempool *, ...); -static inline char * +char *mp_strdup(struct mempool *, char *) LIKE_MALLOC; +void *mp_memdup(struct mempool *, void *, uns) LIKE_MALLOC; +char *mp_multicat(struct mempool *, ...) LIKE_MALLOC SENTINEL_CHECK; +static inline char * LIKE_MALLOC mp_strcat(struct mempool *mp, char *x, char *y) { return mp_multicat(mp, x, y, NULL); } +char *mp_strjoin(struct mempool *p, char **a, uns n, uns sep) LIKE_MALLOC; + +/* mempool-fmt.c */ + +char *mp_printf(struct mempool *p, char *fmt, ...) FORMAT_CHECK(printf,2,3) LIKE_MALLOC; +char *mp_vprintf(struct mempool *p, char *fmt, va_list args) LIKE_MALLOC; #endif