mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
60f6756f92
Neither plperl nor plpython installed sufficient header files to
permit transform modules to be built out-of-tree using PGXS. Fix that
by installing all plperl and plpython header files (other than those
with special purposes such as generated data tables), and also install
plpython's special .mk file for mangling regression tests.
(This commit does not fix the windows install, which does not
currently install _any_ plperl or plpython headers.)
Also fix the existing transform modules for hstore and ltree so that
their cross-module #include directives work as anticipated by commit
df163230b9
et seq. This allows them to serve as working examples of
how to reference other modules when doing separate out-of-tree builds.
Discussion: https://postgr.es/m/87o9ej8bgl.fsf%40news-spur.riddles.org.uk
65 lines
1.5 KiB
C
65 lines
1.5 KiB
C
#include "postgres.h"
|
|
|
|
#include "fmgr.h"
|
|
#include "plpython.h"
|
|
#include "ltree/ltree.h"
|
|
|
|
PG_MODULE_MAGIC;
|
|
|
|
extern void _PG_init(void);
|
|
|
|
/* Linkage to functions in plpython module */
|
|
#if PY_MAJOR_VERSION >= 3
|
|
typedef PyObject *(*PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size);
|
|
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
|
|
#endif
|
|
|
|
|
|
/*
|
|
* Module initialize function: fetch function pointers for cross-module calls.
|
|
*/
|
|
void
|
|
_PG_init(void)
|
|
{
|
|
/* Asserts verify that typedefs above match original declarations */
|
|
#if PY_MAJOR_VERSION >= 3
|
|
AssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
|
|
PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
|
|
load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
|
|
true, NULL);
|
|
#endif
|
|
}
|
|
|
|
|
|
/* These defines must be after the module init function */
|
|
#define PLyUnicode_FromStringAndSize PLyUnicode_FromStringAndSize_p
|
|
|
|
|
|
PG_FUNCTION_INFO_V1(ltree_to_plpython);
|
|
|
|
Datum
|
|
ltree_to_plpython(PG_FUNCTION_ARGS)
|
|
{
|
|
ltree *in = PG_GETARG_LTREE_P(0);
|
|
int i;
|
|
PyObject *list;
|
|
ltree_level *curlevel;
|
|
|
|
list = PyList_New(in->numlevel);
|
|
if (!list)
|
|
ereport(ERROR,
|
|
(errcode(ERRCODE_OUT_OF_MEMORY),
|
|
errmsg("out of memory")));
|
|
|
|
curlevel = LTREE_FIRST(in);
|
|
for (i = 0; i < in->numlevel; i++)
|
|
{
|
|
PyList_SetItem(list, i, PyString_FromStringAndSize(curlevel->name, curlevel->len));
|
|
curlevel = LEVEL_NEXT(curlevel);
|
|
}
|
|
|
|
PG_FREE_IF_COPY(in, 0);
|
|
|
|
return PointerGetDatum(list);
|
|
}
|