src/pl/tcl/pltcl.c
static void
pltcl_init_tuple_store(pltcl_call_state *call_state)
{
	ReturnSetInfo *rsi = call_state->rsi;
	MemoryContext oldcxt;
	ResourceOwner oldowner;

	/* Should be in a SRF */
	Assert(rsi);
	/* Should be first time through */
	Assert(!call_state->tuple_store);
	Assert(!call_state->attinmeta);

	/* We expect caller to provide an appropriate result tupdesc */
	Assert(rsi->expectedDesc);
	call_state->ret_tupdesc = rsi->expectedDesc;

	/*
	 * Switch to the right memory context and resource owner for storing the
	 * tuplestore. If we're within a subtransaction opened for an exception
	 * block, for example, we must still create the tuplestore in the resource
	 * owner that was active when this function was entered, and not in the
	 * subtransaction's resource owner.
	 */
	oldcxt = MemoryContextSwitchTo(call_state->tuple_store_cxt);
	oldowner = CurrentResourceOwner;
	CurrentResourceOwner = call_state->tuple_store_owner;

	call_state->tuple_store =
		tuplestore_begin_heap(rsi->allowedModes & SFRM_Materialize_Random,
							  false, work_mem);

	/* Build attinmeta in this context, too */
	call_state->attinmeta = TupleDescGetAttInMetadata(call_state->ret_tupdesc);

	CurrentResourceOwner = oldowner;
	MemoryContextSwitchTo(oldcxt);
}
/**********************************************************************
 * pltcl_init_tuple_store() - Initialize the result tuplestore for a SRF
 **********************************************************************/
Initialize the result tuplestore for a SRF
Initialize the result tuplestore for a SRF
static void
pltcl_init_tuple_store(pltcl_call_state *call_state)
{
	ReturnSetInfo *rsi = call_state->rsi;
	MemoryContext oldcxt;
	ResourceOwner oldowner;
	Assert(rsi);
	Assert(!call_state->tuple_store);
	Assert(!call_state->attinmeta);
	Assert(rsi->expectedDesc);
	call_state->ret_tupdesc = rsi->expectedDesc;
	oldcxt = MemoryContextSwitchTo(call_state->tuple_store_cxt);
	oldowner = CurrentResourceOwner;
	CurrentResourceOwner = call_state->tuple_store_owner;
	call_state->tuple_store =
		tuplestore_begin_heap(rsi->allowedModes & SFRM_Materialize_Random,
							  false, work_mem);
	call_state->attinmeta = TupleDescGetAttInMetadata(call_state->ret_tupdesc);
	CurrentResourceOwner = oldowner;
	MemoryContextSwitchTo(oldcxt);
}
static void pltcl_init_tuple_store ( pltcl_call_state * call_state ) { ReturnSetInfo * rsi = call_state -> rsi ; MemoryContext oldcxt ; ResourceOwner oldowner ; Assert ( rsi ) ; Assert ( ! call_state -> tuple_store ) ; Assert ( ! call_state -> attinmeta ) ; Assert ( rsi -> expectedDesc ) ; call_state -> ret_tupdesc = rsi -> expectedDesc ; oldcxt = MemoryContextSwitchTo ( call_state -> tuple_store_cxt ) ; oldowner = CurrentResourceOwner ; CurrentResourceOwner = call_state -> tuple_store_owner ; call_state -> tuple_store = tuplestore_begin_heap ( rsi -> allowedModes & SFRM_Materialize_Random , false , work_mem ) ; call_state -> attinmeta = TupleDescGetAttInMetadata ( call_state -> ret_tupdesc ) ; CurrentResourceOwner = oldowner ; MemoryContextSwitchTo ( oldcxt ) ; }
pltcl_init_tuple_store() - Initialize the result tuplestore for a SRF
pltcl_init_tuple_store () - Initialize the result tuplestore for a SRF
/* Should be in a SRF */ /* Should be first time through */ /* We expect caller to provide an appropriate result tupdesc */ /*
	 * Switch to the right memory context and resource owner for storing the
	 * tuplestore. If we're within a subtransaction opened for an exception
	 * block, for example, we must still create the tuplestore in the resource
	 * owner that was active when this function was entered, and not in the
	 * subtransaction's resource owner.
	 */ /* Build attinmeta in this context, too */