Changeset: 4aaf3b723ba5 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/4aaf3b723ba5 Modified Files: clients/Tests/exports.stable.out gdk/ChangeLog gdk/gdk.h gdk/gdk_atoms.c gdk/gdk_atoms.h gdk/gdk_heap.c gdk/gdk_private.h gdk/gdk_select.c gdk/gdk_string.c geom/monetdb5/geom.c monetdb5/mal/mal_atom.c monetdb5/mal/mel.h monetdb5/modules/atoms/blob.c Branch: default Log Message:
Interface changes for atomPut and atomHeap functions. diffs (truncated from 365 to 300 lines): diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out --- a/clients/Tests/exports.stable.out +++ b/clients/Tests/exports.stable.out @@ -344,7 +344,7 @@ void HASHdestroy(BAT *b); BUN HASHlist(Hash *h, BUN i); BUN HASHprobe(const Hash *h, const void *v); void HEAP_free(Heap *heap, var_t block); -void HEAP_initialize(Heap *heap, size_t nbytes, size_t nprivate, int alignment); +gdk_return HEAP_initialize(Heap *heap, size_t nbytes, size_t nprivate, int alignment); var_t HEAP_malloc(BAT *b, size_t nbytes); void HEAPdecref(Heap *h, bool remove); gdk_return HEAPextend(Heap *h, size_t size, bool mayshare) __attribute__((__warn_unused_result__)); diff --git a/gdk/ChangeLog b/gdk/ChangeLog --- a/gdk/ChangeLog +++ b/gdk/ChangeLog @@ -1,3 +1,8 @@ # ChangeLog file for GDK # This file is updated with Maddlog +* Mon Aug 2 2021 Sjoerd Mullender <sjo...@acm.org> +- Some small interface changes to the atom functions: the atomPut function + now returns (var_t) -1 on error instead of 0; the atomHeap function + now returns success or failure as a gdk_return value. + diff --git a/gdk/gdk.h b/gdk/gdk.h --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -1033,7 +1033,7 @@ bat_iterator_nolock(BAT *b) * private space. */ -gdk_export void HEAP_initialize( +gdk_export gdk_return HEAP_initialize( Heap *heap, /* nbytes -- Initial size of the heap. */ size_t nbytes, /* alignment -- for objects on the heap. */ size_t nprivate, /* nprivate -- Size of private space */ diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c --- a/gdk/gdk_atoms.c +++ b/gdk/gdk_atoms.c @@ -301,12 +301,10 @@ ATOMlen(int t, const void *src) gdk_return ATOMheap(int t, Heap *hp, size_t cap) { - void (*h) (Heap *, size_t) = BATatoms[t].atomHeap; + gdk_return (*h) (Heap *, size_t) = BATatoms[t].atomHeap; if (h) { - (*h) (hp, cap); - if (hp->base == NULL) - return GDK_FAIL; + return (*h) (hp, cap); } return GDK_SUCCEED; } diff --git a/gdk/gdk_atoms.h b/gdk/gdk_atoms.h --- a/gdk/gdk_atoms.h +++ b/gdk/gdk_atoms.h @@ -57,7 +57,7 @@ typedef struct { var_t (*atomPut) (BAT *, var_t *off, const void *src); void (*atomDel) (Heap *, var_t *atom); size_t (*atomLen) (const void *atom); - void (*atomHeap) (Heap *, size_t); + gdk_return (*atomHeap) (Heap *, size_t); } atomDesc; #define MAXATOMS 128 @@ -302,7 +302,7 @@ static inline gdk_return __attribute__(( ATOMputVAR(BAT *b, var_t *dst, const void *src) { assert(BATatoms[b->ttype].atomPut != NULL); - if ((*BATatoms[b->ttype].atomPut)(b, dst, src) == 0) + if ((*BATatoms[b->ttype].atomPut)(b, dst, src) == (var_t) -1) return GDK_FAIL; return GDK_SUCCEED; } @@ -353,7 +353,7 @@ ATOMreplaceVAR(BAT *b, var_t *dst, const int type = b->ttype; assert(BATatoms[type].atomPut != NULL); - if ((*BATatoms[type].atomPut)(b, &loc, src) == 0) + if ((*BATatoms[type].atomPut)(b, &loc, src) == (var_t) -1) return GDK_FAIL; if (ATOMunfix(type, dst) != GDK_SUCCEED) return GDK_FAIL; diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c --- a/gdk/gdk_heap.c +++ b/gdk/gdk_heap.c @@ -1037,7 +1037,7 @@ HEAP_empty(Heap *heap, size_t nprivate, headp->next = 0; } -void +gdk_return HEAP_initialize(Heap *heap, size_t nbytes, size_t nprivate, int alignment) { /* For now we know about two alignments. */ @@ -1053,12 +1053,13 @@ HEAP_initialize(Heap *heap, size_t nbyte total = roundup_8(total); if (HEAPalloc(heap, total, 1, 1) != GDK_SUCCEED) - return; + return GDK_FAIL; heap->free = heap->size; } /* initialize heap as empty */ HEAP_empty(heap, nprivate, alignment); + return GDK_SUCCEED; } @@ -1089,7 +1090,7 @@ HEAP_malloc(BAT *b, size_t nbytes) assert(trail == 0 || block > trail); if (trail != 0 && block <= trail) { GDKerror("Free list is not orderered\n"); - return 0; + return (var_t) -1; } if (blockp->size >= nbytes) @@ -1112,7 +1113,7 @@ HEAP_malloc(BAT *b, size_t nbytes) /* Increase the size of the heap. */ TRC_DEBUG(HEAP, "HEAPextend in HEAP_malloc %s %zu %zu\n", heap->filename, heap->size, newsize); if (HEAPgrow(&b->theaplock, &b->tvheap, newsize, false) != GDK_SUCCEED) { - return 0; + return (var_t) -1; } heap = b->tvheap; heap->free = newsize; diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h --- a/gdk/gdk_private.h +++ b/gdk/gdk_private.h @@ -255,7 +255,7 @@ void settailname(Heap *restrict tail, co __attribute__((__visibility__("hidden"))); void strCleanHash(Heap *hp, bool rebuild) __attribute__((__visibility__("hidden"))); -void strHeap(Heap *d, size_t cap) +gdk_return strHeap(Heap *d, size_t cap) __attribute__((__visibility__("hidden"))); var_t strLocate(Heap *h, const char *v) __attribute__((__visibility__("hidden"))); diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c --- a/gdk/gdk_select.c +++ b/gdk/gdk_select.c @@ -772,10 +772,14 @@ fullscan_str(BAT *b, BATiter *bi, struct return fullscan_any(b, bi, ci, bn, tl, th, li, hi, equi, anti, lval, hval, lnil, cnt, hseq, dst, maximum, imprints, algo); - if ((pos = strLocate(b->tvheap, tl)) == 0) { + if ((pos = strLocate(b->tvheap, tl)) == (var_t) -2) { *algo = "select: fullscan equi strelim (nomatch)"; return 0; } + if (pos == (var_t) -1) { + BBPreclaim(bn); + return BUN_NONE; + } *algo = "select: fullscan equi strelim"; assert(pos >= GDK_VAROFFSET); switch (bi->width) { diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c --- a/gdk/gdk_string.c +++ b/gdk/gdk_string.c @@ -64,15 +64,14 @@ const char str_nil[2] = { '\200', 0 }; -void +gdk_return strHeap(Heap *d, size_t cap) { size_t size; cap = MAX(cap, BATTINY); size = GDK_STRHASHTABLE * sizeof(stridx_t) + MIN(GDK_ELIMLIMIT, cap * GDK_VARALIGN); - if (HEAPalloc(d, size, 1, 1) != GDK_SUCCEED) - GDKerror("alloc failed"); + return HEAPalloc(d, size, 1, 1); } @@ -141,7 +140,7 @@ strCleanHash(Heap *h, bool rebuild) /* * The strPut routine. The routine strLocate can be used to identify * the location of a string in the heap if it exists. Otherwise it - * returns zero. + * returns (var_t) -2 (-1 is reserved for error). */ var_t strLocate(Heap *h, const char *v) @@ -152,7 +151,7 @@ strLocate(Heap *h, const char *v) BUN off; if (h->free == 0) { /* empty, so there are no strings */ - return 0; + return (var_t) -2; } off = strHash(v); @@ -167,19 +166,9 @@ strLocate(Heap *h, const char *v) if (strcmp(v, (str) (next + 1)) == 0) return (var_t) ((sizeof(stridx_t) + *ref)); /* found */ } - return 0; + return (var_t) -2; } -#ifdef __GNUC__ -/* __builtin_expect returns its first argument; it is expected to be - * equal to the second argument */ -#define unlikely(expr) __builtin_expect((expr) != 0, 0) -#define likely(expr) __builtin_expect((expr) != 0, 1) -#else -#define unlikely(expr) (expr) -#define likely(expr) (expr) -#endif - var_t strPut(BAT *b, var_t *dst, const void *V) { @@ -193,7 +182,7 @@ strPut(BAT *b, var_t *dst, const void *V if (h->free == 0) { if (h->size < GDK_STRHASHTABLE * sizeof(stridx_t) + BATTINY * GDK_VARALIGN) { if (HEAPgrow(&b->theaplock, &b->tvheap, GDK_STRHASHTABLE * sizeof(stridx_t) + BATTINY * GDK_VARALIGN, true) != GDK_SUCCEED) { - return 0; + return (var_t) -1; } h = b->tvheap; } @@ -245,7 +234,7 @@ strPut(BAT *b, var_t *dst, const void *V #ifndef NDEBUG if (!checkUTF8(v)) { GDKerror("incorrectly encoded UTF-8\n"); - return 0; + return (var_t) -1; } #endif @@ -279,11 +268,11 @@ strPut(BAT *b, var_t *dst, const void *V if (h->free + pad + len >= (size_t) VAR_MAX) { GDKerror("string heaps gets larger than %zuGiB.\n", (size_t) VAR_MAX >> 30); - return 0; + return (var_t) -1; } TRC_DEBUG(HEAP, "HEAPextend in strPut %s %zu %zu\n", h->filename, h->size, newsize); if (HEAPgrow(&b->theaplock, &b->tvheap, newsize, true) != GDK_SUCCEED) { - return 0; + return (var_t) -1; } h = b->tvheap; @@ -317,6 +306,16 @@ strPut(BAT *b, var_t *dst, const void *V * the input is correct UTF-8. */ +#ifdef __GNUC__ +/* __builtin_expect returns its first argument; it is expected to be + * equal to the second argument */ +#define unlikely(expr) __builtin_expect((expr) != 0, 0) +#define likely(expr) __builtin_expect((expr) != 0, 1) +#else +#define unlikely(expr) (expr) +#define likely(expr) (expr) +#endif + ssize_t GDKstrFromStr(unsigned char *restrict dst, const unsigned char *restrict src, ssize_t len) { diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c --- a/geom/monetdb5/geom.c +++ b/geom/monetdb5/geom.c @@ -5247,7 +5247,7 @@ wkbPUT(BAT *b, var_t *bun, const void *V *bun = HEAP_malloc(b, wkb_size(val->len)); base = b->tvheap->base; - if (*bun) { + if (*bun != (var_t) -1) { memcpy(&base[*bun], val, wkb_size(val->len)); b->tvheap->dirty = true; } @@ -5269,10 +5269,10 @@ wkbLENGTH(const void *P) return (size_t) len; } -static void +static gdk_return wkbHEAP(Heap *heap, size_t capacity) { - HEAP_initialize(heap, capacity, 0, (int) sizeof(var_t)); + return HEAP_initialize(heap, capacity, 0, (int) sizeof(var_t)); } /***********************************************/ @@ -5702,7 +5702,7 @@ wkbaPUT(BAT *b, var_t *bun, const void * *bun = HEAP_malloc(b, wkba_size(val->itemsNum)); base = b->tvheap->base; - if (*bun) { + if (*bun != (var_t) -1) { _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list