Thread

  1. Don't cast away const where possible

    Bertrand Drouvot <bertranddrouvot.pg@gmail.com> — 2025-12-18T13:55:23Z

    Hi hackers,
    
    Some functions are casting away the const qualifiers from their signatures in
    local variables.
    
    These 3 patches add const to read only local variables, preserving the const
    qualifiers from the function signatures.
    
    0001: those are simple changes in 6 files (16 changes in total)
    
    0002: Add const to read only TableInfo pointers in pg_dump
    
    Functions that dump table data receive their parameters through const void *
    but were casting away const. Add const qualifiers to functions that only read
    the table information.
    
    Also change getRootTableInfo to return const TableInfo *, since it only traverses
    the parent chain without modifying any TableInfo structures. This allows the dump
    functions to maintain const correctness when calling it.
    
    0003: Separate read and write pointers in pg_saslprep
    
    Use separate pointers for reading const input ('p') and writing
    to mutable output ('outp'), avoiding the need to cast away const on the input
    parameter.
    
    It has been done with the help of [1], but not all the changes proposed by it have
    been implemented. Indeed, I did some filtering and decided not to change the ones
    that:
    
    - are just thin wrappers
    - would require public API changes
    - rely on external functions (such as LZ4F_compressUpdate())
    - would require changes beyond the scope of this cleanup
    
    [1]: https://github.com/bdrouvot/coccinelle_on_pg/blob/main/misc/search_const_away.cocci
    
    Thoughts?
    
    Regards,
    
    -- 
    Bertrand Drouvot
    PostgreSQL Contributors Team
    RDS Open Source Databases
    Amazon Web Services: https://aws.amazon.com