1 /*
2  * src/pl/plpython/plpy_procedure.h
3  */
4 
5 #ifndef PLPY_PROCEDURE_H
6 #define PLPY_PROCEDURE_H
7 
8 #include "plpy_typeio.h"
9 
10 
11 extern void init_procedure_caches(void);
12 
13 
14 /* saved arguments for outer recursion level or set-returning function */
15 typedef struct PLySavedArgs
16 {
17 	struct PLySavedArgs *next;	/* linked-list pointer */
18 	PyObject   *args;			/* "args" element of globals dict */
19 	int			nargs;			/* length of namedargs array */
20 	PyObject   *namedargs[FLEXIBLE_ARRAY_MEMBER];	/* named args */
21 } PLySavedArgs;
22 
23 /* cached procedure data */
24 typedef struct PLyProcedure
25 {
26 	MemoryContext mcxt;			/* context holding this PLyProcedure and its
27 								 * subsidiary data */
28 	char	   *proname;		/* SQL name of procedure */
29 	char	   *pyname;			/* Python name of procedure */
30 	TransactionId fn_xmin;
31 	ItemPointerData fn_tid;
32 	bool		fn_readonly;
33 	bool		is_setof;		/* true, if function returns result set */
34 	bool		is_procedure;
35 	PLyObToDatum result;		/* Function result output conversion info */
36 	PLyDatumToOb result_in;		/* For converting input tuples in a trigger */
37 	char	   *src;			/* textual procedure code, after mangling */
38 	char	  **argnames;		/* Argument names */
39 	PLyDatumToOb *args;			/* Argument input conversion info */
40 	int			nargs;			/* Number of elements in above arrays */
41 	Oid			langid;			/* OID of plpython pg_language entry */
42 	List	   *trftypes;		/* OID list of transform types */
43 	PyObject   *code;			/* compiled procedure code */
44 	PyObject   *statics;		/* data saved across calls, local scope */
45 	PyObject   *globals;		/* data saved across calls, global scope */
46 	long		calldepth;		/* depth of recursive calls of function */
47 	PLySavedArgs *argstack;		/* stack of outer-level call arguments */
48 } PLyProcedure;
49 
50 /* the procedure cache key */
51 typedef struct PLyProcedureKey
52 {
53 	Oid			fn_oid;			/* function OID */
54 	Oid			fn_rel;			/* triggered-on relation or InvalidOid */
55 } PLyProcedureKey;
56 
57 /* the procedure cache entry */
58 typedef struct PLyProcedureEntry
59 {
60 	PLyProcedureKey key;		/* hash key */
61 	PLyProcedure *proc;
62 } PLyProcedureEntry;
63 
64 /* PLyProcedure manipulation */
65 extern char *PLy_procedure_name(PLyProcedure *proc);
66 extern PLyProcedure *PLy_procedure_get(Oid fn_oid, Oid fn_rel, bool is_trigger);
67 extern void PLy_procedure_compile(PLyProcedure *proc, const char *src);
68 extern void PLy_procedure_delete(PLyProcedure *proc);
69 
70 #endif							/* PLPY_PROCEDURE_H */
71