Fix PL/Python for recursion and interleaved set-returning functions.
[pgsql.git] / src / pl / plpython / plpy_procedure.h
blob8ffa38e06866d50587d5751156c73034f027bf23
1 /*
2 * src/pl/plpython/plpy_procedure.h
3 */
5 #ifndef PLPY_PROCEDURE_H
6 #define PLPY_PROCEDURE_H
8 #include "plpy_typeio.h"
11 extern void init_procedure_caches(void);
14 /* saved arguments for outer recursion level or set-returning function */
15 typedef struct PLySavedArgs
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;
23 /* cached procedure data */
24 typedef struct PLyProcedure
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 procedure returns result set */
34 PLyTypeInfo result; /* also used to store info for trigger tuple
35 * type */
36 char *src; /* textual procedure code, after mangling */
37 char **argnames; /* Argument names */
38 PLyTypeInfo args[FUNC_MAX_ARGS];
39 int nargs;
40 Oid langid; /* OID of plpython pg_language entry */
41 List *trftypes; /* OID list of transform types */
42 PyObject *code; /* compiled procedure code */
43 PyObject *statics; /* data saved across calls, local scope */
44 PyObject *globals; /* data saved across calls, global scope */
45 long calldepth; /* depth of recursive calls of function */
46 PLySavedArgs *argstack; /* stack of outer-level call arguments */
47 } PLyProcedure;
49 /* the procedure cache key */
50 typedef struct PLyProcedureKey
52 Oid fn_oid; /* function OID */
53 Oid fn_rel; /* triggered-on relation or InvalidOid */
54 } PLyProcedureKey;
56 /* the procedure cache entry */
57 typedef struct PLyProcedureEntry
59 PLyProcedureKey key; /* hash key */
60 PLyProcedure *proc;
61 } PLyProcedureEntry;
63 /* PLyProcedure manipulation */
64 extern char *PLy_procedure_name(PLyProcedure *proc);
65 extern PLyProcedure *PLy_procedure_get(Oid fn_oid, Oid fn_rel, bool is_trigger);
66 extern void PLy_procedure_compile(PLyProcedure *proc, const char *src);
67 extern void PLy_procedure_delete(PLyProcedure *proc);
69 #endif /* PLPY_PROCEDURE_H */