From patchwork Thu Dec 27 19:26:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 30869 Received: (qmail 16470 invoked by alias); 27 Dec 2018 19:26:52 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 16331 invoked by uid 89); 27 Dec 2018 19:26:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=questionable X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.231) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Dec 2018 19:26:49 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway34.websitewelcome.com (Postfix) with ESMTP id C2BF0620CB5 for ; Thu, 27 Dec 2018 13:26:47 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id cbItgeuXZYTGMcbItgShFc; Thu, 27 Dec 2018 13:26:47 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type: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=0K+7wojHRzrDi9esJtb8NN2mIXAd1aYGEL/XWPGrJkI=; b=B4mLPLPCgyIxTLkdHElLjwLebr JymH5TGJs1uN9dWPAkBmAgHYrwC3cRd4/iy+S5hnFtC4xyxRKmwdiXvCCsz5jdTlgdUEQUVpy1sJP q9aCf/ZSg6dcpkU039sY4THe/; Received: from 75-166-72-210.hlrn.qwest.net ([75.166.72.210]:47364 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gcbIt-0004pC-8m; Thu, 27 Dec 2018 13:26:47 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 5/5] Avoid questionable casts in py-symtab.c Date: Thu, 27 Dec 2018 12:26:37 -0700 Message-Id: <20181227192637.17862-6-tom@tromey.com> In-Reply-To: <20181227192637.17862-1-tom@tromey.com> References: <20181227192637.17862-1-tom@tromey.com> py-symtab.c has some questionable casts of Py_None to symtab_object*. This patch avoids these casts by instead using downcasts at the appropriate places. 2018-12-27 Tom Tromey * python/py-symtab.c (salpy_str): Update. (struct salpy_sal_object) : Now a PyObject. (salpy_dealloc): Update. (del_objfile_sal): Use gdbpy_ref. --- gdb/ChangeLog | 7 +++++++ gdb/python/py-symtab.c | 39 +++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c index d1326e3e67..1b7aa2b02a 100644 --- a/gdb/python/py-symtab.c +++ b/gdb/python/py-symtab.c @@ -58,7 +58,7 @@ static const struct objfile_data *stpy_objfile_data_key; typedef struct salpy_sal_object { PyObject_HEAD /* The GDB Symbol table structure. */ - symtab_object *symtab; + PyObject *symtab; /* The GDB Symbol table and line structure. */ struct symtab_and_line *sal; /* A Symtab and line object is associated with an objfile, so keep @@ -227,8 +227,13 @@ salpy_str (PyObject *self) SALPY_REQUIRE_VALID (self, sal); sal_obj = (sal_object *) self; - filename = (sal_obj->symtab == (symtab_object *) Py_None) - ? "" : symtab_to_filename_for_display (sal_obj->symtab->symtab); + if (sal_obj->symtab == Py_None) + filename = ""; + else + { + symtab *symtab = symtab_object_to_symtab (sal_obj->symtab); + filename = symtab_to_filename_for_display (symtab); + } return PyString_FromFormat ("symbol and line for %s, line %d", filename, sal->line); @@ -323,9 +328,10 @@ salpy_dealloc (PyObject *self) if (self_sal->prev) self_sal->prev->next = self_sal->next; - else if (self_sal->symtab != (symtab_object * ) Py_None) - set_objfile_data (SYMTAB_OBJFILE (self_sal->symtab->symtab), - salpy_objfile_data_key, self_sal->next); + else if (self_sal->symtab != Py_None) + set_objfile_data + (SYMTAB_OBJFILE (symtab_object_to_symtab (self_sal->symtab)), + salpy_objfile_data_key, self_sal->next); if (self_sal->next) self_sal->next->prev = self_sal->prev; @@ -343,11 +349,11 @@ salpy_dealloc (PyObject *self) static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION set_sal (sal_object *sal_obj, struct symtab_and_line sal) { - symtab_object *symtab_obj; + PyObject *symtab_obj; if (sal.symtab) { - symtab_obj = (symtab_object *) symtab_to_symtab_object (sal.symtab); + symtab_obj = symtab_to_symtab_object (sal.symtab); /* If a symtab existed in the sal, but it cannot be duplicated, we exit. */ if (symtab_obj == NULL) @@ -355,7 +361,7 @@ set_sal (sal_object *sal_obj, struct symtab_and_line sal) } else { - symtab_obj = (symtab_object *) Py_None; + symtab_obj = Py_None; Py_INCREF (Py_None); } @@ -367,16 +373,17 @@ set_sal (sal_object *sal_obj, struct symtab_and_line sal) /* If the SAL does not have a symtab, we do not add it to the objfile cleanup observer linked list. */ - if (sal_obj->symtab != (symtab_object *)Py_None) + if (sal_obj->symtab != Py_None) { + symtab *symtab = symtab_object_to_symtab (sal_obj->symtab); + sal_obj->next - = ((struct salpy_sal_object *) - objfile_data (SYMTAB_OBJFILE (sal_obj->symtab->symtab), - salpy_objfile_data_key)); + = ((struct salpy_sal_object *) objfile_data (SYMTAB_OBJFILE (symtab), + salpy_objfile_data_key)); if (sal_obj->next) sal_obj->next->prev = sal_obj; - set_objfile_data (SYMTAB_OBJFILE (sal_obj->symtab->symtab), + set_objfile_data (SYMTAB_OBJFILE (symtab), salpy_objfile_data_key, sal_obj); } else @@ -491,8 +498,8 @@ del_objfile_sal (struct objfile *objfile, void *datum) { sal_object *next = obj->next; - Py_DECREF (obj->symtab); - obj->symtab = (symtab_object *) Py_None; + gdbpy_ref<> tmp (obj->symtab); + obj->symtab = Py_None; Py_INCREF (Py_None); obj->next = NULL;