From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ZkC9IYf6BWC0JwAAWB0awg (envelope-from ) for ; Mon, 18 Jan 2021 16:15:51 -0500 Received: by simark.ca (Postfix, from userid 112) id 7B2681EF80; Mon, 18 Jan 2021 16:15:51 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BC0F61E945 for ; Mon, 18 Jan 2021 16:15:50 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14306386F811; Mon, 18 Jan 2021 21:15:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14306386F811 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611004550; bh=AzEzOdImgu6Sqre3MYC8hZS4ijnjl5ImeDEBNgdMGmQ=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=dYujQQgXpLwaKJ3X2/bmdNw1kXEuzUc97X3+MelLpN/rjSXHD5V1LatbqCu+NfYAD GXp2sYjTlR9KuiLhjKlwzis/CAF3mDuk50nIbXZvvZtOYdha0Tr0T+WncnpjfKuLfE VbMzrfb4QB0tDeG4CaNQEjv56YSt3+zPmPGb1UOw= Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id C183B386F803 for ; Mon, 18 Jan 2021 21:15:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C183B386F803 Received: from vapier (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E7B31340E9B; Mon, 18 Jan 2021 21:15:45 +0000 (UTC) Date: Mon, 18 Jan 2021 16:15:44 -0500 To: Simon Marchi Subject: Re: [PATCH] sim: common: modernize gennltvals.sh Message-ID: Mail-Followup-To: Simon Marchi , gdb-patches@sourceware.org References: <20210117101044.32143-1-vapier@gentoo.org> <0674d2d0-2534-ac08-c83c-4330d090a1bc@polymtl.ca> <57246960-bd66-6a02-49c2-0d0eb66af777@polymtl.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <57246960-bd66-6a02-49c2-0d0eb66af777@polymtl.ca> X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mike Frysinger via Gdb-patches Reply-To: Mike Frysinger Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 18 Jan 2021 13:08, Simon Marchi via Gdb-patches wrote: > On 2021-01-18 12:52 p.m., Mike Frysinger wrote: > > On 18 Jan 2021 12:19, Simon Marchi via Gdb-patches wrote: > >> On 2021-01-18 12:13 p.m., Mike Frysinger wrote: > >>> i had run shellcheck and the only warnings (about unquoted expansion) > >>> i didn't think we worth fixing because of the limited scope of the > >>> script. the variable in question isn't accepting user input, it's > >>> operating on fixed inputs, and if we restrict ourselves to POSIX > >>> shell (which i think we do), then our options are limited, and imo > >>> the alternatives make it harder to read/understand. > >> > >> Even considering this, I think it's worth just quoting the variables > >> and getting rid the warnings. It's trivial, and it would make any > >> future (more important) warning more apparent. > > > > to be clear, it isn't a style issue, it's a correctness issue. > > adding the quotes will break the script. > > > > here's the warning: > > printf '#include <%s>\n' ${files} > > ^------^ SC2086: Double quote to prevent globbing and word splitting. > > > > this is because the code passes in multiple files to process as an arg: > > gentvals "" errno ... "errno.h sys/errno.h" ... > > > > then we use it like: > > files=$4 > > ... > > for f in ${files}; do > > ... > > printf '#include <%s>\n' ${files} > > > > unquoted, we get: > > #include > > #include > > > > quoted, we get: > > #include > > Wait, what. This printf call gives you multiple lines, and does not > tell you "you have too many arguments for the format string"? This > is... surprising. i guess it's just familiarity with it because it's what i expected :). it makes the printf program pretty useful for formatting a bunch of args like we have here. > To produce that output, I would have expected a for loop: > > for f in ${files}; do > printf '#include <%s>\n' "$f" > done that would work, but a single printf call is equiv & simpler :). > > our options are limited with POSIX shell: > > * use arrays ... POSIX shell only has one builtin array: the args. > > so we'd rework the func API to pass in multiple files, and we'd > > operate on $@ by shifting it and iterating. > > Ok, I'm used to using bash arrays, I forgot they weren't standard. hopefully one day someone will push the POSIX committe to extend the shell language to include arrays. until then, our primitives are ... primitive. > > * change the shell runtime env by disabling path expansion. that > > would mitigate the path expansion (which doesn't happen here as > > we know the inputs are all alphanumeric/periods), but still would > > have word splitting because we want that. > > > > shell is just a bad programming language. but i think the tree > > specifically constrains itself to it for portability. i don't know > > what, if any, policies we have about using any other language. > > I think it would be perfectly fine to require bash or python. in what context ? i assume it's off-limits for people downloading a release and building e.g. gdb or gas. but is it acceptable for devs doing dev work (which is what this thing is) ? -mike