diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2016-10-04 17:49:07 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2016-10-04 17:49:07 -0400 |
commit | eda04886c1e048d695728206504ab4198462168e (patch) | |
tree | 30501f4583bd1b5ecf7dd990dd15d16a9f889b9c /contrib/ltree_plpython/ltree_plpython.c | |
parent | fc76259f5b8473dbd3d2009b0e4a267cf3a7e704 (diff) | |
download | postgresql-eda04886c1e048d695728206504ab4198462168e.tar.gz postgresql-eda04886c1e048d695728206504ab4198462168e.zip |
Avoid direct cross-module links in hstore_plperl and ltree_plpython, too.
Just turning the crank on the project started in commit d51924be8.
These cases turn out to be exact subsets of the boilerplate needed
for hstore_plpython.
Discussion: <2652.1475512158@sss.pgh.pa.us>
Diffstat (limited to 'contrib/ltree_plpython/ltree_plpython.c')
-rw-r--r-- | contrib/ltree_plpython/ltree_plpython.c | 29 |
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); |