{"thread":{"id":"54641","subject":"[PATCH] list-objects-filter-options: fix function name in BUG","startedAt":"2020-11-14T08:44:05Z","lastAt":"2020-11-18T06:22:25Z","messageCount":8,"participants":["Martin Ågren","Jeff King","Eric Sunshine","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"409947","messageId":"20201114084327.14891-1-martin.agren@gmail.com","threadId":"54641","inReplyTo":null,"subject":"[PATCH] list-objects-filter-options: fix function name in BUG","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2020-11-14T08:43:26Z","receivedAt":"2020-11-14T08:44:05Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"Fix the function name we give in the BUG message. It's \"config\", not\n\"choice\".\n\nSigned-off-by: Martin Ågren <martin.agren@gmail.com>\n---\n list-objects-filter-options.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/list-objects-filter-options.c b/list-objects-filter-options.c\nindex defd3dfd10..d2d1c81caf 100644\n--- a/list-objects-filter-options.c\n+++ b/list-objects-filter-options.c\n@@ -35,7 +35,7 @@ const char *list_object_filter_config_name(enum list_objects_filter_choice c)\n \t\t/* not a real filter type; just the count of all filters */\n \t\tbreak;\n \t}\n-\tBUG(\"list_object_filter_choice_name: invalid argument '%d'\", c);\n+\tBUG(\"list_object_filter_config_name: invalid argument '%d'\", c);\n }\n \n /*\n-- \n2.29.2.454.gaff20da3a2\n\n"},{"id":"410063","messageId":"20201117021318.GA30463@coredump.intra.peff.net","threadId":"54641","inReplyTo":"20201114084327.14891-1-martin.agren@gmail.com","subject":"Re: [PATCH] list-objects-filter-options: fix function name in BUG","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-11-17T02:13:18Z","receivedAt":"2020-11-17T02:14:01Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Nov 14, 2020 at 09:43:26AM +0100, Martin Ågren wrote:\n\n> Fix the function name we give in the BUG message. It's \"config\", not\n> \"choice\".\n\nYep, obviously an improvement.\n\nBut as a general rule, I don't think we even need to include function\nnames here. The message would look like:\n\n  BUG: list-objects-filter-options.c:20: list_object_filter_choice_name: invalid argument '3'\n\nwhich already tells us where the code is[1]. Perhaps:\n\n  BUG(\"invalid filter choice enum: %d\", c);\n\nwould be shorter but equally informative (I don't overly care here,\nsince the idea is that nobody sees it, but just making a point about the\nfuture).\n\n-Peff\n\n[1] Obviously it doesn't include the actual function name, though we\n    could do so on many platforms by using __FUNCTION__. I tend to think\n    it would make the messages overly long, but again, the hope is that\n    nobody ever sees these.\n"},{"id":"410115","messageId":"CAN0heSoGnAKjTz2tiHpe2==Y-w7M03eiEpW2hU67FRbv=G+H8w@mail.gmail.com","threadId":"54641","inReplyTo":"20201117021318.GA30463@coredump.intra.peff.net","subject":"Re: [PATCH] list-objects-filter-options: fix function name in BUG","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2020-11-17T18:02:19Z","receivedAt":"2020-11-17T18:02:55Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"On Tue, 17 Nov 2020 at 03:13, Jeff King <peff@peff.net> wrote:\n>\n> On Sat, Nov 14, 2020 at 09:43:26AM +0100, Martin Ågren wrote:\n>\n> > Fix the function name we give in the BUG message. It's \"config\", not\n> > \"choice\".\n>\n> Yep, obviously an improvement.\n>\n> But as a general rule, I don't think we even need to include function\n> names here. The message would look like:\n>\n>   BUG: list-objects-filter-options.c:20: list_object_filter_choice_name: invalid argument '3'\n>\n> which already tells us where the code is[1]. Perhaps:\n>\n>   BUG(\"invalid filter choice enum: %d\", c);\n>\n> would be shorter but equally informative (I don't overly care here,\n> since the idea is that nobody sees it, but just making a point about the\n> future).\n\nHaving the function name or something else making the string unique\nacross the codebase could be useful if the compiler doesn't support\nvariadic macros -- we'll fall back to using a function instead of a\nmacro, and can't use __FILE__ and __LINE__. (You obviously know all of\nthis, having written d8193743e0 (\"usage.c: add BUG() function\",\n2017-05-12).)\n\nNow, this here BUG shouldn't be a \"freak\" bug which happens to trigger\nunder very special circumstances, and where it's not even clear which of\n25 equal BUG messages it is that we're seeing. If you add a new enum\nvalue and forget to add a case in this function, you should hit this BUG\nquite quickly and very reliably.\n\nAll of that said, \"don't overly care\" also matches my feeling pretty\nwell.\n\nMartin\n"},{"id":"410173","messageId":"20201117225401.GA642410@coredump.intra.peff.net","threadId":"54641","inReplyTo":"CAN0heSoGnAKjTz2tiHpe2==Y-w7M03eiEpW2hU67FRbv=G+H8w@mail.gmail.com","subject":"Re: [PATCH] list-objects-filter-options: fix function name in BUG","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-11-17T22:54:01Z","receivedAt":"2020-11-17T22:54:04Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Nov 17, 2020 at 07:02:19PM +0100, Martin Ågren wrote:\n\n> > But as a general rule, I don't think we even need to include function\n> > names here. The message would look like:\n> >\n> >   BUG: list-objects-filter-options.c:20: list_object_filter_choice_name: invalid argument '3'\n> >\n> > which already tells us where the code is[1]. Perhaps:\n> >\n> >   BUG(\"invalid filter choice enum: %d\", c);\n> >\n> > would be shorter but equally informative (I don't overly care here,\n> > since the idea is that nobody sees it, but just making a point about the\n> > future).\n> \n> Having the function name or something else making the string unique\n> across the codebase could be useful if the compiler doesn't support\n> variadic macros -- we'll fall back to using a function instead of a\n> macro, and can't use __FILE__ and __LINE__. (You obviously know all of\n> this, having written d8193743e0 (\"usage.c: add BUG() function\",\n> 2017-05-12).)\n\nMy feeling is that we shouldn't care too much about platforms without\nvariadic macros. AFAIK they are an extreme minority at this point, if\nthey exist at all. We are being nice by making Git compile at all on\nsuch platforms, but I don't want people doing normal development work\n(like writing trace or bug calls) to have to be thinking too much about\nit.\n\nI actually wonder if it is time to drop HAVE_VARIADIC_MACROS completely.\nThey are in C99, and we have been introducing many other C99-isms. It\nwould be a minor cleanup to a few bits of code, which perhaps isn't\nworth the risk. But I also have a vague memory of not being able to\nimplement some interfaces because we couldn't count on them.\n\nPoking around, 3689539127 (add helpers for allocating flex-array\nstructs, 2016-02-22) points out one such case. I think discussion of\nBUG_ON() got blocked by that, too. Looks like we also discussed them in\nthe big \"C99 weather balloon\" thread:\n\n  https://lore.kernel.org/git/20170710070342.txmlwwq6gvjkwtw7@sigill.intra.peff.net/\n\nMaybe it's time for something like this as a test:\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 2fd9d5b403..fe5de2239f 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -1194,14 +1194,9 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,\n /* usage.c: only to be used for testing BUG() implementation (see test-tool) */\n extern int BUG_exit_code;\n \n-#ifdef HAVE_VARIADIC_MACROS\n __attribute__((format (printf, 3, 4))) NORETURN\n void BUG_fl(const char *file, int line, const char *fmt, ...);\n #define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__)\n-#else\n-__attribute__((format (printf, 1, 2))) NORETURN\n-void BUG(const char *fmt, ...);\n-#endif\n \n /*\n  * Preserves errno, prints a message, but gives no warning for ENOENT.\ndiff --git a/usage.c b/usage.c\nindex 06665823a2..b72f48f70e 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -273,23 +273,13 @@ static NORETURN void BUG_vfl(const char *file, int line, const char *fmt, va_lis\n \tabort();\n }\n \n-#ifdef HAVE_VARIADIC_MACROS\n NORETURN void BUG_fl(const char *file, int line, const char *fmt, ...)\n {\n \tva_list ap;\n \tva_start(ap, fmt);\n \tBUG_vfl(file, line, fmt, ap);\n \tva_end(ap);\n }\n-#else\n-NORETURN void BUG(const char *fmt, ...)\n-{\n-\tva_list ap;\n-\tva_start(ap, fmt);\n-\tBUG_vfl(NULL, 0, fmt, ap);\n-\tva_end(ap);\n-}\n-#endif\n \n #ifdef SUPPRESS_ANNOTATED_LEAKS\n void unleak_memory(const void *ptr, size_t len)\n"},{"id":"410176","messageId":"CAPig+cQnA_zqtjOu2OryM57jVMQeo32U3iBYVzxFkPnZ9Zd+cA@mail.gmail.com","threadId":"54641","inReplyTo":"20201117225401.GA642410@coredump.intra.peff.net","subject":"Re: [PATCH] list-objects-filter-options: fix function name in BUG","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-11-17T23:07:07Z","receivedAt":"2020-11-17T23:07:43Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Nov 17, 2020 at 5:55 PM Jeff King <peff@peff.net> wrote:\n> I actually wonder if it is time to drop HAVE_VARIADIC_MACROS completely.\n> They are in C99, and we have been introducing many other C99-isms. It\n> would be a minor cleanup to a few bits of code, which perhaps isn't\n> worth the risk. But I also have a vague memory of not being able to\n> implement some interfaces because we couldn't count on them.\n>\n> Poking around, 3689539127 (add helpers for allocating flex-array\n> structs, 2016-02-22) points out one such case. I think discussion of\n> BUG_ON() got blocked by that, too. Looks like we also discussed them in\n> the big \"C99 weather balloon\" thread:\n\nThere was also an idea[1] to use variadic macros to prevent `errno`\nfrom being clobbered in a case like this:\n\n    die_errno(_(\"blah %s\"), foobar());\n\nIn which, if foobar() changes `errno`, then die_errno() reports the wrong value.\n\n[1]: https://lore.kernel.org/git/CAPig+cQKMxwadf9aGyC5ESa-vxDy9PzrYo+m+JaVQ3S=12PyQQ@mail.gmail.com/\n"},{"id":"410193","messageId":"20201118020825.GF650959@coredump.intra.peff.net","threadId":"54641","inReplyTo":"CAPig+cQnA_zqtjOu2OryM57jVMQeo32U3iBYVzxFkPnZ9Zd+cA@mail.gmail.com","subject":"Re: [PATCH] list-objects-filter-options: fix function name in BUG","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-11-18T02:08:25Z","receivedAt":"2020-11-18T02:08:49Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Nov 17, 2020 at 06:07:07PM -0500, Eric Sunshine wrote:\n\n> On Tue, Nov 17, 2020 at 5:55 PM Jeff King <peff@peff.net> wrote:\n> > I actually wonder if it is time to drop HAVE_VARIADIC_MACROS completely.\n> > They are in C99, and we have been introducing many other C99-isms. It\n> > would be a minor cleanup to a few bits of code, which perhaps isn't\n> > worth the risk. But I also have a vague memory of not being able to\n> > implement some interfaces because we couldn't count on them.\n> >\n> > Poking around, 3689539127 (add helpers for allocating flex-array\n> > structs, 2016-02-22) points out one such case. I think discussion of\n> > BUG_ON() got blocked by that, too. Looks like we also discussed them in\n> > the big \"C99 weather balloon\" thread:\n> \n> There was also an idea[1] to use variadic macros to prevent `errno`\n> from being clobbered in a case like this:\n> \n>     die_errno(_(\"blah %s\"), foobar());\n> \n> In which, if foobar() changes `errno`, then die_errno() reports the wrong value.\n> \n> [1]: https://lore.kernel.org/git/CAPig+cQKMxwadf9aGyC5ESa-vxDy9PzrYo+m+JaVQ3S=12PyQQ@mail.gmail.com/\n\nThanks, that's another good example. This _could_ be done conditionally\non HAVE_VARIADIC_MACROS, but it would mean on the non-variadic platform\nthat they'd see the wrong errno. I'm willing to give them worse BUG()\nmessages, but that may be going too far. :)\n\nI still suspect there may be zero such platforms, which would mean\nnobody is affected. But if that is the case, then we should just say so\nand get rid of the HAVE_VARIADIC_MACROS flag entirely.\n\n-Peff\n"},{"id":"410195","messageId":"20201118022402.GC360414@google.com","threadId":"54641","inReplyTo":"20201117225401.GA642410@coredump.intra.peff.net","subject":"Re: [PATCH] list-objects-filter-options: fix function name in BUG","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2020-11-18T02:24:02Z","receivedAt":"2020-11-18T02:24:08Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jeff King wrote:\n\n> I actually wonder if it is time to drop HAVE_VARIADIC_MACROS completely.\n> They are in C99, and we have been introducing many other C99-isms. It\n> would be a minor cleanup to a few bits of code, which perhaps isn't\n> worth the risk. But I also have a vague memory of not being able to\n> implement some interfaces because we couldn't count on them.\n>\n> Poking around, 3689539127 (add helpers for allocating flex-array\n> structs, 2016-02-22) points out one such case. I think discussion of\n> BUG_ON() got blocked by that, too. Looks like we also discussed them in\n> the big \"C99 weather balloon\" thread:\n>\n>   https://lore.kernel.org/git/20170710070342.txmlwwq6gvjkwtw7@sigill.intra.peff.net/\n>\n> Maybe it's time for something like this as a test:\n\nYes.  For what it's worth,\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n\nWant to re-send with a signoff?\n\nThanks,\nJonathan\n\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index 2fd9d5b403..fe5de2239f 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -1194,14 +1194,9 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,\n>  /* usage.c: only to be used for testing BUG() implementation (see test-tool) */\n>  extern int BUG_exit_code;\n>  \n> -#ifdef HAVE_VARIADIC_MACROS\n>  __attribute__((format (printf, 3, 4))) NORETURN\n>  void BUG_fl(const char *file, int line, const char *fmt, ...);\n>  #define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__)\n> -#else\n> -__attribute__((format (printf, 1, 2))) NORETURN\n> -void BUG(const char *fmt, ...);\n> -#endif\n>  \n>  /*\n>   * Preserves errno, prints a message, but gives no warning for ENOENT.\n> diff --git a/usage.c b/usage.c\n> index 06665823a2..b72f48f70e 100644\n> --- a/usage.c\n> +++ b/usage.c\n> @@ -273,23 +273,13 @@ static NORETURN void BUG_vfl(const char *file, int line, const char *fmt, va_lis\n>  \tabort();\n>  }\n>  \n> -#ifdef HAVE_VARIADIC_MACROS\n>  NORETURN void BUG_fl(const char *file, int line, const char *fmt, ...)\n>  {\n>  \tva_list ap;\n>  \tva_start(ap, fmt);\n>  \tBUG_vfl(file, line, fmt, ap);\n>  \tva_end(ap);\n>  }\n> -#else\n> -NORETURN void BUG(const char *fmt, ...)\n> -{\n> -\tva_list ap;\n> -\tva_start(ap, fmt);\n> -\tBUG_vfl(NULL, 0, fmt, ap);\n> -\tva_end(ap);\n> -}\n> -#endif\n>  \n>  #ifdef SUPPRESS_ANNOTATED_LEAKS\n>  void unleak_memory(const void *ptr, size_t len)\n"},{"id":"410203","messageId":"CAN0heSoyQY9H7FtK29KwXj+OkuFPfJSHw388P4Js1NTib=w-8Q@mail.gmail.com","threadId":"54641","inReplyTo":"20201117225401.GA642410@coredump.intra.peff.net","subject":"Re: [PATCH] list-objects-filter-options: fix function name in BUG","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2020-11-18T06:22:08Z","receivedAt":"2020-11-18T06:22:25Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"On Tue, 17 Nov 2020 at 23:54, Jeff King <peff@peff.net> wrote:\n>\n> I actually wonder if it is time to drop HAVE_VARIADIC_MACROS completely.\n> They are in C99, and we have been introducing many other C99-isms. It\n> would be a minor cleanup to a few bits of code, which perhaps isn't\n> worth the risk. But I also have a vague memory of not being able to\n> implement some interfaces because we couldn't count on them.\n>\n> Poking around, 3689539127 (add helpers for allocating flex-array\n> structs, 2016-02-22) points out one such case. I think discussion of\n> BUG_ON() got blocked by that, too. Looks like we also discussed them in\n> the big \"C99 weather balloon\" thread:\n>\n>   https://lore.kernel.org/git/20170710070342.txmlwwq6gvjkwtw7@sigill.intra.peff.net/\n\nOk, that all makes sense.\n\n> Maybe it's time for something like this as a test:\n\nI had a vague memory that for some weather balloons, we would add a\ncomment like \"please let us know if you trip on this; for your own sake,\ndon't just patch it locally.\" But maybe that was just for, e.g.,\n01d3a526ad (\"t0000: check whether the shell supports the \"local\"\nkeyword\", 2017-10-26), where we add a test, and a single failing test\nmight otherwise be easy to ignore.\n\nWhich is different to what would happen if every file including\ngit-compat-util.h and/or each invocation of BUG() would make the\ncompiler complain.\n\nAll in all, this diff makes sense.\n\nMartin\n"}]}