diff --git a/src/jrd/SysFunction.cpp b/src/jrd/SysFunction.cpp index 6a9a94bc71..678b916256 100644 --- a/src/jrd/SysFunction.cpp +++ b/src/jrd/SysFunction.cpp @@ -159,22 +159,32 @@ static double cot(double value) } -static void makeDoubleResult(DataTypeUtilBase* dataTypeUtil, SysFunction* function, dsc* result, int argsCount, const dsc** args) +static bool initResult(dsc* result, int argsCount, const dsc** args, bool* isNullable) { - bool isNullable = false; + *isNullable = false; for (int i = 0; i < argsCount; ++i) { if (args[i]->isNull()) { result->makeNullString(); - return; + return true; } if (args[i]->isNullable()) - isNullable = true; + *isNullable = true; } + return false; +} + + +static void makeDoubleResult(DataTypeUtilBase* dataTypeUtil, SysFunction* function, dsc* result, int argsCount, const dsc** args) +{ + bool isNullable; + if (initResult(result, argsCount, args, &isNullable)) + return; + result->makeDouble(); result->setNullable(isNullable); } @@ -189,19 +199,9 @@ static void makeFromListResult(DataTypeUtilBase* dataTypeUtil, SysFunction* func static void makeInt64Result(DataTypeUtilBase* dataTypeUtil, SysFunction* function, dsc* result, int argsCount, const dsc** args) { - bool isNullable = false; - - for (int i = 0; i < argsCount; ++i) - { - if (args[i]->isNull()) - { - result->makeNullString(); - return; - } - - if (args[i]->isNullable()) - isNullable = true; - } + bool isNullable; + if (initResult(result, argsCount, args, &isNullable)) + return; result->makeInt64(0); result->setNullable(isNullable); @@ -210,19 +210,9 @@ static void makeInt64Result(DataTypeUtilBase* dataTypeUtil, SysFunction* functio static void makeLongResult(DataTypeUtilBase* dataTypeUtil, SysFunction* function, dsc* result, int argsCount, const dsc** args) { - bool isNullable = false; - - for (int i = 0; i < argsCount; ++i) - { - if (args[i]->isNull()) - { - result->makeNullString(); - return; - } - - if (args[i]->isNullable()) - isNullable = true; - } + bool isNullable; + if (initResult(result, argsCount, args, &isNullable)) + return; result->makeLong(0); result->setNullable(isNullable); @@ -244,19 +234,9 @@ static void makeLongStringOrBlobResult(DataTypeUtilBase* dataTypeUtil, SysFuncti static void makeShortResult(DataTypeUtilBase* dataTypeUtil, SysFunction* function, dsc* result, int argsCount, const dsc** args) { - bool isNullable = false; - - for (int i = 0; i < argsCount; ++i) - { - if (args[i]->isNull()) - { - result->makeNullString(); - return; - } - - if (args[i]->isNullable()) - isNullable = true; - } + bool isNullable; + if (initResult(result, argsCount, args, &isNullable)) + return; result->makeShort(0); result->setNullable(isNullable); @@ -487,19 +467,9 @@ static void makeOverlay(DataTypeUtilBase* dataTypeUtil, SysFunction* function, d { fb_assert(argsCount >= function->minArgCount); - bool isNullable = false; - - for (int i = 0; i < argsCount; ++i) - { - if (args[i]->isNull()) - { - result->makeNullString(); - return; - } - - if (args[i]->isNullable()) - isNullable = true; - } + bool isNullable; + if (initResult(result, argsCount, args, &isNullable)) + return; const dsc* value = args[0]; const dsc* placing = args[1]; @@ -532,19 +502,9 @@ static void makePad(DataTypeUtilBase* dataTypeUtil, SysFunction* function, dsc* { fb_assert(argsCount >= function->minArgCount); - bool isNullable = false; - - for (int i = 0; i < argsCount; ++i) - { - if (args[i]->isNull()) - { - result->makeNullString(); - return; - } - - if (args[i]->isNullable()) - isNullable = true; - } + bool isNullable; + if (initResult(result, argsCount, args, &isNullable)) + return; const dsc* value1 = args[0]; const dsc* value2 = (argsCount >= 3 ? args[2] : NULL); @@ -783,8 +743,8 @@ static dsc* evlAsciiChar(Jrd::thread_db* tdbb, SysFunction* function, Jrd::jrd_n if (!(code >= 0 && code <= 255)) status_exception::raise(isc_arith_except, 0); - impure->vlu_misc.vlu_char = (SCHAR) code; - impure->vlu_desc.makeText(1, ttype_none, (UCHAR*) &impure->vlu_misc.vlu_char); + impure->vlu_misc.vlu_uchar = (UCHAR) code; + impure->vlu_desc.makeText(1, ttype_none, &impure->vlu_misc.vlu_uchar); return &impure->vlu_desc; } diff --git a/src/jrd/exe.h b/src/jrd/exe.h index 3232242f54..1ee35fb6d7 100644 --- a/src/jrd/exe.h +++ b/src/jrd/exe.h @@ -207,7 +207,7 @@ struct impure_value { USHORT vlu_flags; // Computed/invariant flags VaryingString* vlu_string; union { - SCHAR vlu_char; + UCHAR vlu_uchar; SSHORT vlu_short; SLONG vlu_long; SINT64 vlu_int64; @@ -500,6 +500,7 @@ const int e_domval_length = sizeof (DSC) / sizeof(::Jrd::jrd_nod*); // Room for // System function expression const int e_sysfun_args = 0; const int e_sysfun_function = 1; +const int e_sysfun_count = 1; const int e_sysfun_length = 2; // Request resources diff --git a/src/jrd/par.cpp b/src/jrd/par.cpp index afb96b949e..4f85041b08 100644 --- a/src/jrd/par.cpp +++ b/src/jrd/par.cpp @@ -2457,7 +2457,7 @@ static jrd_nod* par_sys_function(thread_db* tdbb, CompilerScratch* csb) } jrd_nod* node = PAR_make_node(tdbb, e_sysfun_length); - node->nod_count = 1; + node->nod_count = count_table[blr_sys_function]; node->nod_arg[e_sysfun_args] = par_args(tdbb, csb, VALUE); node->nod_arg[e_sysfun_function] = (jrd_nod*) function; diff --git a/src/misc/blrtable.cpp b/src/misc/blrtable.cpp index c2b7c9cfa5..db8bd6fa30 100644 --- a/src/misc/blrtable.cpp +++ b/src/misc/blrtable.cpp @@ -218,7 +218,7 @@ static const VERB verbs[] = PAIR(nod_strlen, blr_strlen, e_strlen_length, e_strlen_count, VALUE, VALUE), PAIR(nod_trim, blr_trim, e_trim_length, e_trim_count, VALUE, VALUE), PAIR(nod_init_variable, blr_init_variable, e_init_var_length, 0, STATEMENT, OTHER), - PAIR(nod_sys_function, blr_sys_function, 0, 0, VALUE, VALUE), + PAIR(nod_sys_function, blr_sys_function, e_sysfun_length, e_sysfun_count, VALUE, VALUE), {0, NULL, NULL, NULL, NULL, NULL, NULL} };