Changeset: 99d005605181 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=99d005605181
Modified Files:
monetdb5/modules/mal/batcalc.c
Branch: batcalc-updated
Log Message:
Fix retrieving parameters to MAL functions.
diffs (truncated from 559 to 300 lines):
diff --git a/monetdb5/modules/mal/batcalc.c b/monetdb5/modules/mal/batcalc.c
--- a/monetdb5/modules/mal/batcalc.c
+++ b/monetdb5/modules/mal/batcalc.c
@@ -38,39 +38,32 @@ static str
CMDbatUNARY(MalStkPtr stk, InstrPtr pci,
BAT *(*batfunc)(BAT *, BAT *, BAT *), const char
*malfunc)
{
- bat *bid;
+ bat bid;
BAT *bn, *b, *s = NULL, *r = NULL;
- bid = getArgReference_bat(stk, pci, 1);
- if ((b = BATdescriptor(*bid)) == NULL)
+ bid = *getArgReference_bat(stk, pci, 1);
+ if ((b = BATdescriptor(bid)) == NULL)
throw(MAL, malfunc, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
if (pci->argc == 3) {
- bid = getArgReference_bat(stk, pci, 2);
- if (*bid && (s = BATdescriptor(*bid)) == NULL) {
+ bid = *getArgReference_bat(stk, pci, 2);
+ if (!is_bat_nil(bid)) {
+ if ((s = BATdescriptor(bid)) == NULL) {
+ BBPunfix(b->batCacheid);
+ throw(MAL, malfunc, SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
+ }
+ if (s->ttype == TYPE_bit) {
+ r = s;
+ s = NULL;
+ }
+ }
+ } else if (pci->argc == 4) {
+ bid = *getArgReference_bat(stk, pci, 2);
+ if (!is_bat_nil(bid) && (s = BATdescriptor(bid)) == NULL) {
BBPunfix(b->batCacheid);
throw(MAL, malfunc, SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
}
- switch (s->ttype) {
- case TYPE_oid:
- case TYPE_void:
- break;
- case TYPE_bit:
- r = s;
- s = NULL;
- break;
- default:
- BBPunfix(b->batCacheid);
- BBPunfix(s->batCacheid);
- throw(MAL, malfunc, SQLSTATE(42000) ILLEGAL_ARGUMENT);
- }
- } else if (pci->argc == 4) {
- bid = getArgReference_bat(stk, pci, 2);
- if (*bid && (s = BATdescriptor(*bid)) == NULL) {
- BBPunfix(b->batCacheid);
- throw(MAL, malfunc, SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
- }
- bid = getArgReference_bat(stk, pci, 3);
- if (*bid && (r = BATdescriptor(*bid)) == NULL) {
+ bid = *getArgReference_bat(stk, pci, 3);
+ if (!is_bat_nil(bid) && (r = BATdescriptor(bid)) == NULL) {
BBPunfix(b->batCacheid);
BBPunfix(s->batCacheid);
throw(MAL, malfunc, SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
@@ -84,8 +77,8 @@ CMDbatUNARY(MalStkPtr stk, InstrPtr pci,
if (bn == NULL) {
return mythrow(MAL, malfunc, OPERATION_FAILED);
}
- bid = getArgReference_bat(stk, pci, 0);
- BBPkeepref(*bid = bn->batCacheid);
+ *getArgReference_bat(stk, pci, 0) = bn->batCacheid;
+ BBPkeepref(bn->batCacheid);
return MAL_SUCCEED;
}
@@ -93,39 +86,32 @@ static str
CMDbatUNARY1(MalStkPtr stk, InstrPtr pci, bool abort_on_error,
BAT *(*batfunc)(BAT *, BAT *, BAT *, bool), const char
*malfunc)
{
- bat *bid;
+ bat bid;
BAT *bn, *b, *s = NULL, *r = NULL;
- bid = getArgReference_bat(stk, pci, 1);
- if ((b = BATdescriptor(*bid)) == NULL)
+ bid = *getArgReference_bat(stk, pci, 1);
+ if ((b = BATdescriptor(bid)) == NULL)
throw(MAL, malfunc, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
if (pci->argc == 3) {
- bid = getArgReference_bat(stk, pci, 2);
- if (*bid && (s = BATdescriptor(*bid)) == NULL) {
+ bid = *getArgReference_bat(stk, pci, 2);
+ if (!is_bat_nil(bid)) {
+ if ((s = BATdescriptor(bid)) == NULL) {
+ BBPunfix(b->batCacheid);
+ throw(MAL, malfunc, SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
+ }
+ if (s->ttype == TYPE_bit) {
+ r = s;
+ s = NULL;
+ }
+ }
+ } else if (pci->argc == 4) {
+ bid = *getArgReference_bat(stk, pci, 2);
+ if (!is_bat_nil(bid) && (s = BATdescriptor(bid)) == NULL) {
BBPunfix(b->batCacheid);
throw(MAL, malfunc, SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
}
- switch (s->ttype) {
- case TYPE_oid:
- case TYPE_void:
- break;
- case TYPE_bit:
- r = s;
- s = NULL;
- break;
- default:
- BBPunfix(b->batCacheid);
- BBPunfix(s->batCacheid);
- throw(MAL, malfunc, SQLSTATE(42000) ILLEGAL_ARGUMENT);
- }
- } else if (pci->argc == 4) {
- bid = getArgReference_bat(stk, pci, 2);
- if (*bid && (s = BATdescriptor(*bid)) == NULL) {
- BBPunfix(b->batCacheid);
- throw(MAL, malfunc, SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
- }
- bid = getArgReference_bat(stk, pci, 3);
- if (*bid && (r = BATdescriptor(*bid)) == NULL) {
+ bid = *getArgReference_bat(stk, pci, 3);
+ if (!is_bat_nil(bid) && (r = BATdescriptor(bid)) == NULL) {
BBPunfix(b->batCacheid);
BBPunfix(s->batCacheid);
throw(MAL, malfunc, SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
@@ -139,8 +125,8 @@ CMDbatUNARY1(MalStkPtr stk, InstrPtr pci
if (bn == NULL) {
return mythrow(MAL, malfunc, OPERATION_FAILED);
}
- bid = getArgReference_bat(stk, pci, 0);
- BBPkeepref(*bid = bn->batCacheid);
+ *getArgReference_bat(stk, pci, 0) = bn->batCacheid;
+ BBPkeepref(bn->batCacheid);
return MAL_SUCCEED;
}
@@ -338,6 +324,24 @@ calcmodtype(int tp1, int tp2)
return MIN(tp1, tp2);
}
+/* MAL function has one of the following signatures:
+ * # without candidate list
+ * func(b1:bat, b2:bat) :bat
+ * func(b1:bat, v2:any) :bat
+ * func(v1:any, b2:bat) :bat
+ * # with candidate list
+ * func(b1:bat, b2:bat, s1:bat, s2:bat) :bat
+ * func(b1:bat, v2:any, s1:bat) :bat
+ * func(v1:any, b2:bat, s2:bat) :bat
+ * # without candidate list
+ * func(b1:bat, b2:bat, r:bat) :bat
+ * func(b1:bat, v2:any, r:bat) :bat
+ * func(v1:any, b2:bat, r:bat) :bat
+ * # with candidate list
+ * func(b1:bat, b2:bat, s1:bat, s2:bat, r:bat) :bat
+ * func(b1:bat, v2:any, s1:bat, r:bat) :bat
+ * func(v1:any, b2:bat, s2:bat, r:bat) :bat
+ */
static str
CMDbatBINARY2(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci,
BAT *(*batfunc)(BAT *, BAT *, BAT *, BAT *, BAT *,
int, bool),
@@ -348,7 +352,7 @@ CMDbatBINARY2(MalBlkPtr mb, MalStkPtr st
{
bat bid;
BAT *bn, *b1 = NULL, *b2 = NULL, *s1 = NULL, *s2 = NULL, *r = NULL;
- int tp1, tp2, tp3, stp;
+ int tp1, tp2, tp3;
tp1 = stk->stk[getArg(pci, 1)].vtype; /* first argument */
tp2 = stk->stk[getArg(pci, 2)].vtype; /* second argument */
@@ -361,17 +365,6 @@ CMDbatBINARY2(MalBlkPtr mb, MalStkPtr st
b1 = BATdescriptor(bid);
if (b1 == NULL)
goto bailout;
- if (pci->argc >= 4
- && ((stp = stk->stk[getArg(pci, 3)].vtype) == TYPE_bat
- || isaBatType(stp))) {
- bid = *getArgReference_bat(stk, pci, 3);
- if (bid && (s1 = BATdescriptor(bid)) == NULL)
- goto bailout;
- if (pci->argc == 4 && s1->ttype == TYPE_bit) {
- r = s1;
- s1 = NULL;
- }
- }
}
if (tp2 == TYPE_bat || isaBatType(tp2)) {
@@ -379,24 +372,48 @@ CMDbatBINARY2(MalBlkPtr mb, MalStkPtr st
b2 = BATdescriptor(bid);
if (b2 == NULL)
goto bailout;
- if (pci->argc >= 4 + (b1 != NULL)
- && ((stp = stk->stk[getArg(pci, 3 + (b1 !=
NULL))].vtype) == TYPE_bat
- || isaBatType(stp))) {
- bid = *getArgReference_bat(stk, pci, 3 + (b1 != NULL));
- if (bid && (s2 = BATdescriptor(bid)) == NULL)
+ }
+
+ if (pci->argc > 5) {
+ assert(pci->argc == 6);
+ bid = *getArgReference_bat(stk, pci, 5);
+ if (!is_bat_nil(bid)) {
+ r = BATdescriptor(bid);
+ if (r == NULL)
goto bailout;
- if (pci->argc == 4 + (b1 != NULL) && s2->ttype ==
TYPE_bit) {
+ assert(r->ttype == TYPE_bit);
+ }
+ }
+ if (pci->argc > 4) {
+ bid = *getArgReference_bat(stk, pci, 4);
+ if (!is_bat_nil(bid)) {
+ s2 = BATdescriptor(bid);
+ if (s2 == NULL)
+ goto bailout;
+ if (s2->ttype == TYPE_bit) {
+ assert(pci->argc == 5);
+ assert(r == NULL);
+ assert(b1 == NULL || b2 == NULL);
r = s2;
s2 = NULL;
}
}
}
-
- if (r == NULL && pci->argc == 4 + (s1 != NULL) + (s2 != NULL)) {
- bid = *getArgReference_bat(stk, pci, pci->argc - 1);
- if (bid && (r = BATdescriptor(bid)) == NULL)
- goto bailout;
- assert(r->ttype == TYPE_bit);
+ if (pci->argc > 3) {
+ bid = *getArgReference_bat(stk, pci, 3);
+ if (!is_bat_nil(bid)) {
+ s1 = BATdescriptor(bid);
+ if (s1 == NULL)
+ goto bailout;
+ if (s1->ttype == TYPE_bit) {
+ assert(pci->argc == 4);
+ r = s1;
+ s1 = NULL;
+ } else if (b1 == NULL) {
+ s2 = s1;
+ s1 = NULL;
+ }
+ }
}
if (b1 && b2) {
@@ -443,6 +460,25 @@ bailout:
throw(MAL, malfunc, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
}
+/* MAL function has one of the signatures for CMDbatBINARY2, or one of
+ * the following:
+ * # without candidate list
+ * func(b1:bat, b2:bat, abort_on_error:bit) :bat
+ * func(b1:bat, v2:any, abort_on_error:bit) :bat
+ * func(v1:any, b2:bat, abort_on_error:bit) :bat
+ * # with candidate list
+ * func(b1:bat, b2:bat, s1:bat, s2:bat, abort_on_error:bit) :bat
+ * func(b1:bat, v2:any, s1:bat, abort_on_error:bit) :bat
+ * func(v1:any, b2:bat, s2:bat, abort_on_error:bit) :bat
+ * # without candidate list
+ * func(b1:bat, b2:bat, r:bat, abort_on_error:bit) :bat
+ * func(b1:bat, v2:any, r:bat, abort_on_error:bit) :bat
+ * func(v1:any, b2:bat, r:bat, abort_on_error:bit) :bat
+ * # with candidate list
+ * func(b1:bat, b2:bat, s1:bat, s2:bat, r:bat, abort_on_error:bit) :bat
+ * func(b1:bat, v2:any, s1:bat, r:bat, abort_on_error:bit) :bat
+ * func(v1:any, b2:bat, s2:bat, r:bat, abort_on_error:bit) :bat
+ */
static str
CMDbatBINARY1(MalStkPtr stk, InstrPtr pci,
BAT *(*batfunc)(BAT *, BAT *, BAT *, BAT *, BAT *,
bool),
@@ -453,7 +489,7 @@ CMDbatBINARY1(MalStkPtr stk, InstrPtr pc
{
bat bid;
BAT *bn, *b1 = NULL, *b2 = NULL, *s1 = NULL, *s2 = NULL, *r = NULL;
- int tp1, tp2, stp;
+ int tp1, tp2;
tp1 = stk->stk[getArg(pci, 1)].vtype; /* first argument */
tp2 = stk->stk[getArg(pci, 2)].vtype; /* second argument */
@@ -463,17 +499,6 @@ CMDbatBINARY1(MalStkPtr stk, InstrPtr pc
b1 = BATdescriptor(bid);
if (b1 == NULL)
goto bailout;
- if (pci->argc >= 4
- && ((stp = stk->stk[getArg(pci, 3)].vtype) == TYPE_bat
- || isaBatType(stp))) {
- bid = *getArgReference_bat(stk, pci, 3);
- if (bid && (s1 = BATdescriptor(bid)) == NULL)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list