commit 3177286ef8ef4a0c7d77e421b71b85658ca00e1d
Author: Devrim Gunduz <devrim@gunduz.org>
Date:   Mon Oct 12 15:45:59 2026 +0300

    Fix build against PostgreSQL 19
    
      plprofiler.h:
      * PG19's header include-what-you-use (IWYU) cleanup means
        <storage/lwlock.h>, <storage/shmem.h> and <utils/tuplestore.h>
        are no longer pulled in transitively by the headers plprofiler.h
        already included. Without them, LW_SHARED/LW_EXCLUSIVE, the
        LWLock and shmem functions, and tuplestore_begin_heap/
        tuplestore_putvalues are undeclared. Add the three includes.
      * Declare profilerSharedState.lock as "LWLock *" instead of the
        "LWLockId" compatibility typedef, which is just "LWLock *" since
        PostgreSQL 9.4. No functional change.
    
      plprofiler.c:
      * PG19 changed the signature of ShmemInitHash() from
          HTAB *ShmemInitHash(const char *name, long init_size,
                              long max_size, HASHCTL *infoP,
                              int hash_flags);
        to
          HTAB *ShmemInitHash(const char *name, int64 nelems,
                              HASHCTL *infoP, int hash_flags);
        Pass the separate init_size argument only for PG_VERSION_NUM <
        190000 at both call sites in profiler_shmem_startup(), so the
        extension keeps building against older releases.
    
    Tested: builds cleanly against PostgreSQL 13-18 and 19beta4; on
    19beta4 local and global (shared memory) profiling, collect_data
    and reset_shared work as expected.
    
    Supersedes #27, which broke the build on PostgreSQL 18 and older.
    
    Hacked by Claude, tested by me.

diff --git a/plprofiler.c b/plprofiler.c
index 24a39eb..726396f 100755
--- a/plprofiler.c
+++ b/plprofiler.c
@@ -681,7 +681,9 @@ profiler_shmem_startup(void)
 	hash_ctl.hash = line_hash_fn;
 	hash_ctl.match = line_match_fn;
 	functions_shared = ShmemInitHash("plprofiler functions",
+#if PG_VERSION_NUM < 190000
 									 profiler_max_functions,
+#endif
 									 profiler_max_functions,
 									 &hash_ctl,
 									 HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
@@ -693,7 +695,9 @@ profiler_shmem_startup(void)
 	hash_ctl.hash = callgraph_hash_fn;
 	hash_ctl.match = callgraph_match_fn;
 	callgraph_shared = ShmemInitHash("plprofiler callgraph",
+#if PG_VERSION_NUM < 190000
 									  profiler_max_callgraph,
+#endif
 									  profiler_max_callgraph,
 									  &hash_ctl,
 									  HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
diff --git a/plprofiler.h b/plprofiler.h
index 8158454..8ac4d49 100644
--- a/plprofiler.h
+++ b/plprofiler.h
@@ -40,6 +40,8 @@
 #include "pgstat.h"
 #include "plpgsql.h"
 #include "storage/ipc.h"
+#include "storage/lwlock.h"
+#include "storage/shmem.h"
 #include "storage/spin.h"
 #include "utils/array.h"
 #include "utils/builtins.h"
@@ -49,6 +51,7 @@
 #include "utils/memutils.h"
 #include "utils/palloc.h"
 #include "utils/syscache.h"
+#include "utils/tuplestore.h"
 
 PG_MODULE_MAGIC;
 
@@ -161,7 +164,7 @@ typedef struct callGraphEntry
 
 typedef struct
 {
-	LWLockId			lock;
+	LWLock			   *lock;
 	bool				profiler_enabled_global;
 	int					profiler_enabled_pid;
 	int					profiler_collect_interval;
