Changeset: 4e56ae4b1912 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4e56ae4b1912 Modified Files: monetdb5/modules/kernel/bat5.c monetdb5/modules/kernel/bat5.h Branch: default Log Message:
Big cleanup of bat5.c; more often call BATsetaccess to make a bat writable. This is the second part for the fix of bug 3149. We now also call BATsetaccess to BAT_WRITE in more of the delete functions. Among others the function that was called in the test. diffs (truncated from 1542 to 300 lines): diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c --- a/monetdb5/modules/kernel/bat5.c +++ b/monetdb5/modules/kernel/bat5.c @@ -3,19 +3,20 @@ * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.monetdb.org/Legal/MonetDBLicense - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. - * + * * The Original Code is the MonetDB Database System. - * + * * The Initial Developer of the Original Code is CWI. * Portions created by CWI are Copyright (C) 1997-July 2008 CWI. * Copyright August 2008-2012 MonetDB B.V. * All Rights Reserved. -*/ + */ + /* * Peter Boncz, M.L. Kersten * Binary Association Tables @@ -42,27 +43,6 @@ #include "bat5.h" #include "mal_exception.h" -static int -CMDdensebat(BAT **ret, wrd *size) -{ - BAT *b; - - if (*size < 0) - *size = 0; - if (*size > (wrd) BUN_MAX) - *size = (wrd) BUN_MAX; - *ret = b = BATnew(TYPE_void, TYPE_void, (BUN) *size); - if (b == NULL) - return GDK_FAIL; - b->batDirty = 1; - b->hseqbase = 0; - b->tseqbase = 0; - BATkey(b, TRUE); - BATkey(BBP_cache(-b->batCacheid), TRUE); - BATsetcount(b, (BUN) *size); - return GDK_SUCCEED; -} - /* * The next collection of operators fill a hole in the MonetDB kernel libraries. * It provide handy operations on void-BATs. @@ -71,7 +51,7 @@ static BAT * lock_desc(bat bid) { BBPfix(bid); - return (BAT *) BBPgetdesc(bid); + return &BBPgetdesc(bid)->B; } static void @@ -80,105 +60,16 @@ unlock_desc(bat bid) BBPunfix(bid); } -static int -CMDcapacity(lng *res, int *bid) +/* set access mode to bat, replacing input with output */ +static BAT * +setaccess(BAT *b, int mode) { - if (BBPcheck((bat) *bid, "CMDcapacity")) { - BAT *b = lock_desc((bat) *bid); + BAT *bn; - if (b == NULL) { - *res = lng_nil; - } else { - *res = (lng) BATcapacity(b); - } - unlock_desc(*bid); - } - return GDK_SUCCEED; -} - -static int -CMDhead(str *res, int *bid) -{ - if (BBPcheck((bat) *bid, "CMDhead")) { - str ret = (str)str_nil; - BAT *b = lock_desc((bat) *bid); - - if (b) { - ret = *bid > 0 ? ATOMname(b->htype) : ATOMname(b->ttype); - } - *res = GDKstrdup(ret); - unlock_desc(*bid); - } else { - *res = GDKstrdup(str_nil); - } - return GDK_SUCCEED; -} - -static int -CMDtail(str *res, int *bid) -{ - if (BBPcheck((bat) *bid, "CMDtail")) { - str ret = (str)str_nil; - BAT *b = lock_desc((bat) *bid); - - if (b) { - ret = *bid > 0 ? ATOMname(b->ttype) : ATOMname(b->htype); - } - *res = GDKstrdup(ret); - unlock_desc(*bid); - } else { - *res = GDKstrdup(str_nil); - } - return GDK_SUCCEED; -} - -static int -CMDgetkey(bit *ret, BAT *b) -{ - /* we must take care of the special case of a nil column (TYPE_void,seqbase=nil) - * such nil columns never set hkey (and BUNins will never invalidate it if set) yet - * a nil column of a BAT with <= 1 entries does not contain doubles => return TRUE. - */ - if (BATcount(b) <= 1) { - *ret = TRUE; - } else { - if (!b->hkey) { - BATderiveHeadProps(b, 1); - } - *ret = b->hkey ? TRUE : FALSE; - } - return GDK_SUCCEED; -} - -static int -CMDdestroy(bit *res, str input ) -{ - int bid = BBPindex(input); - - *res = FALSE; - if (bid) { - BBPfix(bid); - if (BBPindex(input) == bid) { - BAT *b = (BAT*)BBPgetdesc(ABS(bid)); - - BATmode(b, TRANSIENT); - *res = TRUE; - } - BBPunfix(bid); - } - return GDK_SUCCEED; -} - -static int -CMDsetaccess(BAT **r, BAT *input, int *param) -{ - bat oldCacheid = input->batCacheid; - - *r = BATsetaccess(input, *param); - if ((*r)->batCacheid == oldCacheid) { - BBPfix(oldCacheid); - } - return GDK_SUCCEED; + bn = BATsetaccess(b, mode); /* can return NULL */ + if (b != bn) + BBPunfix(b->batCacheid); + return bn; } static char * @@ -620,14 +511,14 @@ CMDsave(bit *res, str input) str BKCnewBAT(int *res, int *ht, int *tt, BUN *cap) { - BAT *b; + BAT *bn; - b = BATnew(*ht == TYPE_oid ? TYPE_void : *ht, *tt, *cap); - if (b == NULL) + bn = BATnew(*ht == TYPE_oid ? TYPE_void : *ht, *tt, *cap); + if (bn == NULL) throw(MAL, "bat.new", GDK_EXCEPTION); if (*ht == TYPE_oid) - BATseqbase(b, 0); - *res = b->batCacheid; + BATseqbase(bn, 0); + *res = bn->batCacheid; BBPkeepref(*res); return MAL_SUCCEED; } @@ -635,28 +526,34 @@ BKCnewBAT(int *res, int *ht, int *tt, BU str BKCattach(int *ret, int *tt, str *heapfile) { - BAT *b; + BAT *bn; - b = BATattach(*tt, *heapfile); - if (b != NULL) { - *ret = b->batCacheid; - BBPkeepref(*ret); - return MAL_SUCCEED; - } - throw(MAL, "bat.attach", GDK_EXCEPTION); + bn = BATattach(*tt, *heapfile); + if (bn == NULL) + throw(MAL, "bat.attach", GDK_EXCEPTION); + *ret = bn->batCacheid; + BBPkeepref(*ret); + return MAL_SUCCEED; } str BKCdensebat(int *ret, wrd *size) { - BAT *b; + BAT *bn; - if (CMDdensebat(&b, size) == GDK_SUCCEED) { - *ret = b->batCacheid; - BBPkeepref(*ret); - return MAL_SUCCEED; - } - throw(MAL, "bat.densebat", GDK_EXCEPTION); + if (*size < 0) + *size = 0; + if (*size > (wrd) BUN_MAX) + *size = (wrd) BUN_MAX; + bn = BATnew(TYPE_void, TYPE_void, (BUN) *size); + if (bn == NULL) + throw(MAL, "bat.densebat", GDK_EXCEPTION); + BATsetcount(bn, (BUN) *size); + BATseqbase(bn, 0); + BATseqbase(BATmirror(bn), 0); + *ret = bn->batCacheid; + BBPkeepref(*ret); + return MAL_SUCCEED; } str @@ -669,13 +566,10 @@ BKCreverse(int *ret, int *bid) } bn = BATmirror(b); /* bn inherits ref from b */ - if (bn) { - *ret = bn->batCacheid; - BBPkeepref(bn->batCacheid); - return MAL_SUCCEED; - } - BBPreleaseref(b->batCacheid); - throw(MAL, "bat.reverse", GDK_EXCEPTION); + assert(bn != NULL); + *ret = bn->batCacheid; + BBPkeepref(bn->batCacheid); + return MAL_SUCCEED; } str @@ -707,160 +601,162 @@ BKCmirror(int *ret, int *bid) } str -BKCrevert(int *ret, int *bid) +BKCrevert(int *r, int *bid) { - BAT *b, *bn; + BAT *bn, *b; - if ((b = BATdescriptor(*bid)) == NULL) { + if ((b = BATdescriptor(*bid)) == NULL) throw(MAL, "bat.revert", RUNTIME_OBJECT_MISSING); - } - bn= BATrevert(b); - if(bn==NULL ){ + if ((b = setaccess(b, BAT_WRITE)) == NULL) + throw(MAL, "bat.revert", OPERATION_FAILED); + bn = BATrevert(b); + if (b != bn) BBPreleaseref(b->batCacheid); + if (bn == NULL) throw(MAL, "bat.revert", GDK_EXCEPTION); - } - BBPkeepref(*ret= bn->batCacheid); + BBPkeepref(*r = bn->batCacheid); return MAL_SUCCEED; } str -BKCorder(int *ret, int *bid) +BKCorder(int *r, int *bid) { _______________________________________________ Checkin-list mailing list [email protected] http://mail.monetdb.org/mailman/listinfo/checkin-list
