Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

%DCL-MEM-BAD, bad memory VMS-F-PDGERS, pudding between the ears


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.265.1643218924.3079.python-list@python.org>

  copy mid

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

  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.fl...@btinternet.com (Tony Flury)
Newsgroups: comp.lang.python
Subject: Re: Puzzling behaviour of Py_IncRef
Date: Wed, 26 Jan 2022 13:15:01 +0000
Lines: 38
Message-ID: <mailman.265.1643218924.3079.python-list@python.org>
References: <112a6b03-9a98-2d12-3492-67e4327ad32f@btinternet.com>
<1DCDD357-E281-4024-95F8-0C9F066F1439@barrys-emacs.org>
<8201bfa3-8626-a509-bbde-801566e2bc33@btinternet.com>
<f5510b80-6ebb-fc45-3a1a-82d8bba37968@mrabarnett.plus.com>
<3d73447c-c793-fb9e-c690-5b6ab2951e31@btinternet.com>
<CAPTjJmo_ai2rOCVQtfH2hWBaFNzAy2kyYY4swakCCELU3fBJ8w@mail.gmail.com>
<a438147e-a493-7bc7-5f6a-5dc6a340eff2@btinternet.com>
Reply-To: tony.flury@btinternet.com
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de aWSvE5v8wUtqrgOlfZjGjwtfuENOGs7pmrhkjoJwD3vg==
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=qPRpFb6f;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: UNSURE 0.270
X-Spam-Level: **
X-Spam-Evidence: '*H*': 0.48; '*S*': 0.02; '2022': 0.05; 'angelico':
0.09; 'problem.': 0.15; 'chrisa': 0.16; 'email)': 0.16;
'intention': 0.16; 'odd': 0.16; 'reference,': 0.16; 'wrote:':
0.16; 'python': 0.16; 'code.': 0.17; "can't": 0.17; 'to:addr
:python-list': 0.20; 'code': 0.23; 'saying': 0.25; 'tried': 0.26;
"wasn't": 0.26; 'function': 0.27; 'chris': 0.28; 'it,': 0.29;
'header:User-Agent:1': 0.30; 'objects': 0.32; 'python-list': 0.32;
'returning': 0.32; 'received:192.168.1': 0.32; 'there': 0.33;
'header:In-Reply-To:1': 0.34; 'count': 0.36; 'using': 0.37;
'received:192.168': 0.37; 'way': 0.38; 'enough': 0.39; 'wed,':
0.39; 'double': 0.40; 'received:213': 0.40; 'want': 0.40; 'try':
0.40; 'should': 0.40; 'reference': 0.60; 'tell': 0.60; "there's":
0.61; 'simply': 0.63; 'email': 0.63; 'clear': 0.64; 'your': 0.64;
'outside': 0.67; 'exactly': 0.68; 'order': 0.69; 'accurately':
0.69; 'you.': 0.71; 'reply-to:no real name:2**0': 0.78; 'header
:Reply-To:1': 0.79; 'reference.': 0.81; 'anthony': 0.84;
'itself.': 0.84; 'leaked': 0.84; 'remained': 0.84; 'taken.': 0.84;
'tony': 0.84; 'deliberately': 0.91; 'intending': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com;
s=btmx201904; t=1643202902;
bh=Qb1X/7NnoG3FttfOPIlz8uemb2So8pUUzAkhlMCCHP8=;
h=Message-ID:Date:MIME-Version:Reply-To:Subject:To:References:From:In-Reply-To;
b=qPRpFb6f1A6Bwrn1vY1KQ619muqqt58UpUHLzTR/Dmc5u1O1ZDVWRdPR2M8fbjDKcCFW7943TvDy6M3X7eQL3G9U/IX+YEdI6LzFGYB503v+Fs5bpEORPt6Nbt4Q0jLgkiGpwAAXDHNEF8VtneEpb93+LJcgn7XAioXFNeLGI2saVgSJIM0krlGNg1Ju+dLG4PjWTT8EjBXLefEJycIIvDkcMFJckgzt6E+HLAi/CA7EvNoVjBXQYYh7TLF6Yea0dBYEB2S5vFQfjqdVxlTdHQy5lyU2UC95sp13Yrg5y1+vOnAGEvaM3Bg9DKKbAO4UAxfwF67aYWQ8Zk0/hjmjkA==
Authentication-Results: btinternet.com;
auth=pass (PLAIN) smtp.auth=tony.flury@btinternet.com;
bimi=skipped
X-SNCR-Rigid: 613943C612B79750
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: gggruggvucftvghtrhhoucdtuddrgedvvddrfedugdeglecutefuodetggdotefrodftvfcurfhrohhfihhlvgemuceutffkvffkuffjvffgnffgvefqofdpqfgfvfenuceurghilhhouhhtmecufedtudenucenucfjughrpefkffggfghruffvfhfhjggtgfesthejredttdefjeenucfhrhhomhepvfhonhihucfhlhhurhihuceothhonhihrdhflhhurhihsegsthhinhhtvghrnhgvthdrtghomheqnecuggftrfgrthhtvghrnhepkefftdeitefghfekleekhfdvtdejhefffeefjeevtddtheethfegvdelkedufffgnecukfhppeekuddrudehfedrudeggedrudeffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhephhgvlhhopegludelvddrudeikedruddrudegjegnpdhinhgvthepkedurdduheefrddugeegrddufeefpdhmrghilhhfrhhomhepthhonhihrdhflhhurhihsegsthhinhhtvghrnhgvthdrtghomhdpnhgspghrtghpthhtohepuddprhgtphhtthhopehphihthhhonhdqlhhishhtsehphihthhhonhdrohhrgh
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:91.0) Gecko/20100101
Thunderbird/91.5.0
Content-Language: en-US
In-Reply-To: <CAPTjJmo_ai2rOCVQtfH2hWBaFNzAy2kyYY4swakCCELU3fBJ8w@mail.gmail.com>
X-Mailman-Approved-At: Wed, 26 Jan 2022 12:42:03 -0500
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: <a438147e-a493-7bc7-5f6a-5dc6a340eff2@btinternet.com>
X-Mailman-Original-References: <112a6b03-9a98-2d12-3492-67e4327ad32f@btinternet.com>
<1DCDD357-E281-4024-95F8-0C9F066F1439@barrys-emacs.org>
<8201bfa3-8626-a509-bbde-801566e2bc33@btinternet.com>
<f5510b80-6ebb-fc45-3a1a-82d8bba37968@mrabarnett.plus.com>
<3d73447c-c793-fb9e-c690-5b6ab2951e31@btinternet.com>
<CAPTjJmo_ai2rOCVQtfH2hWBaFNzAy2kyYY4swakCCELU3fBJ8w@mail.gmail.com>
 by: Tony Flury - Wed, 26 Jan 2022 13:15 UTC

On 26/01/2022 08:20, Chris Angelico wrote:
> On Wed, 26 Jan 2022 at 19:04, Tony Flury via Python-list
> <python-list@python.org> wrote:
>> So according to that I should increment twice if and only if the calling
>> code is using the result - which you can't tell in the C code - which is
>> very odd behaviour.
> No, the return value from your C function will *always* have a
> reference taken. Whether the return value is "used" or just dropped,
> there's always going to be one ref used by the returning itself.
>
> The standard way to return a value is always to incref it, then return
> the pointer. That is exactly equivalent to Python saying "return
> <thing>".
>
> Incrementing twice is ONLY because you want to leak a reference.
>
> ChrisA

Chris,

You keep saying I am leaking a reference - my original code (not the POC
in the email) wasn't intending to leak a reference, it was incrementing
the reference count in order to accurately count references, from other
objects and i needed to double increment there so that the reference
count remained correct outside of the C code.

I did try to be clear - my intention was never to leak a reference (I
have been writing s/w long enough to know leaks are bad) - my POC code
in the original message was the only code which deliberately leaked a
reference in order to simply illustrate the problem.

I do appreciate the help you have tried to give - so thank you.

--
Anthony Flury
email : anthony.flury@btinternet.com

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor