Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop scratchbuf #239

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Drop scratchbuf #239

wants to merge 13 commits into from

Commits on Nov 15, 2024

  1. strbuf: Extract realloc

    Extract the realloc from the size calculation so it can be shared with
    other upcoming callers.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    c6c2b55 View commit details
    Browse the repository at this point in the history
  2. strbuf: Re-use buf_realloc()

    Let the realloc happen in only one place, so we can change its behavior
    in future.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    f403b54 View commit details
    Browse the repository at this point in the history
  3. strbuf: Document strbuf_popchar(s)

    Document the behavior for these functions and also clarify why the
    testsuite can check the buffer for equality after calling strbuf_str().
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    e206e42 View commit details
    Browse the repository at this point in the history
  4. strbuf: Invalidate (only) when stolen

    The main for strbuf_steal() to free() on error was to allow the caller
    to pass the NULL up the stack with just a return call to
    strbuf_steal().
    
    However this is error-prone and surprising that the buffer is still
    invalidated on error. Provide an strbuf cleanup attribute that can be
    used for the same purpose and make sure that when the string is stolen,
    it's set to NULL, so there's no dangling pointer around.
    
    Since we run the  testsuite with AddressSanitizer, a simple test can be
    added to make sure the stolen string becomes valid when the attribute is
    used.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    d789707 View commit details
    Browse the repository at this point in the history
  5. strbuf: Allow to start with stack space

    This is the main functionality of the scratchbuf implementation: it
    starts with a buffer on stack that covers most of the calls, but also
    has a fallback to allocate the buffer if it grows beyond the initial
    size.
    
    Port that functionality from scratchbuf to strbuf, so the former can be
    eventually removed.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    8979c7f View commit details
    Browse the repository at this point in the history
  6. strbuf: Add strbuf_reserve_extra()

    To accomplish the same task as scratchbuf_alloc() does: make sure the
    buffer has enough space for next operations. One difference is that
    ensures **extra** space, not the total space. If needed in future,
    a strbuf_reserve(), that resembles C++'s std::vector::reserve(), can be
    added on top.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    b90e5e8 View commit details
    Browse the repository at this point in the history
  7. strbuf: Do not append '\0' if not needed

    Unconditionally appending '\0' is not a big problem, but that does
    trigger the buffer to potentially be re-allocated. Avoid that by
    checking the last char is not already NUL.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    2d21d79 View commit details
    Browse the repository at this point in the history
  8. strbuf: Add strbuf_pushmem()

    Wrapper for memcpy(). It's similar to strbuf_pushchars(), but push any
    char, including the NUL byte, relying on the size passed as argument.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    71ce083 View commit details
    Browse the repository at this point in the history
  9. strbuf: Add strbuf_used()

    So users don't feel tempted to look at inside the strbuf. Just add a
    function for it and proper tests.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    b4d3471 View commit details
    Browse the repository at this point in the history
  10. strbuf: Add strbuf_shrink_to()

    Useful when working with paths on a loop and resetting to a base path
    component on every loop iteration.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    aa26361 View commit details
    Browse the repository at this point in the history
  11. depmod: Convert depmod_modules_search_path() to strbuf

    Replace the scratchbuf usage with corresponding API from strbuf.
    
    depmod_modules_search_path() itself may further be simplified in the
    future to share opening the dir with depmod_modules_search_dir(),
    but that is left for later.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    51875b9 View commit details
    Browse the repository at this point in the history
  12. depmod: Convert output_symbols_bin() to strbuf

    Remove last use of scratchbuf.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    9868d6c View commit details
    Browse the repository at this point in the history
  13. Remove scratchbuf implementation

    All its unique features have been ported to strbuf and users converted.
    Nuke it.
    
    Signed-off-by: Lucas De Marchi <[email protected]>
    lucasdemarchi committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    813bb1c View commit details
    Browse the repository at this point in the history