From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15538 invoked by alias); 7 Nov 2016 06:00:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 10527 invoked by uid 89); 7 Nov 2016 05:59:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=Hx-languages-length:1277, manages, H*RU:cmgw2, spots X-HELO: gproxy1.mail.unifiedlayer.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO gproxy1.mail.unifiedlayer.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 Nov 2016 05:57:05 +0000 Received: from CMOut01 (cmgw2 [10.0.90.82]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 7E366177A94 for ; Sun, 6 Nov 2016 22:47:42 -0700 (MST) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id 4tnd1u00Z2f2jeq01tngg7; Sun, 06 Nov 2016 22:47:40 -0700 X-Authority-Analysis: v=2.1 cv=beT4Do/B c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=L24OOQBejmoA:10 a=3QctybO9_PP0IqQ0ywQA:9 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:47918 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c3cmR-0008A3-59 for gdb-patches@sourceware.org; Sun, 06 Nov 2016 22:47:39 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [RFA 00/14] add a smart pointer for PyObject* Date: Mon, 07 Nov 2016 06:00:00 -0000 Message-Id: <1478497656-11832-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c3cmR-0008A3-59 X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya.Home) [174.16.143.211]:47918 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-SW-Source: 2016-11/txt/msg00130.txt.bz2 This patch introduces a new smart pointer that manages a Python reference, and then changes parts of the Python layer to use this new wrapper. Dealing with reference counting in the Python layer has been a consistent source of bugs. It's relatively easy to introduce a memory leak, especially when dealing with an error case. This new class simplifies typical Python-facing code, reducing the chance of such errors. Many spots in gdb's Python layer deal with error-handling by "goto" with a "fail" label; this series removes many such "goto"s. This series provides other sorts of cleanups as well. I avoided introducing changes when an ensure_python_env cleanup was in use locally; throwing an exception across one of these when a gdbpy_reference is in used could change the order of operations, resulting in a Py_DECREF when the GIL is not held. I'm not sure whether this happens in practice but it seemed best not to find out. This is a net code reduction even including the new code and the ChangeLog entries. In the longer run I'd like to remove make_cleanup_py_decref and ensure_python_env. I've built on x86-64 Fedora 24 and run the gdb.python tests locally. I'm also currently sending this through the buildbot. Tom