Add data for WAL in pg_stat_io and backend statistics
[pgsql.git] / contrib / ltree_plpython / ltree_plpython.c
blobac159ea31415c772f9d750fcbe08005eacce71a1
1 #include "postgres.h"
3 #include "fmgr.h"
4 #include "ltree/ltree.h"
5 #include "plpython.h"
7 PG_MODULE_MAGIC;
9 /* Linkage to functions in plpython module */
10 typedef PyObject *(*PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size);
11 static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
15 * Module initialize function: fetch function pointers for cross-module calls.
17 void
18 _PG_init(void)
20 /* Asserts verify that typedefs above match original declarations */
21 AssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
22 PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
23 load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
24 true, NULL);
28 /* These defines must be after the module init function */
29 #define PLyUnicode_FromStringAndSize PLyUnicode_FromStringAndSize_p
32 PG_FUNCTION_INFO_V1(ltree_to_plpython);
34 Datum
35 ltree_to_plpython(PG_FUNCTION_ARGS)
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++)
51 PyList_SetItem(list, i, PLyUnicode_FromStringAndSize(curlevel->name, curlevel->len));
52 curlevel = LEVEL_NEXT(curlevel);
55 PG_FREE_IF_COPY(in, 0);
57 return PointerGetDatum(list);