If I have a multi-call SRF and a user_fctx struct allocated in the
multi_call_memory_ctx, and in the if(SRF_IS_FIRSTCALL()) block while still
in the multi_call_memory_ctx I use PG_GETARG_TEXT_P(n) to get an argument
to my function, and stash the result of this in my user_fctx struct, am I
guaranteed that this pointer will remain valid throughout the remaining
calls to this SRF, or should I instead use PG_GETARG_TEXT_P_COPY(n)?

Here is an example of what I am talking about

typedef struct testfunc_ctx {
 text * txt;
} testfunc_ctx;

Datum testfunc(PG_FUNCTION_ARGS)
 FuncCallContext *funcctx;
 testfunc_ctx *userctx;
 MemoryContext oldcontext;

  funcctx = SRF_FIRSTCALL_INIT();
  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
  userctx = palloc(sizeof(testfunc_ctx));
/* XXX does this need to be PG_GETARG_TEXT_P_COPY, or is this ok like this */
  userctx->txt = PG_GETARG_TEXT_P(0);
  funcctx->user_fctx = userctx;

 funcctx = SRF_PERCALL_SETUP();
 userctx = funcctx->user_fctx;
 /* do something with userctx->txt */

 if (done)
  SRF_RETURN_NEXT(funcctx, result);

The New Testament offers the basis for modern computer coding theory,
in the form of an affirmation of the binary number system.

        But let your communication be Yea, yea; nay, nay: for
        whatsoever is more than these cometh of evil.
                -- Matthew 5:37

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not

Reply via email to