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

Re: [PATCH v2] git-compat-util: use gettimeofday(2) for time(2)

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 21, 2023, 16:20 UTC
Message-ID
<xmqq4jqekreu.fsf@gitster.g>
In-Reply-To
<f78fd970-cce5-0a38-5ada-94ccb5bce592@cs.ucla.edu>
Paul Eggert <eggert@cs.ucla.edu> writes:
Show 6 quoted lines
> Thanks, this looks good. As a matter of fact it almost precisely
> matches what I was about to email you. The only significant difference
> is that yours has "#define time(x) git_time(x)" whereas mine had
> "#define time git_time". Since Git never takes the address of 'time'
> the two macro definitions should have equivalent effects when used in
> Git.

That is a valid concern. Writing &time would not be caught by compilers, and you would not notice such a mistake until you run "nm -ug" on the result.

On the other hand, straight token replacement will risk renaming variables and structure members, and I was not sure if we have such use of the identifier "time". As long as people do not use "time" and "git_time" at the same time as such identifiers, that would not be an issue (except for perhaps expecting to see them in debuggers). Writing "git_time" and "time" at the same time for identifiers not related to the time(2) function would not be caught by compilers, either, but it feels much less likely mistake we would make in the future, so let me drop (x) from the macro.

Thanks.
Previous: Paul EggertNext: Konstantin Khomoutov
Message 13 of 19 in “use gettimeofday for current time”
  1. 0/2 use gettimeofday for current timePaul Eggert, Mar 19, 2023
  2. 2/2 git-compat-util: use gettimeofday for current timePaul Eggert, Mar 19, 2023
  3. Eric WongMar 19, 2023
  4. Junio C HamanoMar 20, 2023
  5. Junio C HamanoMar 20, 2023
  6. Paul EggertMar 20, 2023
  7. Junio C HamanoMar 20, 2023
  8. Taylor BlauMar 20, 2023
  9. Taylor BlauMar 20, 2023
  10. 1/2 git-compat-util: time_now for current timePaul Eggert, Mar 19, 2023
  11. git-compat-util: use gettimeofday(2) for time(2)Junio C Hamano, Mar 20, 2023
  12. Paul EggertMar 20, 2023
  13. Junio C HamanoMar 21, 2023
  14. Konstantin KhomoutovMar 21, 2023
  15. Junio C HamanoMar 21, 2023
  16. Jeff KingMar 21, 2023
  17. Taylor BlauMar 21, 2023
  18. Junio C HamanoMar 21, 2023
  19. Jeff KingMar 22, 2023

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.