mirror of
https://github.com/postgres/postgres.git
synced 2025-04-20 00:42:27 +03:00
It seems potentially useful to label our shared libraries with version information, now that a facility exists for retrieving that. This patch labels them with the PG_VERSION string. There was some discussion about using semantic versioning conventions, but that doesn't seem terribly helpful for modules with no SQL-level presence; and for those that do have SQL objects, we typically expect them to support multiple revisions of the SQL definitions, so it'd still not be very helpful. I did not label any of src/test/modules/. It seems unnecessary since we don't install those, and besides there ought to be someplace that still provides test coverage for the original PG_MODULE_MAGIC macro. Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/dd4d1b59-d0fe-49d5-b28f-1e463b68fa32@gmail.com
62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
#include "postgres.h"
|
|
|
|
#include "fmgr.h"
|
|
#include "ltree/ltree.h"
|
|
#include "plpython.h"
|
|
|
|
PG_MODULE_MAGIC_EXT(
|
|
.name = "ltree_plpython",
|
|
.version = PG_VERSION
|
|
);
|
|
|
|
/* Linkage to functions in plpython module */
|
|
typedef PyObject *(*PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size);
|
|
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
|
|
|
|
|
|
/*
|
|
* Module initialize function: fetch function pointers for cross-module calls.
|
|
*/
|
|
void
|
|
_PG_init(void)
|
|
{
|
|
/* Asserts verify that typedefs above match original declarations */
|
|
AssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
|
|
PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
|
|
load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
|
|
true, NULL);
|
|
}
|
|
|
|
|
|
/* 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, PLyUnicode_FromStringAndSize(curlevel->name, curlevel->len));
|
|
curlevel = LEVEL_NEXT(curlevel);
|
|
}
|
|
|
|
PG_FREE_IF_COPY(in, 0);
|
|
|
|
return PointerGetDatum(list);
|
|
}
|