On Wed, Dec 17, 2025 at 08:03:36AM +0100, Peter Eisentraut wrote: > So it seems to me that either the callbacks API needs some adjustments, or > this particular implementation of the callback function is incorrect.
Hmm, you are right that this is not aligned. This can be improved with one change for each callback: - It is OK with from_serialized_data() to manipulate the header data, because we want to fill a portion of the shmem data with extra data read from disk (the module wants to add a reference to a DSA stored in the shmem entry, read from the second file). So we should discard the const marker from the callback definition. - The const usage is OK for to_serialized_data(): it is better to encourage a policy where the header data cannot be manipulated. So the const needs to be kept in the definition, but I also think that we should change the module implementation so as the cast to PgStatShared_CustomVarEntry is a const. These changes result in the attached. Sami, what do you think? -- Michael
diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat_internal.h
index 5c1ce4d3d6af..01db3b701bdf 100644
--- a/src/include/utils/pgstat_internal.h
+++ b/src/include/utils/pgstat_internal.h
@@ -335,7 +335,7 @@ typedef struct PgStat_KindInfo
const PgStatShared_Common *header,
FILE *statfile);
bool (*from_serialized_data) (const PgStat_HashKey *key,
- const PgStatShared_Common *header,
+ PgStatShared_Common *header,
FILE *statfile);
/*
diff --git a/src/test/modules/test_custom_stats/test_custom_var_stats.c b/src/test/modules/test_custom_stats/test_custom_var_stats.c
index c71922dc4a8f..3dea38e3fe83 100644
--- a/src/test/modules/test_custom_stats/test_custom_var_stats.c
+++ b/src/test/modules/test_custom_stats/test_custom_var_stats.c
@@ -92,7 +92,7 @@ static void test_custom_stats_var_to_serialized_data(const PgStat_HashKey *key,
/* Deserialization callback: read auxiliary entry data */
static bool test_custom_stats_var_from_serialized_data(const PgStat_HashKey *key,
- const PgStatShared_Common *header,
+ PgStatShared_Common *header,
FILE *statfile);
/* Finish callback: end of statistics file operations */
@@ -196,9 +196,10 @@ test_custom_stats_var_to_serialized_data(const PgStat_HashKey *key,
{
char *description;
size_t len;
- PgStatShared_CustomVarEntry *entry = (PgStatShared_CustomVarEntry *) header;
bool found;
uint32 magic_number = TEST_CUSTOM_VAR_MAGIC_NUMBER;
+ const PgStatShared_CustomVarEntry *entry =
+ (const PgStatShared_CustomVarEntry *) header;
/*
* First mark the main file with a magic number, keeping a trace that some
@@ -276,7 +277,7 @@ test_custom_stats_var_to_serialized_data(const PgStat_HashKey *key,
*/
static bool
test_custom_stats_var_from_serialized_data(const PgStat_HashKey *key,
- const PgStatShared_Common *header,
+ PgStatShared_Common *header,
FILE *statfile)
{
PgStatShared_CustomVarEntry *entry;
signature.asc
Description: PGP signature
