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

Re: [PATCH v2] Refactor recv_sideband()

From
Lukas Fleischer <lfleischer@lfos.de>
Date
Jun 27, 2016, 20:34 UTC
Message-ID
<146705966655.11886.6547584744094511110@typhoon>
In-Reply-To
<xmqqbn2mbjxm.fsf@gitster.mtv.corp.google.com>
On Mon, 27 Jun 2016 at 19:50:13, Junio C Hamano wrote:
Show 7 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > On Mon, Jun 27, 2016 at 08:54:22AM -0700, Junio C Hamano wrote:
> >
> >> It's just you used xwrite() there that introduced a different issue.
> >> Wouldn't replacing it with fwrite(stderr) without changing anything
> >> else solve that?

I do not see how using fwrite() buys us anything. Neither fwrite() nor fputs() nor fprintf() guarantee to call write() only once. Each of these three functions is buffered when printing to stdout and unbuffered when printing to stderr. I do not think there is any serious implementation of any of those functions that performs segmented write() calls (but I might be mistaken). According to POSIX, write() can take up to SSIZE_MAX bytes which is guaranteed to be at least 32767 but is actually much larger on most systems (2^32 - 1 here). It is very unlikely that this limit will ever be reached by a single line of a diagnostic error message.

Frankly, there is a small benefit to fwrite() because we already know the string length from the strbuf and most fputs() implementations probably do something equivalent to

    fwrite(s, 1, strlen(s), stream);

I can switch to using fwrite() instead of fputs() in v4 if you prefer that.

Show 9 quoted lines
> >
> > I am having trouble actually seeing how the ANSI-emulation code gets
> > triggered, but the comment in color.h implies that it is only printf,
> > fprintf, and fputs that have the desired effect. So fwrite() may not be
> > sufficient, and we may need fprintf("%.*s", len, buf) or something.
> 
> I have no idea how, either X-<.  But you're probably right about the
> magic being limited to the printf family of functions---I do recall
> hearing something like that in the past.

I do not know anything about the emulation code as well but from a cursory read of winansi_init(), it looks like there is some magic that hooks into the stdout and stderr streams, redirects them to a named pipe, then replaces ANSI control codes and actually prints to the console from console_thread(). So it should work with any of the stream-based functions but not with write(), puts(), etc.

Previous: Junio C HamanoNext: Nicolas Pitre
Message 19 of 60 in “Refactor recv_sideband()”
  1. Refactor recv_sideband()Lukas Fleischer, Jun 13, 2016
  2. Nicolas PitreJun 13, 2016
  3. Johannes SchindelinJun 14, 2016
  4. Nicolas PitreJun 14, 2016
  5. Johannes SchindelinJun 14, 2016
  6. Nicolas PitreJun 14, 2016
  7. Refactor recv_sideband()Lukas Fleischer, Jun 14, 2016
  8. Lukas FleischerJun 14, 2016
  9. Junio C HamanoJun 14, 2016
  10. Jeff KingJun 15, 2016
  11. Jeff KingJun 24, 2016
  12. Johannes SchindelinJun 24, 2016
  13. Jeff KingJun 24, 2016
  14. Junio C HamanoJun 24, 2016
  15. Lukas FleischerJun 27, 2016
  16. Junio C HamanoJun 27, 2016
  17. Jeff KingJun 27, 2016
  18. Junio C HamanoJun 27, 2016
  19. Lukas FleischerJun 27, 2016
  20. Nicolas PitreJun 27, 2016
  21. Lukas FleischerJun 28, 2016
  22. Junio C HamanoJun 28, 2016
  23. Johannes SchindelinJun 28, 2016
  24. Johannes SchindelinJun 28, 2016
  25. Junio C HamanoJun 28, 2016
  26. Johannes SchindelinJun 28, 2016
  27. Dennis KaarsemakerJun 24, 2016
  28. Refactor recv_sideband()Lukas Fleischer, Jun 22, 2016
  29. Nicolas PitreJun 22, 2016
  30. Nicolas PitreJun 22, 2016
  31. Lukas FleischerJun 23, 2016
  32. Nicolas PitreJun 23, 2016
  33. Refactor recv_sideband()Lukas Fleischer, Jun 28, 2016
  34. Junio C HamanoJun 28, 2016
  35. Junio C HamanoJun 28, 2016
  36. Nicolas PitreJun 28, 2016
  37. Junio C HamanoJun 28, 2016
  38. Nicolas PitreJun 28, 2016
  39. Junio C HamanoJun 28, 2016
  40. Nicolas PitreJun 28, 2016
  41. Junio C HamanoJun 28, 2016
  42. Nicolas PitreJun 28, 2016
  43. Junio C HamanoJun 28, 2016
  44. Junio C HamanoJun 28, 2016
  45. Junio C HamanoJun 29, 2016
  46. Nicolas PitreJun 29, 2016
  47. Nicolas PitreJun 29, 2016
  48. Junio C HamanoJun 29, 2016
  49. Lukas FleischerJun 30, 2016
  50. Junio C HamanoJul 1, 2016
  51. Nicolas PitreJul 5, 2016
  52. Junio C HamanoJul 6, 2016
  53. Nicolas PitreJul 7, 2016
  54. Nicolas PitreJun 14, 2016
  55. Nicolas PitreJun 14, 2016
  56. Junio C HamanoJun 14, 2016
  57. Lukas FleischerJun 14, 2016
  58. Junio C HamanoJun 14, 2016
  59. Nicolas PitreJun 14, 2016
  60. Lukas FleischerJun 19, 2016

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.