git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/8] pkt-line: remove buffer arg from write_packetized_from_fd_no_flush()

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 4, 2021, 22:55 UTC
Message-ID
<xmqqh7lqcywi.fsf@gitster.c.googlers.com>
In-Reply-To
<d6ea7688dfb2536312b627f7ed47ff7f42091f60.1614889047.git.gitgitgadget@gmail.com>
"Jeff Hostetler via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 16 quoted lines
> From: Jeff Hostetler <jeffhost@microsoft.com>
>
> Remove the scratch buffer argument from `write_packetized_from_fd_no_flush()`
> and allocate a temporary buffer within the function.
>
> In 3e4447f1ea (pkt-line: eliminate the need for static buffer in
> packet_write_gently(), 2021-02-13) we added the argument in order to
> get rid of a static buffer to make the routine safe in multi-threaded
> contexts and to avoid putting a very large buffer on the stack.  This
> delegated the problem to the caller who has more knowledge of the use
> case and can best decide the most efficient way to provide such a
> buffer.
>
> However, in practice, the (currently, only) caller just created the
> buffer on the stack, so we might as well just allocate it within the
> function and restore the original API.

Hmph, I would have expected, since we already have changed the callchain to pass the buffer down, that we'd keep the structure and update the caller to heap-allocate, but I think I like the result of this patch better. It's not like the caller can allocate and reuse a single buffer with repeated calls to the function; rather, the caller makes a single call that results in relaying many bytes by the helper, all done in a loop, and it is sufficient for the helper to allocate/deallocate outside of its loop to reuse the buffer.

Previous: Jeff Hostetler via GitGitGadgetNext: Jeff Hostetler via GitGitGadget
Message 12 of 15 in “Simple IPC Cleanups”
  1. 0/8 Simple IPC CleanupsJeff Hostetler via GitGitGadget, Mar 4, 2021
  2. 6/8 test-simple-ipc: refactor command line option processing in helperJeff Hostetler via GitGitGadget, Mar 4, 2021
  3. 7/8 test-simple-ipc: add --token=<token> string optionJeff Hostetler via GitGitGadget, Mar 4, 2021
  4. 4/8 simple-ipc: move error handling up a levelJeff Hostetler via GitGitGadget, Mar 4, 2021
  5. 2/8 unix-socket: simplify initialization of unix_stream_listen_optsJeff Hostetler via GitGitGadget, Mar 4, 2021
  6. Junio C HamanoMar 4, 2021
  7. 3/8 unix-stream-server: create unix-stream-server.cJeff Hostetler via GitGitGadget, Mar 4, 2021
  8. 5/8 unix-stream-server: add st_dev and st_mode to socket stolen checksJeff Hostetler via GitGitGadget, Mar 4, 2021
  9. René ScharfeMar 6, 2021
  10. Jeff HostetlerMar 8, 2021
  11. 1/8 pkt-line: remove buffer arg from write_packetized_from_fd_no_flush()Jeff Hostetler via GitGitGadget, Mar 4, 2021
  12. Junio C HamanoMar 4, 2021
  13. 8/8 simple-ipc: update design documentation with more detailsJeff Hostetler via GitGitGadget, Mar 4, 2021
  14. Junio C HamanoMar 5, 2021
  15. Jeff HostetlerMar 5, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.