From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 0AF021F55B for ; Sat, 23 May 2020 12:42:56 +0000 (UTC) Received: from localhost ([::1]:59694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcTUN-0007it-5K for normalperson@yhbt.net; Sat, 23 May 2020 08:42:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcTUJ-0007ih-GF for bug-gnulib@gnu.org; Sat, 23 May 2020 08:42:51 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:42992) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcTUI-0007Tq-IU for bug-gnulib@gnu.org; Sat, 23 May 2020 08:42:51 -0400 Received: by mail-pg1-x541.google.com with SMTP id 124so72313pgi.9 for ; Sat, 23 May 2020 05:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=md3ckOVyzznOz+yVwuW1iQcxOasTZW775ezozWCylCY=; b=viLfWRw66g65iubc0DAnBkpYXjBw3MflLSkG/+Y1yyirGtnIi0ZMbk6DwtCNQJ/4qn ntGcI9Ovmlnv6o0Y5WMfxLDJzEjZHpORWnON74qdOWGs0fvol11yKgfTpp9S+C1035B6 7Xs9eafhAqJ9XKR95UkfSWF8xb5KZaWe/7DUVYfiW6XVh0jvje3Tlyrl+sC2ARrlGAo6 rr7Mo1103FEnIBND25pugFoaubtZea3ZaGS/kjNbayFhARx3TApQdZYtCkToMVUtaWLj pe00ZhXBfEedABn7pK+gMIOQN8WG5WFXXAudj/NX183LWDWKmvYlfVU3zpYFdty5UvlK jOyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=md3ckOVyzznOz+yVwuW1iQcxOasTZW775ezozWCylCY=; b=HJ03ak1fP2SOmSPNRh9yr/syDw6hV2uc6FomFzUHShjzHco3/NZj4Qk2Gyq/2HtVVW 0TBY7R36re94/4F2GDhetplrlfCLEcy3FI9zL8oTz0Es7VHwZq0lqPmVsxXz7Nb1sLj7 boMP5VMyYL4oXWXuy8Wwciy6CS1Ssh/Ot41C5cpVmRc2k4zRbAkr9rqiX8eluU/2M02g /kRgWAdELIoHhJd1NlAS1fMYDLv7ZSfOiNUw9xzF53O24W8QAbwaUJAdQDAWYn4eHKpb O+8if6axL3iAVZf0XpdytSBCCVhInEcsXCT910Czyz7D/kAuBjOdyn/LPYIrkknYk+Co Z4ZQ== X-Gm-Message-State: AOAM53066rAuiMNNz5U0tND9oN2L/0R9w1RCAFgbvTfxGiO2WZiuBy6j uFwAmFk+IMi/gzGdHBNJ7UkhmC2gg8c/oFZ8M0c= X-Google-Smtp-Source: ABdhPJxyE69kC7hCR6cZDETRHXmExBEIcxWPjr1WujtgHbcwcXadNZUhXpCEmYJC6G78b+kccoEu9ubFA3GpqhbbO3k= X-Received: by 2002:a63:8f03:: with SMTP id n3mr17846918pgd.352.1590237769050; Sat, 23 May 2020 05:42:49 -0700 (PDT) MIME-Version: 1.0 References: <2446766.68Cjx1S0tg@omega> <1665251.0HJpBWKgsO@omega> In-Reply-To: <1665251.0HJpBWKgsO@omega> From: =?UTF-8?Q?Marc_Nieper=2DWi=C3=9Fkirchen?= Date: Sat, 23 May 2020 14:42:39 +0200 Message-ID: Subject: Re: stack module To: Bruno Haible Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=marc.nieper@gmail.com; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?Q?Marc_Nieper=2DWi=C3=9Fkirchen?= , bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Hi Bruno, > In Gnulib, we usually avoid extensive use of multi-line macros, because > it hampers debuggability. Here, however, one needs macros, in order to > accommodate the TYPE argument, which is not necessarily compatible to 'void *'. > Nevertheless, we would try to put as much code as possible into functions. > The STACK_INIT macro, for example, could be implemented as a function. How? This would mean that the function stack_init has to take a void * argument, which has to be cast to struct { void *base; ... } and we have to hope that this structure is guaranteed to be compatible to struct { type *base; ... } by the C standard. > > #define STACK_CLEAR(stack) \ > > free ((stack).base) > > Shouldn't this one also set .size and .allocated to 0 ? A stack can be uninitialized or initialized. An uninitialized stack is initialized by STACK_INIT. It is cleared (and uninitialized) by STACK_CLEAR. An uninitialized stack does not have to maintain any invariant. The only way to use it is to initialize it again. Thus, setting .size and .allocated seems pointless. > > #define STACK_POP(stack) \ > > (stack).base [--(stack).size] > > > > #define STACK_DISCARD(stack) \ > > (--(stack).size) > > > > #define STACK_TOP(stack) \ > > (stack).base[(stack).size - 1] > > In these three macros, I would consider to abort() when (stack).size == 0. In the form of assure of the assure module? Or, to facilitate optimization, better assume from verify module? In non-debug builds, I want to make sure that no superfluous checks are made. Marc