From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15094 invoked by alias); 9 Feb 2017 11:58:36 -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 15067 invoked by uid 89); 9 Feb 2017 11:58:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=sk:substit, Hx-languages-length:1431, PyObject, pyobject X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 09 Feb 2017 11:58:25 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B3C6C05AA41; Thu, 9 Feb 2017 11:58:25 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v19BwNjH013079; Thu, 9 Feb 2017 06:58:24 -0500 Subject: Re: [PATCH 1/5] Introduce specialized versions of gdbpy_ref To: Simon Marchi , gdb-patches@sourceware.org References: <20170123224004.8893-1-simon.marchi@ericsson.com> <20170123224004.8893-2-simon.marchi@ericsson.com> Cc: Simon Marchi From: Pedro Alves Message-ID: <5bc0d9b3-f863-0f3d-00d8-67ca81d8f549@redhat.com> Date: Thu, 09 Feb 2017 11:58:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170123224004.8893-2-simon.marchi@ericsson.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-02/txt/msg00215.txt.bz2 On 01/23/2017 10:40 PM, Simon Marchi wrote: > > We must make sure to only use gdbpy_ref_base on objects that actually > are Python objects. For example, gdbpy_ref_base would make > not sense. Since the "inheritance" from the PyObject type is done in a > C way (using PyObject_HEAD), I don't know how we can check at > compile-time that we are not using it with a wrong type. If you have an > idea on how to do that, let me know. We would need to check that there > exists a field named ob_base. Bonus points for ensuring that its type > is PyObject. More bonus points for ensuring that it's the first field > in the structure. You can do all this with SFINAE. For the "is first field check, you could use something like "(PyObject*) this == &this->ob_base" as expression, I think. https://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error There are many examples around the web, if you search for SFINAE and "C++ check if member exists", etc. E.g,: http://stackoverflow.com/questions/1005476/how-to-detect-whether-there-is-a-specific-member-variable-in-class Though I still wonder whether just inheriting our objects from PyObject wouldn't make things simpler. > For convenience, I added a get_py_obj method to gdbpy_ref_base, which > returns the pointer casted to PyObject*, something we need to do > relatively often). Thanks, Pedro Alves