PostgreSQL Source Code
git master
ltree_plpython.c
Go to the documentation of this file.
1
#include "
postgres.h
"
2
3
#include "
fmgr.h
"
4
#include "
ltree/ltree.h
"
5
#include "
plpython.h
"
6
7
PG_MODULE_MAGIC
;
8
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
;
12
13
14
/*
15
* Module initialize function: fetch function pointers for cross-module calls.
16
*/
17
void
18
_PG_init
(
void
)
19
{
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);
25
}
26
27
28
/* These defines must be after the module init function */
29
#define PLyUnicode_FromStringAndSize PLyUnicode_FromStringAndSize_p
30
31
32
PG_FUNCTION_INFO_V1
(
ltree_to_plpython
);
33
34
Datum
35
ltree_to_plpython
(
PG_FUNCTION_ARGS
)
36
{
37
ltree
*in =
PG_GETARG_LTREE_P
(0);
38
int
i
;
39
PyObject *
list
;
40
ltree_level
*curlevel;
41
42
list
= PyList_New(in->
numlevel
);
43
if
(!
list
)
44
ereport
(
ERROR
,
45
(
errcode
(ERRCODE_OUT_OF_MEMORY),
46
errmsg
(
"out of memory"
)));
47
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
}
54
55
PG_FREE_IF_COPY
(in, 0);
56
57
return
PointerGetDatum
(
list
);
58
}
AssertVariableIsOfType
#define AssertVariableIsOfType(varname, typename)
Definition:
c.h:972
load_external_function
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition:
dfmgr.c:105
errcode
int errcode(int sqlerrcode)
Definition:
elog.c:853
errmsg
int errmsg(const char *fmt,...)
Definition:
elog.c:1070
ERROR
#define ERROR
Definition:
elog.h:39
ereport
#define ereport(elevel,...)
Definition:
elog.h:149
fmgr.h
PG_FREE_IF_COPY
#define PG_FREE_IF_COPY(ptr, n)
Definition:
fmgr.h:260
PG_FUNCTION_ARGS
#define PG_FUNCTION_ARGS
Definition:
fmgr.h:193
i
int i
Definition:
isn.c:73
ltree.h
LTREE_FIRST
#define LTREE_FIRST(x)
Definition:
ltree.h:51
LEVEL_NEXT
#define LEVEL_NEXT(x)
Definition:
ltree.h:40
PG_GETARG_LTREE_P
#define PG_GETARG_LTREE_P(n)
Definition:
ltree.h:218
PLyUnicode_FromStringAndSize
#define PLyUnicode_FromStringAndSize
Definition:
ltree_plpython.c:29
_PG_init
void _PG_init(void)
Definition:
ltree_plpython.c:18
PLyUnicode_FromStringAndSize_t
PyObject *(* PLyUnicode_FromStringAndSize_t)(const char *s, Py_ssize_t size)
Definition:
ltree_plpython.c:10
PG_MODULE_MAGIC
PG_MODULE_MAGIC
Definition:
ltree_plpython.c:7
PLyUnicode_FromStringAndSize_p
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p
Definition:
ltree_plpython.c:11
ltree_to_plpython
Datum ltree_to_plpython(PG_FUNCTION_ARGS)
Definition:
ltree_plpython.c:35
PG_FUNCTION_INFO_V1
PG_FUNCTION_INFO_V1(ltree_to_plpython)
sort-test.list
list
Definition:
sort-test.py:13
plpython.h
postgres.h
PointerGetDatum
static Datum PointerGetDatum(const void *X)
Definition:
postgres.h:322
Datum
uintptr_t Datum
Definition:
postgres.h:64
size
static pg_noinline void Size size
Definition:
slab.c:607
ltree_level
Definition:
ltree.h:34
ltree_level::name
char name[FLEXIBLE_ARRAY_MEMBER]
Definition:
ltree.h:36
ltree_level::len
uint16 len
Definition:
ltree.h:35
ltree
Definition:
ltree.h:43
ltree::numlevel
uint16 numlevel
Definition:
ltree.h:45
contrib
ltree_plpython
ltree_plpython.c
Generated on Wed Oct 16 2024 00:13:14 for PostgreSQL Source Code by
1.9.1