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

Go to the source code of this file.


#define PLyUnicode_FromStringAndSize   PLyUnicode_FromStringAndSize_p


typedef PyObject *(* PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size)


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


static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p

Macro Definition Documentation

◆ PLyUnicode_FromStringAndSize

#define PLyUnicode_FromStringAndSize   PLyUnicode_FromStringAndSize_p

Definition at line 29 of file ltree_plpython.c.

Typedef Documentation

◆ PLyUnicode_FromStringAndSize_t

typedef PyObject*(* PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size)

Definition at line 10 of file ltree_plpython.c.

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 18 of file ltree_plpython.c.

19 {
20  /* Asserts verify that typedefs above match original declarations */
23  load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
24  true, NULL);
25 }
#define AssertVariableIsOfType(varname, typename)
Definition: c.h:981
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:105
#define PLyUnicode_FromStringAndSize
PyObject *(* PLyUnicode_FromStringAndSize_t)(const char *s, Py_ssize_t size)
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p

References AssertVariableIsOfType, load_external_function(), PLyUnicode_FromStringAndSize, and PLyUnicode_FromStringAndSize_p.

◆ ltree_to_plpython()

Datum ltree_to_plpython ( PG_FUNCTION_ARGS  )

Definition at line 35 of file ltree_plpython.c.

36 {
37  ltree *in = PG_GETARG_LTREE_P(0);
38  int i;
39  PyObject *list;
40  ltree_level *curlevel;
42  list = PyList_New(in->numlevel);
43  if (!list)
44  ereport(ERROR,
45  (errcode(ERRCODE_OUT_OF_MEMORY),
46  errmsg("out of memory")));
48  curlevel = LTREE_FIRST(in);
49  for (i = 0; i < in->numlevel; i++)
50  {
51  PyList_SetItem(list, i, PLyUnicode_FromStringAndSize(curlevel->name, curlevel->len));
52  curlevel = LEVEL_NEXT(curlevel);
53  }
55  PG_FREE_IF_COPY(in, 0);
57  return PointerGetDatum(list);
58 }
int errcode(int sqlerrcode)
Definition: elog.c:855
int errmsg(const char *fmt,...)
Definition: elog.c:1068
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
int i
Definition: isn.c:73
#define LTREE_FIRST(x)
Definition: ltree.h:51
#define LEVEL_NEXT(x)
Definition: ltree.h:40
#define PG_GETARG_LTREE_P(n)
Definition: ltree.h:218
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
Definition: ltree.h:36
uint16 len
Definition: ltree.h:35
Definition: ltree.h:43
uint16 numlevel
Definition: ltree.h:45

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, PLyUnicode_FromStringAndSize, and PointerGetDatum().


PG_FUNCTION_INFO_V1 ( ltree_to_plpython  )

Variable Documentation



Definition at line 7 of file ltree_plpython.c.

◆ PLyUnicode_FromStringAndSize_p

PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p

Definition at line 11 of file ltree_plpython.c.

Referenced by _PG_init().