diff --git a/include/pgduckdb/pgduckdb.h b/include/pgduckdb/pgduckdb.h index 6173cf0a..041e0d07 100644 --- a/include/pgduckdb/pgduckdb.h +++ b/include/pgduckdb/pgduckdb.h @@ -7,8 +7,21 @@ typedef enum { MOTHERDUCK_AUTO, } MotherDuckEnabled; -// pgduckdb.c +// pgduckdb.cpp extern "C" void _PG_init(void); -// pgduckdb_hooks.c -void DuckdbInitHooks(void); +void DuckdbInitGUC(); + +// pgduckdb_hooks.cpp +void DuckdbInitHooks(); + +// pgduckdb_node.cpp +void DuckdbInitNode(); + +// pgduckdb_background_worker.cpp +void DuckdbInitBackgroundWorker(); + +namespace pgduckdb { +// pgduckdb_xact.cpp +void RegisterDuckdbXactCallback(); +} // namespace pgduckdb diff --git a/include/pgduckdb/pgduckdb_background_worker.hpp b/include/pgduckdb/pgduckdb_background_worker.hpp index f6ab19c7..fc21ca71 100644 --- a/include/pgduckdb/pgduckdb_background_worker.hpp +++ b/include/pgduckdb/pgduckdb_background_worker.hpp @@ -1,7 +1,5 @@ #pragma once -void DuckdbInitBackgroundWorker(void); - namespace pgduckdb { void SyncMotherDuckCatalogsWithPg(bool drop_with_cascade); diff --git a/include/pgduckdb/pgduckdb_node.hpp b/include/pgduckdb/pgduckdb_node.hpp index 7a97b2d2..b3d2fc85 100644 --- a/include/pgduckdb/pgduckdb_node.hpp +++ b/include/pgduckdb/pgduckdb_node.hpp @@ -6,4 +6,3 @@ extern "C" { } extern CustomScanMethods duckdb_scan_scan_methods; -extern "C" void DuckdbInitNode(void); diff --git a/include/pgduckdb/pgduckdb_xact.hpp b/include/pgduckdb/pgduckdb_xact.hpp index 10fdad50..0c1f741b 100644 --- a/include/pgduckdb/pgduckdb_xact.hpp +++ b/include/pgduckdb/pgduckdb_xact.hpp @@ -6,7 +6,6 @@ void PreventInTransactionBlock(const char *statement_type); } // namespace pg void ClaimCurrentCommandId(); -void RegisterDuckdbXactCallback(); void AutocommitSingleStatementQueries(); void MarkStatementNotTopLevel(); } // namespace pgduckdb diff --git a/src/pgduckdb.cpp b/src/pgduckdb.cpp index f914ac2a..1fabeab6 100644 --- a/src/pgduckdb.cpp +++ b/src/pgduckdb.cpp @@ -1,4 +1,6 @@ -#include "duckdb.hpp" +#include "pgduckdb/pgduckdb.h" + +#include extern "C" { #include "postgres.h" @@ -6,13 +8,6 @@ extern "C" { #include "utils/guc.h" } -#include "pgduckdb/pgduckdb.h" -#include "pgduckdb/pgduckdb_node.hpp" -#include "pgduckdb/pgduckdb_background_worker.hpp" -#include "pgduckdb/pgduckdb_xact.hpp" - -static void DuckdbInitGUC(void); - bool duckdb_force_execution = false; int duckdb_max_threads_per_postgres_scan = 1; int duckdb_motherduck_enabled = MotherDuckEnabled::MOTHERDUCK_AUTO; @@ -99,6 +94,7 @@ DefineCustomVariable(const char *name, const char *short_desc, T *var, T min, T } else { static_assert("Unsupported type"); } + func(name, gettext_noop(short_desc), NULL, var, *var, min, max, context, flags, check_hook, assign_hook, show_hook); } @@ -122,8 +118,8 @@ static const struct config_enum_entry motherduck_enabled_options[] = { }; /* clang-format on */ -static void -DuckdbInitGUC(void) { +void +DuckdbInitGUC() { DefineCustomVariable("duckdb.force_execution", "Force queries to use DuckDB execution", &duckdb_force_execution); DefineCustomVariable("duckdb.enable_external_access", "Allow the DuckDB to access external state.", diff --git a/src/pgduckdb_background_worker.cpp b/src/pgduckdb_background_worker.cpp index 49a00422..11c76c8b 100644 --- a/src/pgduckdb_background_worker.cpp +++ b/src/pgduckdb_background_worker.cpp @@ -125,7 +125,7 @@ force_motherduck_sync(PG_FUNCTION_ARGS) { } void -DuckdbInitBackgroundWorker(void) { +DuckdbInitBackgroundWorker() { if (!pgduckdb::IsMotherDuckEnabledAnywhere()) { return; } diff --git a/src/pgduckdb_hooks.cpp b/src/pgduckdb_hooks.cpp index 6936edbe..9fb88b13 100644 --- a/src/pgduckdb_hooks.cpp +++ b/src/pgduckdb_hooks.cpp @@ -256,11 +256,7 @@ IsDuckdbPlan(PlannedStmt *stmt) { } CustomScan *custom_scan = castNode(CustomScan, plan); - if (custom_scan->methods != &duckdb_scan_scan_methods) { - return false; - } - - return true; + return custom_scan->methods == &duckdb_scan_scan_methods; } /* diff --git a/src/pgduckdb_node.cpp b/src/pgduckdb_node.cpp index 355c2c89..838d4755 100644 --- a/src/pgduckdb_node.cpp +++ b/src/pgduckdb_node.cpp @@ -265,7 +265,7 @@ Duckdb_ExplainCustomScan(CustomScanState *node, List * /*ancestors*/, ExplainSta InvokeCPPFunc(Duckdb_ExplainCustomScan_Cpp, node, es); } -extern "C" void +void DuckdbInitNode() { /* setup scan methods */ memset(&duckdb_scan_scan_methods, 0, sizeof(duckdb_scan_scan_methods));