* The arguments are already evaluated into fcinfo->args.
*/
FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
+ Datum save_arg0 = fcinfo->args[0].value;
/* if either argument is NULL they can't be equal */
if (!fcinfo->args[0].isnull && !fcinfo->args[1].isnull)
{
Datum result;
+ /*
+ * If first argument is of varlena type, it might be an
+ * expanded datum. We need to ensure that the value passed to
+ * the comparison function is a read-only pointer. However,
+ * if we end by returning the first argument, that will be the
+ * original read-write pointer if it was read-write.
+ */
+ if (op->d.func.make_ro)
+ fcinfo->args[0].value =
+ MakeExpandedObjectReadOnlyInternal(save_arg0);
+
fcinfo->isnull = false;
result = op->d.func.fn_addr(fcinfo);
}
/* Arguments aren't equal, so return the first one */
- *op->resvalue = fcinfo->args[0].value;
+ *op->resvalue = save_arg0;
*op->resnull = fcinfo->args[0].isnull;
EEO_NEXT();
v_fcinfo = l_ptr_const(fcinfo, l_ptr(StructFunctionCallInfoData));
+ /* save original arg[0] */
+ v_arg0 = l_funcvalue(b, v_fcinfo, 0);
+
/* if either argument is NULL they can't be equal */
v_argnull0 = l_funcnull(b, v_fcinfo, 0);
v_argnull1 = l_funcnull(b, v_fcinfo, 1);
/* one (or both) of the arguments are null, return arg[0] */
LLVMPositionBuilderAtEnd(b, b_hasnull);
- v_arg0 = l_funcvalue(b, v_fcinfo, 0);
LLVMBuildStore(b, v_argnull0, v_resnullp);
LLVMBuildStore(b, v_arg0, v_resvaluep);
LLVMBuildBr(b, opblocks[opno + 1]);
/* build block to invoke function and check result */
LLVMPositionBuilderAtEnd(b, b_nonull);
+ /*
+ * If first argument is of varlena type, it might be an
+ * expanded datum. We need to ensure that the value
+ * passed to the comparison function is a read-only
+ * pointer. However, if we end by returning the first
+ * argument, that will be the original read-write pointer
+ * if it was read-write.
+ */
+ if (op->d.func.make_ro)
+ {
+ LLVMValueRef v_params[1];
+ LLVMValueRef v_arg0_ro;
+
+ v_params[0] = v_arg0;
+ v_arg0_ro =
+ l_call(b,
+ llvm_pg_var_func_type("MakeExpandedObjectReadOnlyInternal"),
+ llvm_pg_func(mod, "MakeExpandedObjectReadOnlyInternal"),
+ v_params, lengthof(v_params), "");
+ LLVMBuildStore(b, v_arg0_ro,
+ l_funcvaluep(b, v_fcinfo, 0));
+ }
+
v_retval = BuildV1Call(context, b, mod, fcinfo, &v_fcinfo_isnull);
/*
- * If result not null, and arguments are equal return null
- * (same result as if there'd been NULLs, hence reuse
- * b_hasnull).
+ * If result not null and arguments are equal return null,
+ * else return arg[0] (same result as if there'd been
+ * NULLs, hence reuse b_hasnull).
*/
v_argsequal = LLVMBuildAnd(b,
LLVMBuildICmp(b, LLVMIntEQ,