PostgreSQL Source Code  git master
plpy_procedure.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/transam.h"
#include "funcapi.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_proc_fn.h"
#include "catalog/pg_type.h"
#include "utils/builtins.h"
#include "utils/hsearch.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/syscache.h"
#include "plpython.h"
#include "plpy_procedure.h"
#include "plpy_elog.h"
#include "plpy_main.h"
Include dependency graph for plpy_procedure.c:

Go to the source code of this file.

Functions

static PLyProcedurePLy_procedure_create (HeapTuple procTup, Oid fn_oid, bool is_trigger)
 
static bool PLy_procedure_valid (PLyProcedure *proc, HeapTuple procTup)
 
static char * PLy_procedure_munge_source (const char *name, const char *src)
 
void init_procedure_caches (void)
 
char * PLy_procedure_name (PLyProcedure *proc)
 
PLyProcedurePLy_procedure_get (Oid fn_oid, Oid fn_rel, bool is_trigger)
 
void PLy_procedure_compile (PLyProcedure *proc, const char *src)
 
void PLy_procedure_delete (PLyProcedure *proc)
 

Variables

static HTABPLy_procedure_cache = NULL
 

Function Documentation

◆ init_procedure_caches()

void init_procedure_caches ( void  )

Definition at line 38 of file plpy_procedure.c.

References HASHCTL::entrysize, HASH_BLOBS, hash_create(), HASH_ELEM, and HASHCTL::keysize.

Referenced by PLy_initialize().

39 {
40  HASHCTL hash_ctl;
41 
42  memset(&hash_ctl, 0, sizeof(hash_ctl));
43  hash_ctl.keysize = sizeof(PLyProcedureKey);
44  hash_ctl.entrysize = sizeof(PLyProcedureEntry);
45  PLy_procedure_cache = hash_create("PL/Python procedures", 32, &hash_ctl,
47 }
#define HASH_ELEM
Definition: hsearch.h:87
Size entrysize
Definition: hsearch.h:73
struct PLyProcedureEntry PLyProcedureEntry
#define HASH_BLOBS
Definition: hsearch.h:88
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:316
Size keysize
Definition: hsearch.h:72
struct PLyProcedureKey PLyProcedureKey
static HTAB * PLy_procedure_cache

◆ PLy_procedure_compile()

void PLy_procedure_compile ( PLyProcedure proc,
const char *  src 
)

Definition at line 359 of file plpy_procedure.c.

References PLyProcedure::code, elog, ERROR, PLyProcedure::globals, PLyProcedure::mcxt, MemoryContextStrdup(), NAMEDATALEN, pfree(), PLy_elog(), PLy_interp_globals, PLy_procedure_munge_source(), PLyProcedure::proname, PLyProcedure::pyname, snprintf(), PLyProcedure::src, and PLyProcedure::statics.

Referenced by plpython_inline_handler(), and PLy_procedure_create().

360 {
361  PyObject *crv = NULL;
362  char *msrc;
363 
364  proc->globals = PyDict_Copy(PLy_interp_globals);
365 
366  /*
367  * SD is private preserved data between calls. GD is global data shared by
368  * all functions
369  */
370  proc->statics = PyDict_New();
371  PyDict_SetItemString(proc->globals, "SD", proc->statics);
372 
373  /*
374  * insert the function code into the interpreter
375  */
376  msrc = PLy_procedure_munge_source(proc->pyname, src);
377  /* Save the mangled source for later inclusion in tracebacks */
378  proc->src = MemoryContextStrdup(proc->mcxt, msrc);
379  crv = PyRun_String(msrc, Py_file_input, proc->globals, NULL);
380  pfree(msrc);
381 
382  if (crv != NULL)
383  {
384  int clen;
385  char call[NAMEDATALEN + 256];
386 
387  Py_DECREF(crv);
388 
389  /*
390  * compile a call to the function
391  */
392  clen = snprintf(call, sizeof(call), "%s()", proc->pyname);
393  if (clen < 0 || clen >= sizeof(call))
394  elog(ERROR, "string would overflow buffer");
395  proc->code = Py_CompileString(call, "<string>", Py_eval_input);
396  if (proc->code != NULL)
397  return;
398  }
399 
400  if (proc->proname)
401  PLy_elog(ERROR, "could not compile PL/Python function \"%s\"",
402  proc->proname);
403  else
404  PLy_elog(ERROR, "could not compile anonymous PL/Python code block");
405 }
static char * PLy_procedure_munge_source(const char *name, const char *src)
void PLy_elog(int elevel, const char *fmt,...)
Definition: plpy_elog.c:47
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define NAMEDATALEN
void pfree(void *pointer)
Definition: mcxt.c:949
#define ERROR
Definition: elog.h:43
MemoryContext mcxt
PyObject * PLy_interp_globals
Definition: plpy_main.c:71
PyObject * statics
PyObject * code
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1063
#define elog
Definition: elog.h:219
PyObject * globals

◆ PLy_procedure_create()

static PLyProcedure * PLy_procedure_create ( HeapTuple  procTup,
Oid  fn_oid,
bool  is_trigger 
)
static

Definition at line 141 of file plpy_procedure.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), Anum_pg_proc_prosrc, Anum_pg_proc_protrftypes, PLyProcedure::argnames, PLyProcedure::args, PLyProcedure::argstack, Assert, PLyProcedure::calldepth, PLyProcedure::code, elog, ereport, errcode(), errmsg(), ERROR, EVTTRIGGEROID, PLyProcedure::fn_readonly, PLyProcedure::fn_tid, PLyProcedure::fn_xmin, format_type_be(), get_func_arg_info(), GETSTRUCT, PLyProcedure::globals, HeapTupleHeaderGetRawXmin, HeapTupleIsValid, i, InvalidOid, PLyProcedure::is_setof, PLyProcedure::langid, PLyProcedure::mcxt, MemoryContextSwitchTo(), NAMEDATALEN, NameStr, PLyProcedure::nargs, NIL, ObjectIdGetDatum, oid_array_to_list(), palloc0(), pfree(), PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PLy_input_setup_func(), PLy_output_setup_func(), PLy_procedure_compile(), PLy_procedure_delete(), PROARGMODE_OUT, PROARGMODE_TABLE, PROCOID, PLyProcedure::proname, PROVOLATILE_VOLATILE, pstrdup(), PLyProcedure::pyname, RECORDOID, ReleaseSysCache(), PLyProcedure::result, PLyProcedure::result_in, SearchSysCache1(), snprintf(), PLyProcedure::src, PLyProcedure::statics, SysCacheGetAttr(), HeapTupleData::t_data, HeapTupleData::t_self, TextDatumGetCString, TopMemoryContext, PLyProcedure::trftypes, TRIGGEROID, TYPEOID, types, PLyDatumToOb::typoid, PLyObToDatum::typoid, TYPTYPE_PSEUDO, and VOIDOID.

Referenced by PLy_procedure_get().

142 {
143  char procName[NAMEDATALEN + 256];
144  Form_pg_proc procStruct;
145  PLyProcedure *volatile proc;
146  MemoryContext cxt;
147  MemoryContext oldcxt;
148  int rv;
149  char *ptr;
150 
151  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
152  rv = snprintf(procName, sizeof(procName),
153  "__plpython_procedure_%s_%u",
154  NameStr(procStruct->proname),
155  fn_oid);
156  if (rv >= sizeof(procName) || rv < 0)
157  elog(ERROR, "procedure name would overrun buffer");
158 
159  /* Replace any not-legal-in-Python-names characters with '_' */
160  for (ptr = procName; *ptr; ptr++)
161  {
162  if (!((*ptr >= 'A' && *ptr <= 'Z') ||
163  (*ptr >= 'a' && *ptr <= 'z') ||
164  (*ptr >= '0' && *ptr <= '9')))
165  *ptr = '_';
166  }
167 
168  /* Create long-lived context that all procedure info will live in */
170  procName,
172 
173  oldcxt = MemoryContextSwitchTo(cxt);
174 
175  proc = (PLyProcedure *) palloc0(sizeof(PLyProcedure));
176  proc->mcxt = cxt;
177 
178  PG_TRY();
179  {
180  Datum protrftypes_datum;
181  Datum prosrcdatum;
182  bool isnull;
183  char *procSource;
184  int i;
185 
186  proc->proname = pstrdup(NameStr(procStruct->proname));
187  proc->pyname = pstrdup(procName);
188  proc->fn_xmin = HeapTupleHeaderGetRawXmin(procTup->t_data);
189  proc->fn_tid = procTup->t_self;
190  proc->fn_readonly = (procStruct->provolatile != PROVOLATILE_VOLATILE);
191  proc->is_setof = procStruct->proretset;
192  proc->src = NULL;
193  proc->argnames = NULL;
194  proc->args = NULL;
195  proc->nargs = 0;
196  proc->langid = procStruct->prolang;
197  protrftypes_datum = SysCacheGetAttr(PROCOID, procTup,
199  &isnull);
200  proc->trftypes = isnull ? NIL : oid_array_to_list(protrftypes_datum);
201  proc->code = NULL;
202  proc->statics = NULL;
203  proc->globals = NULL;
204  proc->calldepth = 0;
205  proc->argstack = NULL;
206 
207  /*
208  * get information required for output conversion of the return value,
209  * but only if this isn't a trigger.
210  */
211  if (!is_trigger)
212  {
213  Oid rettype = procStruct->prorettype;
214  HeapTuple rvTypeTup;
215  Form_pg_type rvTypeStruct;
216 
217  rvTypeTup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(rettype));
218  if (!HeapTupleIsValid(rvTypeTup))
219  elog(ERROR, "cache lookup failed for type %u", rettype);
220  rvTypeStruct = (Form_pg_type) GETSTRUCT(rvTypeTup);
221 
222  /* Disallow pseudotype result, except for void or record */
223  if (rvTypeStruct->typtype == TYPTYPE_PSEUDO)
224  {
225  if (rettype == VOIDOID ||
226  rettype == RECORDOID)
227  /* okay */ ;
228  else if (rettype == TRIGGEROID || rettype == EVTTRIGGEROID)
229  ereport(ERROR,
230  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
231  errmsg("trigger functions can only be called as triggers")));
232  else
233  ereport(ERROR,
234  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
235  errmsg("PL/Python functions cannot return type %s",
236  format_type_be(rettype))));
237  }
238 
239  /* set up output function for procedure result */
240  PLy_output_setup_func(&proc->result, proc->mcxt,
241  rettype, -1, proc);
242 
243  ReleaseSysCache(rvTypeTup);
244  }
245  else
246  {
247  /*
248  * In a trigger function, we use proc->result and proc->result_in
249  * for converting tuples, but we don't yet have enough info to set
250  * them up. PLy_exec_trigger will deal with it.
251  */
252  proc->result.typoid = InvalidOid;
253  proc->result_in.typoid = InvalidOid;
254  }
255 
256  /*
257  * Now get information required for input conversion of the
258  * procedure's arguments. Note that we ignore output arguments here.
259  * If the function returns record, those I/O functions will be set up
260  * when the function is first called.
261  */
262  if (procStruct->pronargs)
263  {
264  Oid *types;
265  char **names,
266  *modes;
267  int pos,
268  total;
269 
270  /* extract argument type info from the pg_proc tuple */
271  total = get_func_arg_info(procTup, &types, &names, &modes);
272 
273  /* count number of in+inout args into proc->nargs */
274  if (modes == NULL)
275  proc->nargs = total;
276  else
277  {
278  /* proc->nargs was initialized to 0 above */
279  for (i = 0; i < total; i++)
280  {
281  if (modes[i] != PROARGMODE_OUT &&
282  modes[i] != PROARGMODE_TABLE)
283  (proc->nargs)++;
284  }
285  }
286 
287  /* Allocate arrays for per-input-argument data */
288  proc->argnames = (char **) palloc0(sizeof(char *) * proc->nargs);
289  proc->args = (PLyDatumToOb *) palloc0(sizeof(PLyDatumToOb) * proc->nargs);
290 
291  for (i = pos = 0; i < total; i++)
292  {
293  HeapTuple argTypeTup;
294  Form_pg_type argTypeStruct;
295 
296  if (modes &&
297  (modes[i] == PROARGMODE_OUT ||
298  modes[i] == PROARGMODE_TABLE))
299  continue; /* skip OUT arguments */
300 
301  Assert(types[i] == procStruct->proargtypes.values[pos]);
302 
303  argTypeTup = SearchSysCache1(TYPEOID,
304  ObjectIdGetDatum(types[i]));
305  if (!HeapTupleIsValid(argTypeTup))
306  elog(ERROR, "cache lookup failed for type %u", types[i]);
307  argTypeStruct = (Form_pg_type) GETSTRUCT(argTypeTup);
308 
309  /* disallow pseudotype arguments */
310  if (argTypeStruct->typtype == TYPTYPE_PSEUDO)
311  ereport(ERROR,
312  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
313  errmsg("PL/Python functions cannot accept type %s",
314  format_type_be(types[i]))));
315 
316  /* set up I/O function info */
317  PLy_input_setup_func(&proc->args[pos], proc->mcxt,
318  types[i], -1, /* typmod not known */
319  proc);
320 
321  /* get argument name */
322  proc->argnames[pos] = names ? pstrdup(names[i]) : NULL;
323 
324  ReleaseSysCache(argTypeTup);
325 
326  pos++;
327  }
328  }
329 
330  /*
331  * get the text of the function.
332  */
333  prosrcdatum = SysCacheGetAttr(PROCOID, procTup,
334  Anum_pg_proc_prosrc, &isnull);
335  if (isnull)
336  elog(ERROR, "null prosrc");
337  procSource = TextDatumGetCString(prosrcdatum);
338 
339  PLy_procedure_compile(proc, procSource);
340 
341  pfree(procSource);
342  }
343  PG_CATCH();
344  {
345  MemoryContextSwitchTo(oldcxt);
346  PLy_procedure_delete(proc);
347  PG_RE_THROW();
348  }
349  PG_END_TRY();
350 
351  MemoryContextSwitchTo(oldcxt);
352  return proc;
353 }
#define NIL
Definition: pg_list.h:69
ItemPointerData fn_tid
#define GETSTRUCT(TUP)
Definition: htup_details.h:661
struct typedefs * types
Definition: ecpg.c:29
char * pstrdup(const char *in)
Definition: mcxt.c:1076
int get_func_arg_info(HeapTuple procTup, Oid **p_argtypes, char ***p_argnames, char **p_argmodes)
Definition: funcapi.c:846
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define Anum_pg_proc_prosrc
Definition: pg_proc.h:115
void PLy_procedure_delete(PLyProcedure *proc)
int errcode(int sqlerrcode)
Definition: elog.c:575
void PLy_procedure_compile(PLyProcedure *proc, const char *src)
char * format_type_be(Oid type_oid)
Definition: format_type.c:94
#define Anum_pg_proc_protrftypes
Definition: pg_proc.h:114
TransactionId fn_xmin
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
FormData_pg_type * Form_pg_type
Definition: pg_type.h:233
unsigned int Oid
Definition: postgres_ext.h:31
#define PROARGMODE_OUT
Definition: pg_proc.h:5556
PLyDatumToOb * args
HeapTupleHeader t_data
Definition: htup.h:67
#define NAMEDATALEN
List * oid_array_to_list(Datum datum)
Definition: pg_proc.c:1156
char ** argnames
void pfree(void *pointer)
Definition: mcxt.c:949
#define VOIDOID
Definition: pg_type.h:690
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define TRIGGEROID
Definition: pg_type.h:692
#define PROARGMODE_TABLE
Definition: pg_proc.h:5559
MemoryContext mcxt
ItemPointerData t_self
Definition: htup.h:65
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
PyObject * statics
void PLy_input_setup_func(PLyDatumToOb *arg, MemoryContext arg_mcxt, Oid typeOid, int32 typmod, PLyProcedure *proc)
Definition: plpy_typeio.c:421
#define RECORDOID
Definition: pg_type.h:680
#define ereport(elevel, rest)
Definition: elog.h:122
MemoryContext TopMemoryContext
Definition: mcxt.c:43
#define PROVOLATILE_VOLATILE
Definition: pg_proc.h:5539
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
#define TextDatumGetCString(d)
Definition: builtins.h:92
PyObject * code
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
void * palloc0(Size size)
Definition: mcxt.c:877
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:83
#define InvalidOid
Definition: postgres_ext.h:36
#define PG_CATCH()
Definition: elog.h:293
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define EVTTRIGGEROID
Definition: pg_type.h:694
#define Assert(condition)
Definition: c.h:670
PLyDatumToOb result_in
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:307
#define PG_RE_THROW()
Definition: elog.h:314
PLySavedArgs * argstack
#define TYPTYPE_PSEUDO
Definition: pg_type.h:724
void PLy_output_setup_func(PLyObToDatum *arg, MemoryContext arg_mcxt, Oid typeOid, int32 typmod, PLyProcedure *proc)
Definition: plpy_typeio.c:299
PLyObToDatum result
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define NameStr(name)
Definition: c.h:547
#define elog
Definition: elog.h:219
#define PG_TRY()
Definition: elog.h:284
PyObject * globals
#define PG_END_TRY()
Definition: elog.h:300

◆ PLy_procedure_delete()

void PLy_procedure_delete ( PLyProcedure proc)

Definition at line 408 of file plpy_procedure.c.

References PLyProcedure::code, PLyProcedure::globals, PLyProcedure::mcxt, MemoryContextDelete(), and PLyProcedure::statics.

Referenced by plpython_inline_handler(), PLy_procedure_create(), and PLy_procedure_get().

409 {
410  Py_XDECREF(proc->code);
411  Py_XDECREF(proc->statics);
412  Py_XDECREF(proc->globals);
413  MemoryContextDelete(proc->mcxt);
414 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
MemoryContext mcxt
PyObject * statics
PyObject * code
PyObject * globals

◆ PLy_procedure_get()

PLyProcedure* PLy_procedure_get ( Oid  fn_oid,
Oid  fn_rel,
bool  is_trigger 
)

Definition at line 77 of file plpy_procedure.c.

References elog, ERROR, PLyProcedureKey::fn_oid, PLyProcedureKey::fn_rel, HASH_ENTER, HASH_REMOVE, hash_search(), HeapTupleIsValid, InvalidOid, ObjectIdGetDatum, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PLy_procedure_create(), PLy_procedure_delete(), PLy_procedure_valid(), PLyProcedureEntry::proc, PROCOID, ReleaseSysCache(), and SearchSysCache1().

Referenced by plpython_call_handler(), and plpython_validator().

78 {
79  bool use_cache = !(is_trigger && fn_rel == InvalidOid);
80  HeapTuple procTup;
81  PLyProcedureKey key;
82  PLyProcedureEntry *volatile entry = NULL;
83  PLyProcedure *volatile proc = NULL;
84  bool found = false;
85 
86  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(fn_oid));
87  if (!HeapTupleIsValid(procTup))
88  elog(ERROR, "cache lookup failed for function %u", fn_oid);
89 
90  /*
91  * Look for the function in the cache, unless we don't have the necessary
92  * information (e.g. during validation). In that case we just don't cache
93  * anything.
94  */
95  if (use_cache)
96  {
97  key.fn_oid = fn_oid;
98  key.fn_rel = fn_rel;
99  entry = hash_search(PLy_procedure_cache, &key, HASH_ENTER, &found);
100  proc = entry->proc;
101  }
102 
103  PG_TRY();
104  {
105  if (!found)
106  {
107  /* Haven't found it, create a new procedure */
108  proc = PLy_procedure_create(procTup, fn_oid, is_trigger);
109  if (use_cache)
110  entry->proc = proc;
111  }
112  else if (!PLy_procedure_valid(proc, procTup))
113  {
114  /* Found it, but it's invalid, free and reuse the cache entry */
115  entry->proc = NULL;
116  if (proc)
117  PLy_procedure_delete(proc);
118  proc = PLy_procedure_create(procTup, fn_oid, is_trigger);
119  entry->proc = proc;
120  }
121  /* Found it and it's valid, it's fine to use it */
122  }
123  PG_CATCH();
124  {
125  /* Do not leave an uninitialized entry in the cache */
126  if (use_cache)
128  PG_RE_THROW();
129  }
130  PG_END_TRY();
131 
132  ReleaseSysCache(procTup);
133 
134  return proc;
135 }
void PLy_procedure_delete(PLyProcedure *proc)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:902
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
static bool PLy_procedure_valid(PLyProcedure *proc, HeapTuple procTup)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#define InvalidOid
Definition: postgres_ext.h:36
static PLyProcedure * PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
#define PG_CATCH()
Definition: elog.h:293
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define PG_RE_THROW()
Definition: elog.h:314
PLyProcedure * proc
static HTAB * PLy_procedure_cache
#define elog
Definition: elog.h:219
#define PG_TRY()
Definition: elog.h:284
#define PG_END_TRY()
Definition: elog.h:300

◆ PLy_procedure_munge_source()

static char * PLy_procedure_munge_source ( const char *  name,
const char *  src 
)
static

Definition at line 434 of file plpy_procedure.c.

References Assert, elog, FATAL, palloc(), and snprintf().

Referenced by PLy_procedure_compile().

435 {
436  char *mrc,
437  *mp;
438  const char *sp;
439  size_t mlen;
440  int plen;
441 
442  /*
443  * room for function source and the def statement
444  */
445  mlen = (strlen(src) * 2) + strlen(name) + 16;
446 
447  mrc = palloc(mlen);
448  plen = snprintf(mrc, mlen, "def %s():\n\t", name);
449  Assert(plen >= 0 && plen < mlen);
450 
451  sp = src;
452  mp = mrc + plen;
453 
454  while (*sp != '\0')
455  {
456  if (*sp == '\r' && *(sp + 1) == '\n')
457  sp++;
458 
459  if (*sp == '\n' || *sp == '\r')
460  {
461  *mp++ = '\n';
462  *mp++ = '\t';
463  sp++;
464  }
465  else
466  *mp++ = *sp++;
467  }
468  *mp++ = '\n';
469  *mp++ = '\n';
470  *mp = '\0';
471 
472  if (mp > (mrc + mlen))
473  elog(FATAL, "buffer overrun in PLy_munge_source");
474 
475  return mrc;
476 }
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define FATAL
Definition: elog.h:52
#define Assert(condition)
Definition: c.h:670
const char * name
Definition: encode.c:521
void * palloc(Size size)
Definition: mcxt.c:848
#define elog
Definition: elog.h:219

◆ PLy_procedure_name()

char* PLy_procedure_name ( PLyProcedure proc)

Definition at line 57 of file plpy_procedure.c.

References PLyProcedure::proname.

Referenced by plpython_error_callback(), and PLy_traceback().

58 {
59  if (proc == NULL)
60  return "<unknown procedure>";
61  return proc->proname;
62 }

◆ PLy_procedure_valid()

static bool PLy_procedure_valid ( PLyProcedure proc,
HeapTuple  procTup 
)
static

Definition at line 420 of file plpy_procedure.c.

References PLyProcedure::fn_tid, PLyProcedure::fn_xmin, HeapTupleHeaderGetRawXmin, ItemPointerEquals(), HeapTupleData::t_data, and HeapTupleData::t_self.

Referenced by PLy_procedure_get().

421 {
422  if (proc == NULL)
423  return false;
424 
425  /* If the pg_proc tuple has changed, it's not valid */
426  if (!(proc->fn_xmin == HeapTupleHeaderGetRawXmin(procTup->t_data) &&
427  ItemPointerEquals(&proc->fn_tid, &procTup->t_self)))
428  return false;
429 
430  return true;
431 }
ItemPointerData fn_tid
TransactionId fn_xmin
HeapTupleHeader t_data
Definition: htup.h:67
ItemPointerData t_self
Definition: htup.h:65
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:307
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29

Variable Documentation

◆ PLy_procedure_cache

HTAB* PLy_procedure_cache = NULL
static

Definition at line 30 of file plpy_procedure.c.