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

Re: [PATCH v2 0/7] Builtin FSMonitor Part 1

From
JHJeff Hostetler <git@jeffhostetler.com>
Date
Sep 23, 2021, 17:12 UTC
Message-ID
<0ec69aff-40a9-aac1-5fca-08033c967d88@jeffhostetler.com>
In-Reply-To
<87v92r49mt.fsf@evledraar.gmail.com>
On 9/23/21 10:33 AM, Ævar Arnfjörð Bjarmason wrote:
Show 20 quoted lines
> 
> On Mon, Sep 20 2021, Jeff Hostetler via GitGitGadget wrote:
> 
>> Here is V2 of Part 1 of my Builtin FSMonitor series.
>>
>> Changes since V1 include:
>>
>>   * Drop the Trace2 memory leak.
>>   * Added a new "child_ready" event to Trace2 as an alternative to the
>>     "child_exit" event for background processes.
>>   * Convert the Trace2-related NEEDSWORK items in "start_bg_command()" to use
>>     the new "child_ready" event.
>>   * Various minor code and documentation cleanups.
> 
> I see 7/7 still has a pattern you included only to make a compiler error
> better. I noted in
> https://lore.kernel.org/git/87ilyycko3.fsf@evledraar.gmail.com/ that it
> make the error worse, on at least clang. You didn't note which compiler
> you were massaging, presumably MSVC.
> 

I've been holding my tongue for days on this issue and hoping a third party would step in an render an opinion one way or another.

Too me, a forward declaration seemed like no big deal and it does have value as I tried to explain. And frankly, it felt a little bit like bike-shedding and was trying to avoid that again.

The error message I quoted was from Clang v11.0.3. My forward declaration of the function prior to the actual definition of the function causes the compiler to stop at the function definition and complain with a short message saying that the function itself is incorrectly defined and doesn't match the typedef that it is associated with.

When I use MSVC I get a similar error at the function definition.

When I use GCC I get error messages at both the function definition and the usage in the call.

Additionally, the forward declaration states that the function is associated with that typedef (something that is otherwise implicit and may be hard to discover (more on that in a minute)).

And it doesn't require a reference to the function pointer (either on the right side of an assignment, a vtable initialization, or passing it in a function call) to flag the error. We always get the error at the point of the definition.

The error message in your example is, I feel, worse than mine. It splats 2 different function signatures -- only one of which has the typedef name -- in a large, poorly wrapped brick of text.

Yes, your error message does print corresponding arg in the function prototype of "start_bg_command()" that doesn't agree with the symbol used at the call-site, but that is much later than where the actual error occurred. And if the forward declaration were present, you'd already know that back up at the definition, right.

Let's look at this from another point of view.

Suppose for example we have two function prototypes with the same signature. Perhaps they describe groups of functions with different semantics -- the fact that they have the same argument list and return type is just a coincidence.

     typedef int(t_fn_1)(int);
     typedef int(t_fn_2)(int);
And then declare one or more instances of functions in those groups:
     int foo_a(int x) { ... }
     int foo_b(int x) { ... }
     int foo_c(int x) { ... }
     int foo_d(int x) { ... }
     int foo_e(int x) { ... }
     int foo_f(int x) { ... }
     int foo_g(int x) { ... }

Which of those functions should be associated with "t_fn_1" and which with "t_fn_2"? Again, they all have the same signature, but different semantics. The author knows when they wrote the code, but it may be hard to automatically determine later.

If I then have a function like start_bg_command() that receives a function pointer:

     int test(..., t_fn_1 *fn, ...) { ... }

In C -- even with the use of forward function declarations -- the compiler won't complain if you pass test() a pointer of type t_fn_2 -- as long a t_fn_1 and t_fn_2 have the same signature.

But it does give the human a chance to catch the error. Of if we later change the function signature in the t_fn_1 typedef, we will automatically get a list of which of those foo_x functions do and do not need to be updated.

Anyway, I've soapboxed on this enough. I think it is a worthy feature for the price.

Jeff
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 63 of 66 in “Builtin FSMonitor Part 1”
  1. 0/7 Builtin FSMonitor Part 1Jeff Hostetler via GitGitGadget, Sep 15, 2021
  2. 4/7 simple-ipc/ipc-win32: add trace2 debuggingJeff Hostetler via GitGitGadget, Sep 15, 2021
  3. Ævar Arnfjörð BjarmasonSep 16, 2021
  4. Jeff HostetlerSep 17, 2021
  5. 6/7 run-command: create start_bg_commandJeff Hostetler via GitGitGadget, Sep 15, 2021
  6. Taylor BlauSep 16, 2021
  7. Taylor BlauSep 16, 2021
  8. Ævar Arnfjörð BjarmasonSep 16, 2021
  9. 5/7 simple-ipc/ipc-win32: add Windows ACL to named pipeJeff Hostetler via GitGitGadget, Sep 15, 2021
  10. Ævar Arnfjörð BjarmasonSep 16, 2021
  11. Jeff HostetlerSep 17, 2021
  12. Ævar Arnfjörð BjarmasonSep 17, 2021
  13. 1/7 trace2: fix memory leak of thread nameJeff Hostetler via GitGitGadget, Sep 15, 2021
  14. Junio C HamanoSep 15, 2021
  15. Taylor BlauSep 16, 2021
  16. Ævar Arnfjörð BjarmasonSep 16, 2021
  17. Taylor BlauSep 16, 2021
  18. Ævar Arnfjörð BjarmasonSep 16, 2021
  19. Jeff HostetlerSep 16, 2021
  20. Ævar Arnfjörð BjarmasonSep 16, 2021
  21. Junio C HamanoSep 16, 2021
  22. 3/7 simple-ipc: move definition of ipc_active_state outside of ifdefJeff Hostetler via GitGitGadget, Sep 15, 2021
  23. Junio C HamanoSep 15, 2021
  24. Jeff HostetlerSep 17, 2021
  25. Carlo ArenasSep 18, 2021
  26. Junio C HamanoSep 20, 2021
  27. 2/7 simple-ipc: preparations for supporting binary messages.Jeff Hostetler via GitGitGadget, Sep 15, 2021
  28. Eric SunshineSep 15, 2021
  29. Jeff HostetlerSep 17, 2021
  30. 7/7 t/helper/simple-ipc: convert test-simple-ipc to use start_bg_commandJeff Hostetler via GitGitGadget, Sep 15, 2021
  31. Taylor BlauSep 16, 2021
  32. Jeff HostetlerSep 17, 2021
  33. Ævar Arnfjörð BjarmasonSep 18, 2021
  34. Ævar Arnfjörð BjarmasonSep 16, 2021
  35. 0/7 Builtin FSMonitor Part 1Jeff Hostetler via GitGitGadget, Sep 20, 2021
  36. 1/7 trace2: add trace2_child_ready() to report on background childrenJeff Hostetler via GitGitGadget, Sep 20, 2021
  37. 2/7 simple-ipc: preparations for supporting binary messages.Jeff Hostetler via GitGitGadget, Sep 20, 2021
  38. 3/7 simple-ipc: move definition of ipc_active_state outside of ifdefJeff Hostetler via GitGitGadget, Sep 20, 2021
  39. 4/7 simple-ipc/ipc-win32: add trace2 debuggingJeff Hostetler via GitGitGadget, Sep 20, 2021
  40. 6/7 run-command: create start_bg_commandJeff Hostetler via GitGitGadget, Sep 20, 2021
  41. 5/7 simple-ipc/ipc-win32: add Windows ACL to named pipeJeff Hostetler via GitGitGadget, Sep 20, 2021
  42. 7/7 t/helper/simple-ipc: convert test-simple-ipc to use start_bg_commandJeff Hostetler via GitGitGadget, Sep 20, 2021
  43. Ævar Arnfjörð BjarmasonSep 23, 2021
  44. Jeff HostetlerSep 23, 2021
  45. Junio C HamanoSep 23, 2021
  46. Adam DinwoodieNov 4, 2021
  47. Ramsay JonesNov 4, 2021
  48. Jeff HostetlerNov 8, 2021
  49. Johannes SchindelinNov 8, 2021
  50. Ramsay JonesNov 9, 2021
  51. Johannes SchindelinNov 9, 2021
  52. Junio C HamanoNov 9, 2021
  53. Johannes SchindelinNov 10, 2021
  54. Adam DinwoodieNov 12, 2021
  55. Junio C HamanoNov 12, 2021
  56. Adam DinwoodieNov 12, 2021
  57. Johannes SchindelinNov 16, 2021
  58. Johannes SchindelinNov 16, 2021
  59. Ramsay JonesNov 13, 2021
  60. Ramsay JonesNov 14, 2021
  61. Adam DinwoodieNov 14, 2021
  62. Ævar Arnfjörð BjarmasonSep 23, 2021
  63. Jeff HostetlerSep 23, 2021
  64. Ævar Arnfjörð BjarmasonSep 23, 2021
  65. Jeff HostetlerSep 27, 2021
  66. Taylor BlauSep 23, 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.