aboutsummaryrefslogtreecommitdiff
path: root/contrib/ltree_plpython/ltree_plpython.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ltree_plpython/ltree_plpython.c')
-rw-r--r--contrib/ltree_plpython/ltree_plpython.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/contrib/ltree_plpython/ltree_plpython.c b/contrib/ltree_plpython/ltree_plpython.c
index 26b7b3c275d..bdd462a91b9 100644
--- a/contrib/ltree_plpython/ltree_plpython.c
+++ b/contrib/ltree_plpython/ltree_plpython.c
@@ -1,10 +1,39 @@
#include "postgres.h"
+
#include "fmgr.h"
#include "plpython.h"
#include "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);