From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-5.8 required=3.0 tests=AWL,BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 0DC1E203C1 for ; Mon, 12 Dec 2016 19:51:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752760AbcLLTve (ORCPT ); Mon, 12 Dec 2016 14:51:34 -0500 Received: from mout.web.de ([212.227.15.3]:60346 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752492AbcLLTvd (ORCPT ); Mon, 12 Dec 2016 14:51:33 -0500 Received: from [192.168.178.36] ([79.213.118.247]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MBH5Z-1cOSZi3cF3-00AETH; Mon, 12 Dec 2016 20:51:15 +0100 Subject: Re: [PATCH 1/3] compat: add qsort_s() To: Junio C Hamano , Jeff King References: <3083fbf7-d67e-77e4-e05f-94a7e7e15eba@web.de> <20161201193556.j2odwy3sepaxxq5a@sigill.intra.peff.net> Cc: Git List , Johannes Schindelin From: =?UTF-8?Q?Ren=c3=a9_Scharfe?= Message-ID: Date: Mon, 12 Dec 2016 20:51:14 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:ySpFQ1btvCyE/rPdQ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6mCwfRk Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Am 01.12.2016 um 21:22 schrieb Junio C Hamano: > Junio C Hamano writes: > >> Eh, wait. BSD and Microsoft have paramters reordered in the >> callback comparison function. I suspect that would not fly very >> well. > > Hmm. We could do it like this, which may not be too bad. It's kinda cool to have a bespoke compatibility layer for major platforms, but the more I think about it the less I can answer why we would want that. Safety, reliability and performance can't be good reasons -- if our fallback function lacks in these regards then we have to improve it in any case. Text size could be a valid reason, but the full function only adds a bit more than 2KB to the unstripped git binary. The flip side is we'd build an ifdef maze that's harder to read and a lot more difficult to test. What do we get in return for that additional complexity? > #if APPLE_QSORT_R > struct apple_qsort_adapter { > int (*user_cmp)(const void *, const void *, void *); > void *user_ctx; > } > > static int apple_qsort_adapter_cmp(void *ctx, const void *a, const void *b) > { > struct apple_qsort_adapter *wrapper_ctx = ctx; > return wrapper_ctx->user_cmp(a, b, wrapper_ctx->user_ctx); > } > #endif > > int git_qsort_s(void *b, size_t n, size_t s, > int (*cmp)(const void *, const void *, void *), void *ctx) > { > if (!n) > return 0; > if (!b || !cmp) > return -1; > #if GNU_QSORT_R > qsort_r(b, n, s, cmp, ctx); > #elif APPLE_QSORT_R > { > struct appple_qsort_adapter a = { cmp, ctx }; > qsort_r(b, n, s, &a, appple_qsort_adapter_cmp); > } > #endif Nit: The fallback for non-GNU, non-Apple systems is missing here, but the idea is illustrated clearly enough. > return 0; > } >