From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 41797 invoked by alias); 9 Feb 2017 16:18:02 -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 41701 invoked by uid 89); 9 Feb 2017 16:17:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.2 required=5.0 tests=AWL,BAYES_50,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=H*u:1.2.3, H*UA:1.2.3, HX-PHP-Originating-Script:rcube.php, sk:substit X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 09 Feb 2017 16:17:48 +0000 Received: by simark.ca (Postfix, from userid 33) id C1A581EA09; Thu, 9 Feb 2017 11:17:46 -0500 (EST) To: Pedro Alves Subject: Re: [PATCH 1/5] Introduce specialized versions of gdbpy_ref X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 09 Feb 2017 16:18:00 -0000 From: Simon Marchi Cc: Simon Marchi , gdb-patches@sourceware.org In-Reply-To: <5bc0d9b3-f863-0f3d-00d8-67ca81d8f549@redhat.com> References: <20170123224004.8893-1-simon.marchi@ericsson.com> <20170123224004.8893-2-simon.marchi@ericsson.com> <5bc0d9b3-f863-0f3d-00d8-67ca81d8f549@redhat.com> Message-ID: <7ba500c23d1b0ac8e964b87c489a0afc@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.2.3 X-IsSubscribed: yes X-SW-Source: 2017-02/txt/msg00229.txt.bz2 On 2017-02-09 06:58, Pedro Alves wrote: > 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 Thanks! This kind of thing doesn't come to me naturally yet. > Though I still wonder whether just inheriting our objects from > PyObject wouldn't make things simpler. I'll have to try that. Thanks, Simon