PostgreSQL Source Code  git master
ltree_plpython.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "plpython.h"
#include "ltree.h"
Include dependency graph for ltree_plpython.c:

Go to the source code of this file.

Macros

#define PLyUnicode_FromStringAndSize   PLyUnicode_FromStringAndSize_p
 

Functions

void _PG_init (void)
 
 PG_FUNCTION_INFO_V1 (ltree_to_plpython)
 
Datum ltree_to_plpython (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Macro Definition Documentation

◆ PLyUnicode_FromStringAndSize

#define PLyUnicode_FromStringAndSize   PLyUnicode_FromStringAndSize_p

Definition at line 35 of file ltree_plpython.c.

Referenced by _PG_init().

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 22 of file ltree_plpython.c.

References AssertVariableIsOfType, load_external_function(), and PLyUnicode_FromStringAndSize.

23 {
24  /* Asserts verify that typedefs above match original declarations */
25 #if PY_MAJOR_VERSION >= 3
26  AssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
27  PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
28  load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
29  true, NULL);
30 #endif
31 }
#define PLyUnicode_FromStringAndSize
PGFunction load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:94
#define AssertVariableIsOfType(varname, typename)
Definition: c.h:789

◆ ltree_to_plpython()

Datum ltree_to_plpython ( PG_FUNCTION_ARGS  )

Definition at line 41 of file ltree_plpython.c.

References ereport, errcode(), errmsg(), ERROR, i, ltree_level::len, LEVEL_NEXT, sort-test::list, LTREE_FIRST, ltree_level::name, ltree::numlevel, PG_FREE_IF_COPY, PG_GETARG_LTREE_P, and PointerGetDatum.

42 {
43  ltree *in = PG_GETARG_LTREE_P(0);
44  int i;
45  PyObject *list;
46  ltree_level *curlevel;
47 
48  list = PyList_New(in->numlevel);
49  if (!list)
50  ereport(ERROR,
51  (errcode(ERRCODE_OUT_OF_MEMORY),
52  errmsg("out of memory")));
53 
54  curlevel = LTREE_FIRST(in);
55  for (i = 0; i < in->numlevel; i++)
56  {
57  PyList_SetItem(list, i, PyString_FromStringAndSize(curlevel->name, curlevel->len));
58  curlevel = LEVEL_NEXT(curlevel);
59  }
60 
61  PG_FREE_IF_COPY(in, 0);
62 
63  return PointerGetDatum(list);
64 }
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: ltree.h:13
uint16 len
Definition: ltree.h:12
#define PointerGetDatum(X)
Definition: postgres.h:562
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:171
#define ERROR
Definition: elog.h:43
#define LEVEL_NEXT(x)
Definition: ltree.h:17
#define ereport(elevel, rest)
Definition: elog.h:122
Definition: ltree.h:19
uint16 numlevel
Definition: ltree.h:22
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define LTREE_FIRST(x)
Definition: ltree.h:27
int i

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( ltree_to_plpython  )

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 7 of file ltree_plpython.c.