Skip to content

Commit 4812905

Browse files
Zhdanov0Alexander Zhdanovdyemanov
authored
Move the call of the checkArgsMismatch function before the call of th… (#8242)
* Move the call of the checkArgsMismatch function before the call of the setParamsFunc function * Replace unneeded checks with asserts. Move the JRD-level validation from pass2() to parse(). --------- Co-authored-by: Alexander Zhdanov <[email protected]> Co-authored-by: Dmitry Yemanov <[email protected]>
1 parent b14254f commit 4812905

File tree

2 files changed

+109
-103
lines changed

2 files changed

+109
-103
lines changed

src/dsql/ExprNodes.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12481,6 +12481,8 @@ DmlNode* SysFuncCallNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScrat
1248112481

1248212482
node->args = PAR_args(tdbb, csb);
1248312483

12484+
node->function->checkArgsMismatch(node->args->items.getCount());
12485+
1248412486
if (name == "MAKE_DBKEY")
1248512487
{
1248612488
// Special handling for system function MAKE_DBKEY:
@@ -12551,7 +12553,6 @@ void SysFuncCallNode::make(DsqlCompilerScratch* dsqlScratch, dsc* desc)
1255112553
}
1255212554

1255312555
DSqlDataTypeUtil dataTypeUtil(dsqlScratch);
12554-
function->checkArgsMismatch(argsArray.getCount());
1255512556
function->makeFunc(&dataTypeUtil, function, desc, argsArray.getCount(), argsArray.begin());
1255612557
}
1255712558

@@ -12618,8 +12619,6 @@ ValueExprNode* SysFuncCallNode::pass2(thread_db* tdbb, CompilerScratch* csb)
1261812619
{
1261912620
ValueExprNode::pass2(tdbb, csb);
1262012621

12621-
function->checkArgsMismatch(args->items.getCount());
12622-
1262312622
dsc desc;
1262412623
getDesc(tdbb, csb, &desc);
1262512624
impureOffset = csb->allocImpure<impure_value>();
@@ -12643,14 +12642,18 @@ ValueExprNode* SysFuncCallNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
1264312642

1264412643
if (node->function)
1264512644
{
12645+
auto& items = node->args->items;
12646+
12647+
node->function->checkArgsMismatch(items.getCount());
12648+
1264612649
if (node->function->setParamsFunc)
1264712650
{
12648-
Array<dsc> tempDescs(node->args->items.getCount());
12649-
tempDescs.resize(node->args->items.getCount());
12651+
Array<dsc> tempDescs(items.getCount());
12652+
tempDescs.resize(items.getCount());
1265012653

12651-
Array<dsc*> argsArray(node->args->items.getCount());
12654+
Array<dsc*> argsArray(items.getCount());
1265212655

12653-
for (auto& item : node->args->items)
12656+
for (auto& item : items)
1265412657
{
1265512658
DsqlDescMaker::fromNode(dsqlScratch, item);
1265612659

@@ -12669,7 +12672,7 @@ ValueExprNode* SysFuncCallNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
1266912672
node->function->setParamsFunc(&dataTypeUtil, node->function,
1267012673
argsArray.getCount(), argsArray.begin());
1267112674

12672-
for (auto& item : node->args->items)
12675+
for (auto& item : items)
1267312676
{
1267412677
PASS1_set_parameter_type(dsqlScratch, item,
1267512678
[&] (dsc* desc) { *desc = item->getDsqlDesc(); },

src/jrd/SysFunction.cpp

Lines changed: 98 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -615,24 +615,27 @@ void setParamsInt64(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc**
615615

616616
void setParamsSecondInteger(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
617617
{
618-
if (argsCount >= 2)
619-
{
620-
if (args[1]->isUnknown())
621-
args[1]->makeLong(0);
622-
}
618+
fb_assert(argsCount >= 2);
619+
620+
if (args[1]->isUnknown())
621+
args[1]->makeLong(0);
623622
}
624623

625624

626625
void setParamsAsciiVal(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
627626
{
628-
if (argsCount >= 1 && args[0]->isUnknown())
627+
fb_assert(argsCount >= 1);
628+
629+
if (args[0]->isUnknown())
629630
args[0]->makeText(1, CS_ASCII);
630631
}
631632

632633

633634
void setParamsBlobAppend(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
634635
{
635-
if (argsCount >= 1 && args[0]->isUnknown())
636+
fb_assert(argsCount >= 1);
637+
638+
if (args[0]->isUnknown())
636639
args[0]->makeBlob(isc_blob_text, CS_dynamic);
637640

638641
for (int i = 1; i < argsCount; ++i)
@@ -645,14 +648,18 @@ void setParamsBlobAppend(DataTypeUtilBase*, const SysFunction*, int argsCount, d
645648

646649
void setParamsCharToUuid(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
647650
{
648-
if (argsCount >= 1 && args[0]->isUnknown())
651+
fb_assert(argsCount >= 1);
652+
653+
if (args[0]->isUnknown())
649654
args[0]->makeText(Uuid::STR_LEN, ttype_ascii);
650655
}
651656

652657

653658
void setParamsDateAdd(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
654659
{
655-
if (argsCount >= 1 && args[0]->isUnknown())
660+
fb_assert(argsCount >= 3);
661+
662+
if (args[0]->isUnknown())
656663
{
657664
if (args[1]->dsc_address && // constant
658665
CVT_get_long(args[1], 0, JRD_get_thread_data()->getAttachment()->att_dec_status, ERR_post) == blr_extract_millisecond)
@@ -663,31 +670,32 @@ void setParamsDateAdd(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc*
663670
args[0]->makeInt64(0);
664671
}
665672

666-
if (argsCount >= 3 && args[2]->isUnknown())
673+
if (args[2]->isUnknown())
667674
args[2]->makeTimestamp();
668675
}
669676

670677

671678
void setParamsDateDiff(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
672679
{
673-
if (argsCount >= 3)
680+
fb_assert(argsCount >= 3);
681+
682+
if (args[1]->isUnknown() && args[2]->isUnknown())
674683
{
675-
if (args[1]->isUnknown() && args[2]->isUnknown())
676-
{
677-
args[1]->makeTimestamp();
678-
args[2]->makeTimestamp();
679-
}
680-
else if (args[1]->isUnknown())
681-
*args[1] = *args[2];
682-
else if (args[2]->isUnknown())
683-
*args[2] = *args[1];
684+
args[1]->makeTimestamp();
685+
args[2]->makeTimestamp();
684686
}
687+
else if (args[1]->isUnknown())
688+
*args[1] = *args[2];
689+
else if (args[2]->isUnknown())
690+
*args[2] = *args[1];
685691
}
686692

687693

688694
void setParamsUnicodeVal(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
689695
{
690-
if (argsCount >= 1 && args[0]->isUnknown())
696+
fb_assert(argsCount >= 1);
697+
698+
if (args[0]->isUnknown())
691699
args[0]->makeText(4, CS_UTF8);
692700
}
693701

@@ -823,23 +831,24 @@ void setParamsRsaPublic(DataTypeUtilBase*, const SysFunction*, int argsCount, ds
823831

824832
void setParamsFirstLastDay(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
825833
{
826-
if (argsCount >= 2)
827-
{
828-
if (args[1]->isUnknown())
829-
args[1]->makeTimestamp();
830-
}
834+
fb_assert(argsCount >= 2);
835+
836+
if (args[1]->isUnknown())
837+
args[1]->makeTimestamp();
831838
}
832839

833840

834841
void setParamsGetSetContext(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
835842
{
836-
if (argsCount >= 1 && args[0]->isUnknown())
843+
fb_assert(argsCount >= 2);
844+
845+
if (args[0]->isUnknown())
837846
{
838847
args[0]->makeVarying(80, ttype_none);
839848
args[0]->setNullable(true);
840849
}
841850

842-
if (argsCount >= 2 && args[1]->isUnknown())
851+
if (args[1]->isUnknown())
843852
{
844853
args[1]->makeVarying(80, ttype_none);
845854
args[1]->setNullable(true);
@@ -865,86 +874,84 @@ void setParamsMakeDbkey(DataTypeUtilBase*, const SysFunction*, int argsCount, ds
865874
{
866875
// MAKE_DBKEY ( REL_NAME | REL_ID, RECNUM [, DPNUM [, PPNUM] ] )
867876

868-
if (argsCount > 1)
869-
{
870-
if (args[0]->isUnknown())
871-
args[0]->makeLong(0);
877+
fb_assert(argsCount >= 2);
872878

873-
if (args[1]->isUnknown())
874-
args[1]->makeInt64(0);
875-
}
879+
if (args[0]->isUnknown())
880+
args[0]->makeLong(0);
876881

877-
if (argsCount > 2 && args[2]->isUnknown())
882+
if (args[1]->isUnknown())
883+
args[1]->makeInt64(0);
884+
885+
if (argsCount >= 3 && args[2]->isUnknown())
878886
args[2]->makeInt64(0);
879887

880-
if (argsCount > 3 && args[3]->isUnknown())
888+
if (argsCount >= 4 && args[3]->isUnknown())
881889
args[3]->makeInt64(0);
882890
}
883891

884892

885893
void setParamsOverlay(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
886894
{
887-
if (argsCount >= 3)
895+
fb_assert(argsCount >= 3);
896+
897+
if (!(args[0]->isUnknown() && args[1]->isUnknown()))
888898
{
889-
if (!(args[0]->isUnknown() && args[1]->isUnknown()))
890-
{
891-
if (args[1]->isUnknown())
892-
*args[1] = *args[0];
893-
else if (args[0]->isUnknown())
894-
*args[0] = *args[1];
895-
}
899+
if (args[1]->isUnknown())
900+
*args[1] = *args[0];
901+
else if (args[0]->isUnknown())
902+
*args[0] = *args[1];
903+
}
896904

897-
if (argsCount >= 4)
905+
if (argsCount >= 4)
906+
{
907+
if (args[2]->isUnknown() && args[3]->isUnknown())
898908
{
899-
if (args[2]->isUnknown() && args[3]->isUnknown())
900-
{
901-
args[2]->makeLong(0);
902-
args[3]->makeLong(0);
903-
}
904-
else if (args[2]->isUnknown())
905-
*args[2] = *args[3];
906-
else if (args[3]->isUnknown())
907-
*args[3] = *args[2];
908-
}
909-
910-
if (args[2]->isUnknown())
911909
args[2]->makeLong(0);
910+
args[3]->makeLong(0);
911+
}
912+
else if (args[2]->isUnknown())
913+
*args[2] = *args[3];
914+
else if (args[3]->isUnknown())
915+
*args[3] = *args[2];
912916
}
917+
918+
if (args[2]->isUnknown())
919+
args[2]->makeLong(0);
913920
}
914921

915922

916923
void setParamsPosition(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
917924
{
918-
if (argsCount >= 2)
919-
{
920-
if (args[0]->isUnknown())
921-
*args[0] = *args[1];
925+
fb_assert(argsCount >= 2);
922926

923-
if (args[1]->isUnknown())
924-
*args[1] = *args[0];
925-
}
927+
if (args[0]->isUnknown())
928+
*args[0] = *args[1];
929+
930+
if (args[1]->isUnknown())
931+
*args[1] = *args[0];
926932
}
927933

928934

929935
void setParamsRoundTrunc(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
930936
{
931-
if (argsCount >= 1)
932-
{
933-
if (args[0]->isUnknown())
934-
args[0]->makeDouble();
937+
fb_assert(argsCount >= 1);
935938

936-
if (argsCount >= 2)
937-
{
938-
if (args[1]->isUnknown())
939-
args[1]->makeLong(0);
940-
}
939+
if (args[0]->isUnknown())
940+
args[0]->makeDouble();
941+
942+
if (argsCount >= 2)
943+
{
944+
if (args[1]->isUnknown())
945+
args[1]->makeLong(0);
941946
}
942947
}
943948

944949

945950
void setParamsUuidToChar(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
946951
{
947-
if (argsCount >= 1 && args[0]->isUnknown())
952+
fb_assert(argsCount >= 1);
953+
954+
if (args[0]->isUnknown())
948955
args[0]->makeText(16, ttype_binary);
949956
}
950957

@@ -1308,23 +1315,20 @@ void makeBlobAppend(DataTypeUtilBase* dataTypeUtil, const SysFunction* function,
13081315
result->makeBlob(isc_blob_untyped, ttype_binary);
13091316
result->setNullable(true);
13101317

1311-
if (argsCount > 0)
1318+
for (int i = 0; i < argsCount; ++i)
13121319
{
1313-
for (int i = 0; i < argsCount; ++i)
1314-
{
1315-
if (makeBlobAppendBlob(result, args[i]))
1316-
break;
1317-
}
1320+
if (makeBlobAppendBlob(result, args[i]))
1321+
break;
1322+
}
13181323

1319-
result->setNullable(true);
1324+
result->setNullable(true);
13201325

1321-
for (int i = 0; i < argsCount; ++i)
1326+
for (int i = 0; i < argsCount; ++i)
1327+
{
1328+
if (!args[i]->isNullable())
13221329
{
1323-
if (!args[i]->isNullable())
1324-
{
1325-
result->setNullable(false);
1326-
break;
1327-
}
1330+
result->setNullable(false);
1331+
break;
13281332
}
13291333
}
13301334
}
@@ -1421,13 +1425,12 @@ void makeFirstLastDayResult(DataTypeUtilBase*, const SysFunction*, dsc* result,
14211425

14221426
result->makeDate();
14231427

1424-
if (argsCount >= 2)
1425-
{
1426-
if (args[1]->dsc_dtype == dtype_timestamp)
1427-
result->makeTimestamp();
1428-
else if (args[1]->dsc_dtype == dtype_timestamp_tz)
1429-
result->makeTimestampTz();
1430-
}
1428+
fb_assert(argsCount >= 2);
1429+
1430+
if (args[1]->dsc_dtype == dtype_timestamp)
1431+
result->makeTimestamp();
1432+
else if (args[1]->dsc_dtype == dtype_timestamp_tz)
1433+
result->makeTimestampTz();
14311434

14321435
result->setNullable(isNullable);
14331436
}

0 commit comments

Comments
 (0)