plpython.h included plpy_util.h, simply on the grounds that "it's
easier to just include it everywhere". However, plpy_util.h must
include plpython.h, or it won't pass headerscheck. While the
resulting circularity doesn't have any immediate bad effect,
it's poor design. We have seen serious messes arise in the past
from overly-broad inclusion footprints created by such circularities,
so let's establish a project policy against it.
To fix, just replace *.c files' inclusions of plpython.h with
plpy_util.h. They'll pull in plpython.h indirectly; indeed, almost
all have already done so via inclusions of other plpy_xxx.h headers.
(Any extensions using plpython.h can do likewise without breaking
the compatibility of their code with prior Postgres versions.)
Reported-by: Bertrand Drouvot <[email protected]>
Author: Tom Lane <
[email protected]>
Reviewed-by: Bertrand Drouvot <[email protected]>
Discussion: https://postgr.es/m/
[email protected]
#include "fmgr.h"
#include "hstore/hstore.h"
#include "plpy_typeio.h"
-#include "plpython.h"
+#include "plpy_util.h"
PG_MODULE_MAGIC_EXT(
.name = "hstore_plpython",
#include "plpy_elog.h"
#include "plpy_typeio.h"
-#include "plpython.h"
+#include "plpy_util.h"
#include "utils/fmgrprotos.h"
#include "utils/jsonb.h"
#include "utils/numeric.h"
#include "fmgr.h"
#include "ltree/ltree.h"
-#include "plpython.h"
+#include "plpy_util.h"
PG_MODULE_MAGIC_EXT(
.name = "ltree_plpython",
#include "plpy_planobject.h"
#include "plpy_resultobject.h"
#include "plpy_spi.h"
-#include "plpython.h"
+#include "plpy_util.h"
#include "utils/memutils.h"
static PyObject *PLy_cursor_query(const char *query);
#include "plpy_elog.h"
#include "plpy_main.h"
#include "plpy_procedure.h"
-#include "plpython.h"
+#include "plpy_util.h"
PyObject *PLy_exc_error = NULL;
PyObject *PLy_exc_fatal = NULL;
#include "plpy_main.h"
#include "plpy_procedure.h"
#include "plpy_subxactobject.h"
-#include "plpython.h"
+#include "plpy_util.h"
#include "utils/fmgrprotos.h"
#include "utils/rel.h"
#include "plpy_plpymodule.h"
#include "plpy_procedure.h"
#include "plpy_subxactobject.h"
-#include "plpython.h"
+#include "plpy_util.h"
#include "utils/guc.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "plpy_cursorobject.h"
#include "plpy_planobject.h"
#include "plpy_spi.h"
-#include "plpython.h"
+#include "plpy_util.h"
#include "utils/memutils.h"
static void PLy_plan_dealloc(PLyPlanObject *self);
#include "plpy_resultobject.h"
#include "plpy_spi.h"
#include "plpy_subxactobject.h"
-#include "plpython.h"
+#include "plpy_util.h"
#include "utils/builtins.h"
HTAB *PLy_spi_exceptions = NULL;
#include "plpy_elog.h"
#include "plpy_main.h"
#include "plpy_procedure.h"
-#include "plpython.h"
+#include "plpy_util.h"
#include "utils/builtins.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
#include "plpy_elog.h"
#include "plpy_resultobject.h"
-#include "plpython.h"
+#include "plpy_util.h"
static void PLy_result_dealloc(PLyResultObject *self);
static PyObject *PLy_result_colnames(PyObject *self, PyObject *unused);
#include "plpy_plpymodule.h"
#include "plpy_resultobject.h"
#include "plpy_spi.h"
-#include "plpython.h"
+#include "plpy_util.h"
#include "utils/memutils.h"
static PyObject *PLy_spi_execute_query(char *query, long limit);
#include "access/xact.h"
#include "plpy_elog.h"
#include "plpy_subxactobject.h"
-#include "plpython.h"
+#include "plpy_util.h"
#include "utils/memutils.h"
List *explicit_subtransactions = NIL;
#include "plpy_elog.h"
#include "plpy_main.h"
#include "plpy_typeio.h"
-#include "plpython.h"
+#include "plpy_util.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "mb/pg_wchar.h"
#include "plpy_elog.h"
#include "plpy_util.h"
-#include "plpython.h"
/*
* Convert a Python unicode object to a Python string/bytes object in
*
* plpython.h - Python as a procedural language for PostgreSQL
*
+ * Note: this file is #include'd by each of the sub-module header files
+ * (plpy_elog.h, etc). It's therefore unnecessary for any plpython *.c
+ * files to include it directly.
+ *
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
#undef TEXTDOMAIN
#define TEXTDOMAIN PG_TEXTDOMAIN("plpython")
-/*
- * Used throughout, so it's easier to just include it everywhere.
- */
-#include "plpy_util.h"
-
#endif /* PLPYTHON_H */