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

Re: [RFC PATCH v5 0/8] rebase-interactive

From
JHJeff Hostetler <git@jeffhostetler.com>
Date
Mar 26, 2018, 17:01 UTC
Message-ID
<9ca76d31-828d-0b6f-5069-375792c1f55d@jeffhostetler.com>
In-Reply-To
<xmqqzi2ude4w.fsf@gitster-ct.c.googlers.com>
On 3/26/2018 11:56 AM, Junio C Hamano wrote:
Show 34 quoted lines
> Wink Saville <wink@saville.com> writes:
> 
>> json-writer.c:123:38:  error:  format specifies type 'uintmax_t' (aka
>> 'unsigned long') but the argument has type 'uint64_t' (aka 'unsigned
>> long long') [-Werror,-Wformat]
>>
>>          strbuf_addf(&jw->json, ":%"PRIuMAX, value);
>>                                   ~~         ^~~~~
>> json-writer.c:228:37:  error:  format specifies type 'uintmax_t' (aka
>> 'unsigned long') but the argument has type 'uint64_t' (aka 'unsigned
>> long long') [-Werror,-Wformat] [0m
>>
>>          strbuf_addf(&jw->json, "%"PRIuMAX, value);
>>                                   ~~         ^~~~~
>> 2 errors generated.
>> make: *** [json-writer.o] Error 1
>> make: *** Waiting for unfinished jobs....
> 
> For whatever reason, our codebase seems to shy away from PRIu64,
> even though there are liberal uses of PRIu32.  Showing the value
> casted to uintmax_t with PRIuMAX seems to be our preferred way to
> say "We cannot say how wide this type is on different platforms, and
> are playing safe by using widest-possible int type" (e.g. showing a
> pid_t value from daemon.c).
> 
> In this codepath, the actual values are specified to be uint64_t, so
> the use of PRIu64 may be OK, but I have to wonder why the codepath
> is not dealing with uintmax_t in the first place.  When even larger
> than present archs are prevalent in N years and 64-bit starts to
> feel a tad small (like we feel for 16-bit ints these days), it will
> feel a bit silly to have a subsystem that is limited to such a
> "fixed and a tad small these days" types and pretend it to be be a
> generic seriealizer, I suspect.
> 

I defined that routine to take a uint64_t because I wanted to pass a nanosecond value received from getnanotime() and that's what it returns.

My preference would be to change the PRIuMAX to PRIu64, but there aren't any other references in the code to that symbol and I didn't want to start a new trend here.

I am concerned that the above compiler error message says that uintmax_t is defined as an "unsigned long" (which is defined as *at least* 32 bits, but not necessarily 64. But a uint64_t is defined as a "unsigned long long" and guaranteed as a 64 bit value.

So while I'm not really worried about 128 bit integers right now, I'm more concerned about 32 bit compilers truncating that value without any warnings.

Jeff
Previous: Junio C HamanoNext: Junio C Hamano
Message 32 of 42 in “rebase-interactive”
  1. rebase-interactiveWink Saville, Mar 23, 2018
  2. rebase-interactive: Simplify pick_on_preserving_mergesWink Saville, Mar 23, 2018
  3. Johannes SchindelinMar 23, 2018
  4. rebase: Update invocation of rebase dot-sourced scriptsWink Saville, Mar 23, 2018
  5. Eric SunshineMar 23, 2018
  6. Junio C HamanoMar 23, 2018
  7. Eric SunshineMar 23, 2018
  8. Johannes SchindelinMar 23, 2018
  9. Wink SavilleMar 23, 2018
  10. Junio C HamanoMar 23, 2018
  11. Wink SavilleMar 23, 2018
  12. 0/8 rebase-interactiveWink Saville, Mar 23, 2018
  13. 1/8 rebase-interactive: simplify pick_on_preserving_mergesWink Saville, Mar 23, 2018
  14. 2/8 rebase: update invocation of rebase dot-sourced scriptsWink Saville, Mar 23, 2018
  15. 3/8 Indent function git_rebase__interactiveWink Saville, Mar 23, 2018
  16. Junio C HamanoMar 23, 2018
  17. Wink SavilleMar 23, 2018
  18. Junio C HamanoMar 23, 2018
  19. Wink SavilleMar 24, 2018
  20. 4/8 Extract functions out of git_rebase__interactiveWink Saville, Mar 23, 2018
  21. Junio C HamanoMar 23, 2018
  22. Eric SunshineMar 24, 2018
  23. 5/8 Add and use git_rebase__interactive__preserve_mergesWink Saville, Mar 23, 2018
  24. 6/8 Remove unused code paths from git_rebase__interactiveWink Saville, Mar 23, 2018
  25. 7/8 Remove unused code paths from git_rebase__interactive__preserve_mergesWink Saville, Mar 23, 2018
  26. 8/8 Remove merges_option and a blank lineWink Saville, Mar 23, 2018
  27. Wink SavilleMar 23, 2018
  28. Junio C HamanoMar 23, 2018
  29. Wink SavilleMar 23, 2018
  30. Wink SavilleMar 24, 2018
  31. Junio C HamanoMar 26, 2018
  32. Jeff HostetlerMar 26, 2018
  33. Junio C HamanoMar 26, 2018
  34. Jeff HostetlerMar 26, 2018
  35. Junio C HamanoMar 27, 2018
  36. Jeff HostetlerMar 27, 2018
  37. Junio C HamanoMar 26, 2018
  38. Jeff HostetlerMar 26, 2018
  39. Wink SavilleMar 26, 2018
  40. Junio C HamanoMar 26, 2018
  41. Johannes SchindelinMar 26, 2018
  42. Junio C HamanoMar 23, 2018

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.