> fair point. In that case why don't we just keep: I did something similar, but using a simple pointer comparison instead of strings, to avoid a warning about discarding const qualifiers.
What do you think about this version?
+void *sample_arg_ptr = &tdr_dsm;
+
static void
-init_tdr_dsm(void *ptr)
+init_tdr_dsm(void *ptr, void *arg)
{
TestDSMRegistryStruct *dsm = (TestDSMRegistryStruct *) ptr;
- LWLockInitialize(&dsm->lck, LWLockNewTrancheId("test_dsm_registry"));
+ if (arg != sample_arg_ptr)
+ ereport(ERROR,
+ (errmsg("Unexpected arg pointer address")));
+
+ LWLockInitialize(&dsm->lck,
LWLockNewTrancheId("test_dsm_registry_dsm"));
dsm->val = 0;
}
On Fri, Dec 12, 2025 at 8:57 PM Sami Imseih <[email protected]> wrote:
>
> > On Fri, Dec 12, 2025 at 12:48:52PM -0600, Sami Imseih wrote:
> > > As far as testing, I did not think it's worth it since in the cases out
> > > there now a NULL void * will result in an error when calling
> > > LWLockNewTrancheId.
> >
> > I think we should pass NULL to all the existing in-tree calls to
> > GetNamedDSMSegment(), except for perhaps a new test in test_dsm_registry
> > that verifies the pointer value in the initialization function. In all the
> > other cases, there's no issue with hard-coding the tranche names, so we can
> > keep those simple.
>
> fair point. In that case why don't we just keep:
>
> ```
> static void
> -init_tdr_dsm(void *ptr)
> +init_tdr_dsm(void *ptr, void *arg)
> {
> TestDSMRegistryStruct *dsm = (TestDSMRegistryStruct *) ptr;
>
> - LWLockInitialize(&dsm->lck, LWLockNewTrancheId("test_dsm_registry"));
> + LWLockInitialize(&dsm->lck, LWLockNewTrancheId((char *) arg));
> dsm->val = 0;
> }
>
> @@ -60,6 +60,7 @@ tdr_attach_shmem(void)
> tdr_dsm = GetNamedDSMSegment("test_dsm_registry_dsm",
>
> sizeof(TestDSMRegistryStruct),
> init_tdr_dsm,
> +
> "test_dsm_registry",
> &found);
>
> if (tdr_dsa == NULL)
> ```
>
> instead of creating a new test? For the other GetNamedDSMSegment
> calls, I'll pass
> NULL to the void * and hard code the tranche name in the init callback.
>
> --
> Sami Imseih
> Amazon Web Services (AWS)
>
v6-0001-Add-init_callback_arg-parameter-to-GetNamedDSMSegmen.patch
Description: Binary data
