- result = (int2vector *)
- DatumGetPointer(DirectFunctionCall3(array_recv,
- PointerGetDatum(buf),
- ObjectIdGetDatum(INT2OID),
- Int32GetDatum(-1)));
+ /*
+ * Normally one would call array_recv() using DirectFunctionCall3,
+ * but that does not work since array_recv wants to cache some data
+ * using fcinfo->flinfo->fn_extra. So we need to pass it our own
+ * flinfo parameter.
+ */
+ InitFunctionCallInfoData(locfcinfo, fcinfo->flinfo, 3, NULL, NULL);
+
+ locfcinfo.arg[0] = PointerGetDatum(buf);
+ locfcinfo.arg[1] = ObjectIdGetDatum(INT2OID);
+ locfcinfo.arg[2] = Int32GetDatum(-1);
+ locfcinfo.argnull[0] = false;
+ locfcinfo.argnull[1] = false;
+ locfcinfo.argnull[2] = false;
+
+ result = (int2vector *) DatumGetPointer(array_recv(&locfcinfo));
+
+ Assert(!locfcinfo.isnull);
+