From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id 64B5A3857728 for ; Wed, 24 May 2023 16:37:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 64B5A3857728 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-7747df5b674so96834739f.3 for ; Wed, 24 May 2023 09:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684946253; x=1687538253; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NEGQ5q36FskjGnSXMfn598/YoxoWWeRzqtvoB7clJY0=; b=Z7TyIePlcRJKhtTWV2n9MdDXqHYuMmg/67sHAccQaASbfQwYER+WcsuCt6zcSQnHX0 uLVFv2XHXQv3cKvPzDV1nYgbRUF2rIIdOkrM/qLuVVqATTH+2ExrmcD3Pmrnn9M6rdXC mGpyYnabzXgMlXqRbXAqilY2fiMcRhZpz+YTLCdYQk/5Oz/vjb7kD6kZvM7ZSepn2m0P sB/l9q3pXXKZr7ol7c/qgX9168AkoKr/XAxYq5dVf3LXFJZxkkmM0GDWYyfaMBWj8Byq gYUKrCtRoGvtr+vo+E1+cFNePCQZZhWlbeSDq7521rP/DhVWCY1fofpJjDRBabOEuqpJ aIew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946253; x=1687538253; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NEGQ5q36FskjGnSXMfn598/YoxoWWeRzqtvoB7clJY0=; b=SHiNeAnt1ET3SQDRfu8i026V29K2Vek7ONnEY5XuiYgagovAGvE5/oAxcL5QU2rVn2 HIYeeK4FYr4drIzimHztp12tXSC4UT788uKUSIWA+Mg3GJP5FmJHqoEt+gLIFj8P2hq3 4qJsP+fbQs+hNbTjpEqtN4Cj/8/g2+2r2+V3nGZ0QLwrchu8OqHinCCZOkET5ge7lvQ4 100vio+CAaScelZh4lP8y01b1CLKgILQoMcaYC4LQp/SNoFVoo0djfIDnmJS1alKz32t iPStyouXJv6NpKMNJVY7kWGsK+FVMFRM3/mgOJFkmyG1MbQ7STW6L6MMI0qFD2kvRfmJ taIw== X-Gm-Message-State: AC+VfDzKl+WSkx1iBtPX/oivvHyzmvWZ9jcxAZp3nUzhUCKJkcIXEVik ajkfzIhn+qzKe+VQ/5OVNbIoMEHw3VS5yzX73PwaMw== X-Google-Smtp-Source: ACHHUZ78Xk1ij2mF5B/EIjoKYCP+uiaFRIWr8EtianeJM8LPCipW22s/8Gr9QxDYmDtJKZSYXwHGBA== X-Received: by 2002:a6b:db19:0:b0:769:82a4:4419 with SMTP id t25-20020a6bdb19000000b0076982a44419mr12203230ioc.14.1684946253740; Wed, 24 May 2023 09:37:33 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:33 -0700 (PDT) From: Tom Tromey Date: Wed, 24 May 2023 10:37:07 -0600 Subject: [PATCH 16/25] Use tuples for default arguments in DAP MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20230427-ada-catch-exception-v1-16-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: My co-worker Kévin taught me that using a mutable object as a default argument in Python is somewhat dangerous, because the object is created a single time (when the function is defined), and so if it is mutated in the body of the function, the changes will stick around. This patch changes the cases like this in DAP to use () rather than [] as the default. This patch is merely preventative, as no bugs like this are in the code. --- gdb/python/lib/gdb/dap/breakpoint.py | 4 ++-- gdb/python/lib/gdb/dap/launch.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index 877069f79a5..8ffa1829031 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -96,7 +96,7 @@ def _set_breakpoints(kind, specs): @request("setBreakpoints") -def set_breakpoint(*, source, breakpoints=[], **args): +def set_breakpoint(*, source, breakpoints=(), **args): if "path" not in source: result = [] else: @@ -188,7 +188,7 @@ def _set_exception_catchpoints(filter_options): "label": "Ada exceptions", "supportsCondition": True, })) -def set_exception_breakpoints(*, filters, filterOptions=[], **args): +def set_exception_breakpoints(*, filters, filterOptions=(), **args): # Convert the 'filters' to the filter-options style. options = [{"filterId": filter} for filter in filters] options.extend(filterOptions) diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index a46be1dcca2..dc4bf3c6d15 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -36,7 +36,7 @@ def _set_args_env(args, env): # from implementations. Any additions or changes here should be # documented in the gdb manual. @request("launch") -def launch(*, program=None, args=[], env=None, **extra): +def launch(*, program=None, args=(), env=None, **extra): if program is not None: global _program _program = program -- 2.40.0