src/pl/tcl/pltcl.c
static Datum
pltcl_handler(PG_FUNCTION_ARGS, bool pltrusted)
{
	Datum		retval = (Datum) 0;
	pltcl_call_state current_call_state;
	pltcl_call_state *save_call_state;

	/*
	 * Initialize current_call_state to nulls/zeroes; in particular, set its
	 * prodesc pointer to null.  Anything that sets it non-null should
	 * increase the prodesc's fn_refcount at the same time.  We'll decrease
	 * the refcount, and then delete the prodesc if it's no longer referenced,
	 * on the way out of this function.  This ensures that prodescs live as
	 * long as needed even if somebody replaces the originating pg_proc row
	 * while they're executing.
	 */
	memset(&current_call_state, 0, sizeof(current_call_state));

	/*
	 * Ensure that static pointer is saved/restored properly
	 */
	save_call_state = pltcl_current_call_state;
	pltcl_current_call_state = &current_call_state;

	PG_TRY();
	{
		/*
		 * Determine if called as function or trigger and call appropriate
		 * subhandler
		 */
		if (CALLED_AS_TRIGGER(fcinfo))
		{
			/* invoke the trigger handler */
			retval = PointerGetDatum(pltcl_trigger_handler(fcinfo,
														   &current_call_state,
														   pltrusted));
		}
		else if (CALLED_AS_EVENT_TRIGGER(fcinfo))
		{
			/* invoke the event trigger handler */
			pltcl_event_trigger_handler(fcinfo, &current_call_state, pltrusted);
			retval = (Datum) 0;
		}
		else
		{
			/* invoke the regular function handler */
			current_call_state.fcinfo = fcinfo;
			retval = pltcl_func_handler(fcinfo, &current_call_state, pltrusted);
		}
	}
	PG_FINALLY();
	{
		/* Restore static pointer, then clean up the prodesc refcount if any */
		/*
		 * (We're being paranoid in case an error is thrown in context
		 * deletion)
		 */
		pltcl_current_call_state = save_call_state;
		if (current_call_state.prodesc != NULL)
		{
			Assert(current_call_state.prodesc->fn_refcount > 0);
			if (--current_call_state.prodesc->fn_refcount == 0)
				MemoryContextDelete(current_call_state.prodesc->fn_cxt);
		}
	}
	PG_END_TRY();

	return retval;
}
/**********************************************************************
 * pltcl_handler()		- Handler for function and trigger calls, for
 *						  both trusted and untrusted interpreters.
 **********************************************************************/
pltcl_handler()              - Handler for function and trigger calls, for
both trusted and untrusted interpreters.
pltcl_handler () - Handler for function and trigger calls for both trusted and untrusted interpreters .
static Datum
pltcl_handler(PG_FUNCTION_ARGS, bool pltrusted)
{
	Datum		retval = (Datum) 0;
	pltcl_call_state current_call_state;
	pltcl_call_state *save_call_state;
	memset(&current_call_state, 0, sizeof(current_call_state));
	save_call_state = pltcl_current_call_state;
	pltcl_current_call_state = &current_call_state;
	PG_TRY();
	{
		if (CALLED_AS_TRIGGER(fcinfo))
		{
			retval = PointerGetDatum(pltcl_trigger_handler(fcinfo,
														   &current_call_state,
														   pltrusted));
		}
		else if (CALLED_AS_EVENT_TRIGGER(fcinfo))
		{
			pltcl_event_trigger_handler(fcinfo, &current_call_state, pltrusted);
			retval = (Datum) 0;
		}
		else
		{
			current_call_state.fcinfo = fcinfo;
			retval = pltcl_func_handler(fcinfo, &current_call_state, pltrusted);
		}
	}
	PG_FINALLY();
	{
		pltcl_current_call_state = save_call_state;
		if (current_call_state.prodesc != NULL)
		{
			Assert(current_call_state.prodesc->fn_refcount > 0);
			if (--current_call_state.prodesc->fn_refcount == 0)
				MemoryContextDelete(current_call_state.prodesc->fn_cxt);
		}
	}
	PG_END_TRY();
	return retval;
}
static Datum pltcl_handler ( PG_FUNCTION_ARGS , bool pltrusted ) { Datum retval = ( Datum ) 0 ; pltcl_call_state current_call_state ; pltcl_call_state * save_call_state ; memset ( & current_call_state , 0 , sizeof ( current_call_state ) ) ; save_call_state = pltcl_current_call_state ; pltcl_current_call_state = & current_call_state ; PG_TRY ( ) ; { if ( CALLED_AS_TRIGGER ( fcinfo ) ) { retval = PointerGetDatum ( pltcl_trigger_handler ( fcinfo , & current_call_state , pltrusted ) ) ; } else if ( CALLED_AS_EVENT_TRIGGER ( fcinfo ) ) { pltcl_event_trigger_handler ( fcinfo , & current_call_state , pltrusted ) ; retval = ( Datum ) 0 ; } else { current_call_state . fcinfo = fcinfo ; retval = pltcl_func_handler ( fcinfo , & current_call_state , pltrusted ) ; } } PG_FINALLY ( ) ; { pltcl_current_call_state = save_call_state ; if ( current_call_state . prodesc != NULL ) { Assert ( current_call_state . prodesc -> fn_refcount > 0 ) ; if ( -- current_call_state . prodesc -> fn_refcount == 0 ) MemoryContextDelete ( current_call_state . prodesc -> fn_cxt ) ; } } PG_END_TRY ( ) ; return retval ; }
pltcl_handler()              - Handler for function and trigger calls, for
                                                both trusted and untrusted interpreters.
pltcl_handler () - Handler for function and trigger calls for both trusted and untrusted interpreters .
/*
	 * Initialize current_call_state to nulls/zeroes; in particular, set its
	 * prodesc pointer to null.  Anything that sets it non-null should
	 * increase the prodesc's fn_refcount at the same time.  We'll decrease
	 * the refcount, and then delete the prodesc if it's no longer referenced,
	 * on the way out of this function.  This ensures that prodescs live as
	 * long as needed even if somebody replaces the originating pg_proc row
	 * while they're executing.
	 */ /*
	 * Ensure that static pointer is saved/restored properly
	 */ /*
		 * Determine if called as function or trigger and call appropriate
		 * subhandler
		 */ /* invoke the trigger handler */ /* invoke the event trigger handler */ /* invoke the regular function handler */ /* Restore static pointer, then clean up the prodesc refcount if any */ /*
		 * (We're being paranoid in case an error is thrown in context
		 * deletion)
		 */