Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Man will never fly. Space travel is merely a dream. All aspirin is alike.


devel / comp.lang.python / Re: Puzzling behaviour of Py_IncRef

SubjectAuthor
o Re: Puzzling behaviour of Py_IncRefTony Flury

1
Re: Puzzling behaviour of Py_IncRef

<mailman.227.1642602139.3079.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21175&group=comp.lang.python#21175

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: tony.flury@btinternet.com (Tony Flury)
Newsgroups: comp.lang.python
Subject: Re: Puzzling behaviour of Py_IncRef
Date: Wed, 19 Jan 2022 14:22:10 +0000
Lines: 47
Message-ID: <mailman.227.1642602139.3079.python-list@python.org>
References: <042d2815-628c-e6b1-1eda-1e385dc26bcc@btinternet.com>
<CAPTjJmq==4CHdPU2GiXefPG+OUG-jA6LRqWdxDxkdzjdTccANw@mail.gmail.com>
<e640d910-50e6-7485-db97-e1a7b62339e0@btinternet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de Iu2uXNamiAPx61+tUd4RzgIlX39Bi3bUeIW0krB9XmCg==
Return-Path: <tony.flury@btinternet.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=btinternet.com header.i=@btinternet.com header.b=JQJ6/rP+;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.022
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '2022': 0.05; 'exit': 0.07;
'explicitly': 0.07; 'angelico': 0.09; 'effectively': 0.09; 'skip:*
30': 0.09; 'behaviour': 0.16; 'chrisa': 0.16; 'indeed': 0.16;
'reference,': 0.16; 'static': 0.16; 'wrote:': 0.16; 'to:addr
:python-list': 0.20; 'code': 0.23; 'extension': 0.25; 'object':
0.26; 'function': 0.27; 'chris': 0.28; 'header:User-Agent:1':
0.30; '(as': 0.32; 'point,': 0.32; 'python-list': 0.32;
'returning': 0.32; 'received:192.168.1': 0.32; 'but': 0.32;
'header:In-Reply-To:1': 0.34; 'count': 0.36; 'change': 0.36;
'received:192.168': 0.37; 'wed,': 0.39; 'still': 0.40;
'received:213': 0.40; 'should': 0.40; 'reference': 0.60; "you'd":
0.64; 'your': 0.64; 'order': 0.69; 'subsequent': 0.76; 'breaking':
0.78; 'puzzled': 0.84; 'tony': 0.84; 'return.': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com;
s=btmx201904; t=1642602132;
bh=Rj9M2uh5bw8NpMAx4ouFz46KnHnTwRQXl7LD4CqzIH4=;
h=Subject:To:References:From:Message-ID:Date:MIME-Version:In-Reply-To;
b=JQJ6/rP+VKzXyduc9ES0+oY23PG6OXRVAftDsyh38XdH3xkALy6Q6i41LqgLTh2SZUonbBDxSNLNu50oBIuz1gCUu8i0wjztf1slL9Pm9jX2xcTZCBAgCrTG0K0LVA75y4Mv5iKkNnFKHeSSPAFuEVNz6/1Bqawo+Tj1LDZuTxvMQ2B18bhDpUp8ySnAS2LlgV2GLMG3jZH1uGQ8SXAcH5asdc+JVHNn0BeggcelmKTiQWcKPm452aZx4hBFQuJ+VIBizvyXQdOLN5dvninM61moYYeddqorcP6wnWN+C2R2QgNnwKFfpSf5mktlP6DVMcIgyJR8eEVspFOAfJVcDw==
Authentication-Results: btinternet.com;
auth=pass (PLAIN) smtp.auth=tony.flury@btinternet.com;
bimi=skipped
X-SNCR-Rigid: 613943C611D0AC8A
X-Originating-IP: [81.153.144.133]
X-OWM-Source-IP: 81.153.144.133 (GB)
X-OWM-Env-Sender: tony.flury@btinternet.com
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvvddrudeigddtgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemuceutffkvffkuffjvffgnffgvefqofdpqfgfvfenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomhepvfhonhihucfhlhhurhihuceothhonhihrdhflhhurhihsegsthhinhhtvghrnhgvthdrtghomheqnecuggftrfgrthhtvghrnhepueeggfeigfehuddulefhtdekfedthedutdfghfduveeitedvfeegfedvgfejudeknecukfhppeekuddrudehfedrudeggedrudeffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhephhgvlhhopegludelvddrudeikedruddrjeeingdpihhnvghtpeekuddrudehfedrudeggedrudeffedpmhgrihhlfhhrohhmpehtohhnhidrfhhluhhrhiessghtihhnthgvrhhnvghtrdgtohhmpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepphihthhhohhnqdhlihhsthesphihthhhohhnrdhorhhgpdhrtghpthhtoheprhhoshhurghvsehgmhgrihhlrdgtohhm
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-SNCR-hdrdom: btinternet.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
In-Reply-To: <CAPTjJmq==4CHdPU2GiXefPG+OUG-jA6LRqWdxDxkdzjdTccANw@mail.gmail.com>
Content-Language: en-US
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <e640d910-50e6-7485-db97-e1a7b62339e0@btinternet.com>
X-Mailman-Original-References: <042d2815-628c-e6b1-1eda-1e385dc26bcc@btinternet.com>
<CAPTjJmq==4CHdPU2GiXefPG+OUG-jA6LRqWdxDxkdzjdTccANw@mail.gmail.com>
 by: Tony Flury - Wed, 19 Jan 2022 14:22 UTC

On 19/01/2022 11:09, Chris Angelico wrote:
> On Wed, Jan 19, 2022 at 10:00 PM Tony Flury via Python-list
> <python-list@python.org> wrote:
>> Extension function :
>>
>> static PyObject *_Node_test_ref_count(PyObject *self)
>> {
>> printf("\nIncrementing ref count for self - just for the hell
>> of it\n");
>> printf("\n before self has a ref count of %ld\n", Py_REFCNT(self));
>> Py_INCREF(self);
>> printf("\n after self has a ref count of %ld\n", Py_REFCNT(self));
>> fflush(stdout);
> At this point, the refcount has indeed been increased.
>
>> return self;
>> }
> And then you say "my return value is this object".
>
> The normal thing to do is to add a reference to whatever you're
> returning. For instance, Py_RETURN_NONE will incref None and then
> return it.
>
> So you're incrementing the refcount, then returning it without
> incrementing the refcount. Your code is actually equivalent to "return
> self".
>
> In order to actually leak a reference, you'd need to incref it twice.
>
> ChrisA

Chris - I am still puzzled - does  doing 'return self' automatically
decrement the ref count of the object ?, and why is that the desired
behaviour ? Effectively it results in a decrement of two, since at the
exit of the function the ref count is only 1 (as witnessed by the
subsequent call to assertEqual).

(I am not suggesting that it should be changed - I understand that would
be a breaking change !).

You say I am returning it without incrementing, but I am explicitly
incrementing it before the return.


devel / comp.lang.python / Re: Puzzling behaviour of Py_IncRef

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor