From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from qproxy5-pub.mail.unifiedlayer.com (qproxy5-pub.mail.unifiedlayer.com [69.89.21.30]) by sourceware.org (Postfix) with ESMTPS id 567213858CDB for ; Fri, 3 Mar 2023 14:32:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 567213858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from outbound-ss-761.bluehost.com (outbound-ss-761.bluehost.com [74.220.211.250]) by qproxy5.mail.unifiedlayer.com (Postfix) with ESMTP id 553808030849 for ; Fri, 3 Mar 2023 14:32:56 +0000 (UTC) Received: from cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway8.mail.pro1.eigbox.com (Postfix) with ESMTP id BAED110047D70 for ; Fri, 3 Mar 2023 14:32:25 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id Y6SPpT0kmC4qIY6SPpWU6u; Fri, 03 Mar 2023 14:32:25 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=Jcx5EWGV c=1 sm=1 tr=0 ts=640204f9 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=k__wU0fu6RkA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=jXMSeIWpKXvR-itHOnEA:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=SCAHU+qe90iyU1Lr5Wb3vmENqNaY5VZbLy6itrUixSk=; b=oqD0encWhAL4m/1s84n7RTDaaA ++ZbGt8ZxlbtE7hLkzDqp5H3GOPyvHYYKqgciMvtUSOVUNltCx18300is/gmb5YnWuPyyu8sqLxmY usE8RH+xCTUCoJmvEnzX3gZ9U; Received: from 75-166-130-93.hlrn.qwest.net ([75.166.130.93]:52160 helo=murgatroyd) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pY6SP-0009MF-HR; Fri, 03 Mar 2023 07:32:25 -0700 From: Tom Tromey To: Tom de Vries via Gdb-patches Cc: Tom de Vries Subject: Re: [PATCH] [gdb/testsuite] Allow args in gdb_caching_proc References: <20230303140602.9477-1-tdevries@suse.de> X-Attribution: Tom Date: Fri, 03 Mar 2023 07:32:22 -0700 In-Reply-To: <20230303140602.9477-1-tdevries@suse.de> (Tom de Vries via Gdb-patches's message of "Fri, 3 Mar 2023 15:06:02 +0100") Message-ID: <87zg8taosp.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.130.93 X-Source-L: No X-Exim-ID: 1pY6SP-0009MF-HR X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-130-93.hlrn.qwest.net (murgatroyd) [75.166.130.93]:52160 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3020.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: >>>>> "Tom" == Tom de Vries via Gdb-patches writes: Tom> Test-case gdb.base/morestack.exp contains: Tom> ... Tom> require {have_compile_flag -fsplit-stack} Tom> ... Tom> and I want to cache the result of have_compile_flag. Seems reasonable. Tom> + if { ![regexp -- "^gdb_caching_proc \[ \t\]*(\[^ \t\]*)" $line \ Tom> + match procname] } { Tom> + continue Tom> } Tom> + if { [regexp -- "{\[ \t\]*\[^ \t\].*}" $line] } { Tom> + # With args. Tom> + continue Tom> + } Tom> + lappend procnames $procname In Tcl you can inspect the arguments to a proc using 'info args', which may be more robust than a regexp. I didn't read the test to see if this is really possible in this case, though. Tom> - set code [catch {uplevel 2 $real_name} result] Tom> + set code [catch {uplevel 2 $real_name {*}$args} result] I think this is the wrong quoting and will cause problems if any argument has a space. Instead I think you want: + set code [catch {uplevel 2 [list $real_name {*}$args]} result] Tom> -proc gdb_caching_proc {name body} { Tom> +proc gdb_caching_proc_1 { name args body } { I would call this something other than 'args'. The name 'args' is special in Tcl when it's the last argument, so it's confusing to find it other places. Tom> # Define the advertised proc. Tom> - proc $name {} [list gdb_do_cache $name] Tom> + set body [list "gdb_do_cache" "$name"] The quotes here aren't needed. It's safe to add them if you like them, but they don't do anything. Also reusing 'body' here seems weird. Tom> + foreach arg $args { Tom> + lappend body $$arg Tom> + } Tom> + set body [join $body] "join" is usually wrong when constructing lists, and I think here this line can just be dropped. I notice this doesn't handle defaulted arguments. This isn't hard if you want to do it; each argument is a list and in that loop you'd just use [lindex $arg 0]. Tom> +# Define a new proc named NAME, with optional args ARGS. BODY is the body of Tom> +# the proc. The proc will evaluate BODY and cache the results, both in memory Tom> +# and, if GDB_PARALLEL is defined, in the filesystem for use across Tom> +# invocations of dejagnu. Tom> +# Tom> +# Valid forms: Tom> +# gdb_caching_proc NAME BODY Tom> +# gdb_caching_proc NAME ARGS BODY Tom> + Tom> +proc gdb_caching_proc { name args } { I think it would be better to just require gdb_caching_proc to work exactly like proc, and fix all the existing calls to add a {} for the arg list. Tom> + if { [llength $args] == 1 } { Tom> + set body [lindex $args 0] Tom> + set args {} Tom> + } elseif { [llength $args] == 2 } { Tom> + set body [lindex $args 1] Tom> + set args [lindex $args 0] Tom> + } else { Tom> + error "Incorrect number of arguments" Tom> + } Then none of this would be needed either. Tom