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

Re: [PATCH] pkt-line: extract out PACKET_HEADER_SIZE

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 13, 2020, 16:51 UTC
Message-ID
<xmqqimfuzz73.fsf@gitster.c.googlers.com>
In-Reply-To
<20200613142306.GA4680@danh.dev>
Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:
Show 10 quoted lines
>>  void packet_flush(int fd)
>>  {
>> -	packet_trace("0000", 4, 1);
>> -	if (write_in_full(fd, "0000", 4) < 0)
>> +	packet_trace("0000", PACKET_HEADER_SIZE, 1);
>> +	if (write_in_full(fd, "0000", PACKET_HEADER_SIZE) < 0)
>
> I think the magic number 4 is easier to follow than some macro
> PACKET_HEADER_SIZE defined elsewhere. Because reader may judge that is
> the size of "0000"

I hate to admit it immensely, but I tend to agree with you. In the context of this single call,

	write_in_full(fd, "0000", 4)
	write_in_full(fd, "0000", PACKET_HEADER_SIZE)
I find the former vastly easier.
> How about (this ugly code):
>
> 	packet_trace("0000", sizeof "0000" - 1, 1);
> 	if (write_in_full(fd, "0000", sizeof "0000" - 1) < 0)

Yeah, that is ugly. I was thinking more in the direction of replacing these three-argument write_in_full with something like

#define write_constant(fd, constant_string) \
	write_in_full((fd), (constant_string), strlen(constant_string))

with some preprocessor magic to make the compilation break when the second parameter to the macro is not a string constant.

Previous: Denton LiuNext: Junio C Hamano
Message 4 of 22 in “pkt-line: extract out PACKET_HEADER_SIZE”
  1. pkt-line: extract out PACKET_HEADER_SIZEDenton Liu, Jun 13, 2020
  2. Đoàn Trần Công DanhJun 13, 2020
  3. Denton LiuJun 13, 2020
  4. Junio C HamanoJun 13, 2020
  5. Junio C HamanoJun 14, 2020
  6. 0/3 pkt-line: war on magical `4` literalDenton Liu, Jun 14, 2020
  7. 2/3 pkt-line: use string versions of functionsDenton Liu, Jun 14, 2020
  8. Đoàn Trần Công DanhJun 14, 2020
  9. pkt-line: use string versions of functionsDenton Liu, Jun 14, 2020
  10. Junio C HamanoJun 14, 2020
  11. Denton LiuJun 14, 2020
  12. Đoàn Trần Công DanhJun 15, 2020
  13. 1/3 remote-curl: use strlen() instead of magic numbersDenton Liu, Jun 14, 2020
  14. 3/3 pkt-line: extract out PACKET_HEADER_SIZEDenton Liu, Jun 14, 2020
  15. Junio C HamanoJun 14, 2020
  16. 0/3 pkt-line: war on magical `4` literalDenton Liu, Jun 23, 2020
  17. 1/3 remote-curl: use strlen() instead of magic numbersDenton Liu, Jun 23, 2020
  18. Jeff KingJun 23, 2020
  19. Junio C HamanoJun 23, 2020
  20. 2/3 pkt-line: use string versions of functionsDenton Liu, Jun 23, 2020
  21. Jeff KingJun 23, 2020
  22. 3/3 pkt-line: extract out PACKET_HEADER_SIZEDenton Liu, Jun 23, 2020

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.