From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4KZzKLSqsmCyBAAAWB0awg (envelope-from ) for ; Sat, 29 May 2021 16:57:24 -0400 Received: by simark.ca (Postfix, from userid 112) id A38F01F11C; Sat, 29 May 2021 16:57:24 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,RDNS_DYNAMIC,T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.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 4057D1E813 for ; Sat, 29 May 2021 16:57:23 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E99103886C4B; Sat, 29 May 2021 20:57:22 +0000 (GMT) Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id D481C385802D for ; Sat, 29 May 2021 20:57:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D481C385802D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x42c.google.com with SMTP id n2so6779731wrm.0 for ; Sat, 29 May 2021 13:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WQHFylW5iiZLMFK4XvVaB7g4kbyuSoKQ0nPq6PRp/5I=; b=MyUQpob5HvNJq/0DgLfyrqsZjHwgqqq/+4rP54fKt1JZYIQTx9/NtEI9Fm4Q8mVmMQ 4fWfAsz9yIyfyADqk5vd567M4HfGUmdiveFPcLUlOSumrN0Y4XzYg9VqScu4v/RtD9w+ uijFuA73IGPyrJsA8+46szZa9ZmNqjIdy/2HO4VctkYvX5E+TGFlaCywfmyZIxXKMCCP htinqE78JFNzKSoZ+F4myQ4dsZLIpdrkUmyThjokYKOBcdGuoPQm5rDOP1TJrWCtE/Lu pT55AkyrF+7KeE4eij4o45HF4HBM5uv6AmT4hblawyYakL0bmAZBM03ZqsTD+eF8r1OH wI7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WQHFylW5iiZLMFK4XvVaB7g4kbyuSoKQ0nPq6PRp/5I=; b=eaMhwa57MSD/Ucx6B4cB4TS8zc9FGcL5P52J+E5yMBqFz7/dWGWsZn1Pe8P4p3bAci /FkTAAOioNqq+lYqPop0INOF/zpXVhz4SXi1Am09BYoT1SrYJnESnKAKKjQnuav+H27p DXd/gz5YVObAl2Y7eXvhZzcYcPzufvKkR5pUPi/L8X1rxbNzKF6fO1/E7ohzlK24ubsD kEThgwdcgwjFsDiQTnate2GlFlEt11lwVvW+fRLAASHzFc69WBH2QOb4Mw6A6tYt/bv+ SHD/QSjJa7C7RAq1n/LomMdLH72xWX2z+14t02Ci5C8Q4McxMhLt3z9d+n953Lk4IBzz Utsg== X-Gm-Message-State: AOAM531TVEjcse5n1Zg2hOdFhIJMgDL4WrchIAM4/eKC3K2uBI+xgsy8 iylgca/kJrwtT0+XwJGr1YKWV0T1RlHEgA== X-Google-Smtp-Source: ABdhPJwv3U/o6aQPzCvlEOd+5sb+FXwwn7473DVlcbo5FJvy+R4Rh9ZNG5UVgwl58RJ+lMwwuoTuEA== X-Received: by 2002:adf:dcd2:: with SMTP id x18mr14714330wrm.202.1622321839771; Sat, 29 May 2021 13:57:19 -0700 (PDT) Received: from localhost (host109-151-46-70.range109-151.btcentralplus.com. [109.151.46.70]) by smtp.gmail.com with ESMTPSA id p16sm11576115wrs.52.2021.05.29.13.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 May 2021 13:57:19 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH 2/5] gdb/python: move PyLong_From* calls into py-utils.c Date: Sat, 29 May 2021 21:57:11 +0100 Message-Id: <2e8e11d00b1eea71a99a49d5860deb3392372c91.1622321523.git.andrew.burgess@embecosm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" We already have two helper functions in py-utils.c: gdb_py_object_from_longest (LONGEST l) gdb_py_object_from_ulongest (ULONGEST l) these wrap around calls to either PyLong_FromLongLong, PyLong_FromLong, or PyInt_From_Long (if Python 2 is being used). There is one place in gdb/python/* where a call to PyLong_FromLong was added outside of the above utility functions, this was done in the recent commit: commit 55789354fcbaf879f3ca8475b647b2747dec486e Date: Fri May 14 11:56:31 2021 +0200 gdb/python: add a 'connection_num' attribute to Inferior objects In this commit I propose that we move this new call to PyLong_FromLong into a new utility function gdb_py_object_from_int. The biggest win I see here is that we have a consistent interface for converting number like things into Python objects, however, I have made it such that on Python 2 we will call PyInt_FromLong, so there is a slight change in behaviour here, which seems to be inline with how we handle the LONGEST types. Beyond the PyLong/PyInt change described above there should be no user visible changes from this commit. gdb/ChangeLog: * python/py-inferior.c (infpy_get_connection_num): Call new function gdb_py_object_from_int. * python/py-utils.c (gdb_py_object_from_int): New function. * python/python-internal.h (gdb_py_object_from_int): Declare. --- gdb/ChangeLog | 7 +++++++ gdb/python/py-inferior.c | 2 +- gdb/python/py-utils.c | 12 ++++++++++++ gdb/python/python-internal.h | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 336c6426b8c..bdbde0b3e61 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -441,7 +441,7 @@ infpy_get_connection_num (PyObject *self, void *closure) if (target == nullptr) Py_RETURN_NONE; - return PyLong_FromLong (target->connection_number); + return gdb_py_object_from_int (target->connection_number).release (); } static PyObject * diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 10c4173efcd..c3f712debcb 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -335,6 +335,18 @@ gdb_py_object_from_ulongest (ULONGEST l) #endif } +/* Convert an int I to the appropriate Python object. */ + +gdbpy_ref<> +gdb_py_object_from_int (int i) +{ +#ifdef IS_PY3K + return gdbpy_ref<> (PyLong_FromLong (i)); +#else + return gdbpy_ref<> (PyInt_FromLong (l)); +#endif +} + /* Like PyInt_AsLong, but returns 0 on failure, 1 on success, and puts the value into an out parameter. */ diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 690d2fb43c0..91b5bea58eb 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -747,6 +747,8 @@ int get_addr_from_python (PyObject *obj, CORE_ADDR *addr) gdbpy_ref<> gdb_py_object_from_longest (LONGEST l); gdbpy_ref<> gdb_py_object_from_ulongest (ULONGEST l); +gdbpy_ref<> gdb_py_object_from_int (int i); + int gdb_py_int_as_long (PyObject *, long *); PyObject *gdb_py_generic_dict (PyObject *self, void *closure); -- 2.25.4