@@ -834,40 +834,15 @@ pldbgapi2_func_setup(PLpgSQL_execstate *estate, PLpgSQL_function *func)
834834 * in expected order (usually when plpgsql_check is initialized
835835 * inside function.
836836 */
837- if (!fcache_plpgsql )
837+ if (!fcache_plpgsql ||
838+ fcache_plpgsql -> magic != FMGR_CACHE_MAGIC ||
839+ !fcache_plpgsql -> is_plpgsql )
838840 {
839- ereport (WARNING ,
840- (errmsg ("late initialization of fmgr_plpgsql_cache" ),
841- errhint ("use \"load 'plpgsql_check'\" before you try to use pldbgapi2" )));
842-
843- /*
844- * Unfortunately, we have not access to fmgr context, so we should
845- * to use top memory context. This is permament leak, but only for
846- * few calls until fmgr hook will be correctly used.
847- */
848- oldcxt = MemoryContextSwitchTo (TopMemoryContext );
849-
850- fcache_plpgsql = palloc0 (sizeof (fmgr_plpgsql_cache ));
851-
852- fcache_plpgsql -> magic = FMGR_CACHE_MAGIC ;
853-
854- fcache_plpgsql -> funcid = func -> fn_oid ;
855-
856- fcache_plpgsql -> is_plpgsql = true;
857- fcache_plpgsql -> fn_mcxt = CurrentMemoryContext ;
858- fcache_plpgsql -> stmtid_stack = palloc_array (int , INITIAL_PLDBGAPI2_STMT_STACK_SIZE );
859- fcache_plpgsql -> stmtid_stack_size = INITIAL_PLDBGAPI2_STMT_STACK_SIZE ;
860- fcache_plpgsql -> current_stmtid_stack_size = 0 ;
861-
862- last_fmgr_plpgsql_cache = fcache_plpgsql ;
863-
864- MemoryContextSwitchTo (oldcxt );
841+ ereport (ERROR ,
842+ (errmsg ("too late initialization of fmgr_plpgsql_cache" ),
843+ errhint ("Use \"load 'plpgsql_check'\" before you use plpgsql_check functionality." )));
865844 }
866845
867- Assert (fcache_plpgsql -> magic == FMGR_CACHE_MAGIC );
868- Assert (fcache_plpgsql );
869- Assert (fcache_plpgsql -> is_plpgsql );
870-
871846#ifdef USE_ASSERT_CHECKING
872847
873848 if (fcache_plpgsql -> funcid != PLpgSQLinlineFunc )
0 commit comments