postgres-github.git / summary / log / commit / refs

commit    d65995cbc6e1644b5514d28f07c89f68fa690e53
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Fri Apr 17 19:14:40 2026 +0000

    Change PointerGetDatum() back to a macro
    
    The argument was marked as "const void *X", but that might rightly
    give the compiler the idea that *X cannot be modified through the
    resulting Datum, and make incorrect optimizations based on that. Some
    functions use pointer Datums to pass output arguments, like GIN
    support functions. Coverity started to complain after commit
    6f5ad00ab7 that there's dead code in ginExtractEntries(), because it
    didn't see that it passes PointerGetDatum(&nentries) to a function
    that sets it.
    
    This issue goes back to commit c8b2ef05f481 (version 16), which
    changed PointerGetDatum() from a macro to a static inline function.
    This commit changes it back to a macro, but uses a trick with a dummy
    conditional expression to still produce a compiler error if you try to
    pass a non-pointer as the argument.
    
    Even though this goes back to v16, I'm only committing this to
    'master' for now, to verify that this silences the Coverity warning.
    If this works, we might want to introduce separate const and non-const
    versions of PointerGetDatum() instead of this, but that's a bigger
    patch.  It's also not decided yet whether to back-patch this (or some
    other fix), given that we haven't yet seen any hard evidence of
    compilers actually producing buggy code because of this.
    
    Discussion: https://www.postgresql.org/message-id/342012.1776017102@sss.pgh.pa.us

[parent: 4321dcad475b]