{"thread":{"id":"51695","subject":"[PATCH] sha1-name: make sort_ambiguous_oid_array() thread-safe","startedAt":"2019-08-20T18:49:22Z","lastAt":"2019-08-20T18:57:10Z","messageCount":2,"participants":["René Scharfe","Derrick Stolee"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"380837","messageId":"a08751c7-170d-7faf-272e-79c589ec3eab@web.de","threadId":"51695","inReplyTo":null,"subject":"[PATCH] sha1-name: make sort_ambiguous_oid_array() thread-safe","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-08-20T18:49:12Z","receivedAt":"2019-08-20T18:49:22Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Use QSORT_S instead of QSORT, which allows passing the repository\npointer to the comparison function without using a static variable.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n sha1-name.c | 9 +++------\n 1 file changed, 3 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 2989e27b71..c665e3f96d 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -403,9 +403,9 @@ static int repo_collect_ambiguous(struct repository *r,\n \treturn collect_ambiguous(oid, data);\n }\n\n-static struct repository *sort_ambiguous_repo;\n-static int sort_ambiguous(const void *a, const void *b)\n+static int sort_ambiguous(const void *a, const void *b, void *ctx)\n {\n+\tstruct repository *sort_ambiguous_repo = ctx;\n \tint a_type = oid_object_info(sort_ambiguous_repo, a, NULL);\n \tint b_type = oid_object_info(sort_ambiguous_repo, b, NULL);\n \tint a_type_sort;\n@@ -434,10 +434,7 @@ static int sort_ambiguous(const void *a, const void *b)\n\n static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)\n {\n-\t/* mutex will be needed if this code is to be made thread safe */\n-\tsort_ambiguous_repo = r;\n-\tQSORT(a->oid, a->nr, sort_ambiguous);\n-\tsort_ambiguous_repo = NULL;\n+\tQSORT_S(a->oid, a->nr, sort_ambiguous, r);\n }\n\n static enum get_oid_result get_short_oid(struct repository *r,\n--\n2.23.0\n"},{"id":"380839","messageId":"7000e687-800b-c613-aa90-e022bd30a023@gmail.com","threadId":"51695","inReplyTo":"a08751c7-170d-7faf-272e-79c589ec3eab@web.de","subject":"Re: [PATCH] sha1-name: make sort_ambiguous_oid_array() thread-safe","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-08-20T18:57:04Z","receivedAt":"2019-08-20T18:57:10Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 8/20/2019 2:49 PM, René Scharfe wrote:\n> Use QSORT_S instead of QSORT, which allows passing the repository\n> pointer to the comparison function without using a static variable.\n\nMakes sense.\n\n> -static struct repository *sort_ambiguous_repo;\n> -static int sort_ambiguous(const void *a, const void *b)\n> +static int sort_ambiguous(const void *a, const void *b, void *ctx)\n>  {\n> +\tstruct repository *sort_ambiguous_repo = ctx;\n>  \tint a_type = oid_object_info(sort_ambiguous_repo, a, NULL);\n>  \tint b_type = oid_object_info(sort_ambiguous_repo, b, NULL);\n>  \tint a_type_sort;\n> @@ -434,10 +434,7 @@ static int sort_ambiguous(const void *a, const void *b)\n> \n>  static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)\n>  {\n> -\t/* mutex will be needed if this code is to be made thread safe */\n> -\tsort_ambiguous_repo = r;\n> -\tQSORT(a->oid, a->nr, sort_ambiguous);\n> -\tsort_ambiguous_repo = NULL;\n> +\tQSORT_S(a->oid, a->nr, sort_ambiguous, r);\n>  }\n\nLGTM!\n\nThanks,\n-Stolee\n"}]}