From: | Jeremy Drake <pgsql(at)jdrake(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | quick SRF question |
Date: | 2007-02-08 02:50:40 |
Message-ID: | Pine.BSO.4.64.0702071838430.28908@resin.csoft.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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;
if (SRF_IS_FIRSTCALL())
{
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);
MemoryContextSwitchTo(oldcontext);
funcctx->user_fctx = userctx;
}
funcctx = SRF_PERCALL_SETUP();
userctx = funcctx->user_fctx;
/* do something with userctx->txt */
if (done)
SRF_RETURN_DONE(funcctx);
else
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
From | Date | Subject | |
---|---|---|---|
Next Message | Jan Wieck | 2007-02-08 03:13:22 | Re: Proposal: Commit timestamp |
Previous Message | Markus Schiltknecht | 2007-02-08 02:27:52 | Re: Proposal: Commit timestamp |