• Tom Lane's avatar
    Change API of ShmemAlloc() so it throws error rather than returning NULL. · 6c03d981
    Tom Lane authored
    A majority of callers seem to have believed that this was the API spec
    already, because they omitted any check for a NULL result, and hence
    would crash on an out-of-shared-memory failure.  The original proposal
    was to just add such error checks everywhere, but that does nothing to
    prevent similar omissions in future.  Instead, let's make ShmemAlloc()
    throw the error (so we can remove the caller-side checks that do exist),
    and introduce a new function ShmemAllocNoError() that has the previous
    behavior of returning NULL, for the small number of callers that need
    that and are prepared to do the right thing.  This also lets us remove
    the rather wishy-washy behavior of printing a WARNING for out-of-shmem,
    which never made much sense: either the caller has a strategy for
    dealing with that, or it doesn't.  It's not ShmemAlloc's business to
    decide whether a warning is appropriate.
    
    The v10 release notes will need to call this out as a significant
    source-code change.  It's likely that it will be a bug fix for
    extension callers too, but if not, they'll need to change to using
    ShmemAllocNoError().
    
    This is nominally a bug fix, but the odds that it's fixing any live
    bug are actually rather small, because in general the requests
    being made by the unchecked callers were already accounted for in
    determining the overall shmem size, so really they ought not fail.
    Between that and the possible impact on extensions, no back-patch.
    
    Discussion: <24843.1472563085@sss.pgh.pa.us>
    6c03d981
shmem.c 14.3 KB