From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI shortcircuit=no autolearn=ham autolearn_force=no version=3.4.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 5C1FA1F97E for ; Fri, 5 Oct 2018 19:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728278AbeJFCIy (ORCPT ); Fri, 5 Oct 2018 22:08:54 -0400 Received: from cloud.peff.net ([104.130.231.41]:43544 "HELO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1728139AbeJFCIx (ORCPT ); Fri, 5 Oct 2018 22:08:53 -0400 Received: (qmail 24452 invoked by uid 109); 5 Oct 2018 19:08:50 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with SMTP; Fri, 05 Oct 2018 19:08:50 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 14981 invoked by uid 111); 5 Oct 2018 19:08:06 -0000 Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7) by peff.net (qpsmtpd/0.94) with (ECDHE-RSA-AES256-GCM-SHA384 encrypted) SMTP; Fri, 05 Oct 2018 15:08:06 -0400 Authentication-Results: peff.net; auth=none Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Fri, 05 Oct 2018 15:08:48 -0400 Date: Fri, 5 Oct 2018 15:08:48 -0400 From: Jeff King To: =?utf-8?B?UmVuw6k=?= Scharfe Cc: Derrick Stolee , Derrick Stolee via GitGitGadget , git@vger.kernel.org, Junio C Hamano , Derrick Stolee Subject: Re: [PATCH 15/16] commit-reach: make can_all_from_reach... linear Message-ID: <20181005190847.GC17482@sigill.intra.peff.net> References: <816821eec9ba476ccdfbfdf6e3cdd3619743ea2e.1531746012.git.gitgitgadget@gmail.com> <223b14f7-213f-4d22-4776-22dcfd1806c2@web.de> <7b95417a-c8fb-4f1e-cb09-c36804a3a4d0@web.de> <20181005165157.GC11254@sigill.intra.peff.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Fri, Oct 05, 2018 at 08:48:27PM +0200, René Scharfe wrote: > If the comparison function has proper types then we need to declare a > version with void pointer parameters as well to give to qsort(3). I > think using cast function pointers is undefined. Perhaps like this? I think it's undefined, too, though we have many instances already. > +#define DEFINE_SORT(name, type, compare) \ > +static int compare##_void(const void *one, const void *two) \ > +{ \ > + return compare(one, two); \ > +} \ > +static void name(type base, size_t nmemb) \ > +{ \ > + const type dummy = NULL; \ > + if (nmemb > 1) \ > + qsort(base, nmemb, sizeof(base[0]), compare##_void); \ > + else if (0) \ > + compare(dummy, dummy); \ > +} I do like that this removes the need to have the code block aspart of the macro. Did you measure to see if there is any runtime impact? As an aside, we may need to take a "scope" argument in case somebody wants to do this in a non-static way. It would be nice if we could make this "static inline", but I don't think even a clever compiler would be able to omit the wrapper call. -Peff