From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00364e01.pphosted.com (mx0b-00364e01.pphosted.com [148.163.139.74]) by sourceware.org (Postfix) with ESMTPS id 4D06D385AC09 for ; Wed, 23 Aug 2023 21:16:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D06D385AC09 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=columbia.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=columbia.edu Received: from pps.filterd (m0167076.ppops.net [127.0.0.1]) by mx0b-00364e01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37NKUQiM021600 for ; Wed, 23 Aug 2023 17:16:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; h=mime-version : references : in-reply-to : from : date : message-id : subject : to : cc : content-type : content-transfer-encoding; s=pps01; bh=cSaRKywWwUNAyETnZoA69xcLaIOHxYNfT0o/FRJ+e6c=; b=YQReBFnP1e/HxuEc8cYFsWmq9+hSu0C3SUxOj3TBcaoTdaQts6iK8NXaVO9Ojqjv1oRH VaXZQ3Irqe4eXtmJWW29EowUb0NRWctRy4duv1DVkzdDQC9Fi+3B7qFctttLk8+lAP0c gsNSFzZYGddYgscy/TWDBQQfBjxgXVnekBte6ACEKMggCwoPeR/ZcQX/z8wSHpHvKAVL VxyMQLvuKP9jPmj0GraeCh5STYKPIllkb2YLPL1mOJRatet4hlOVGRQfeqwYfBZjk8Hl +Mt5ggBOEHN78Wu88nPSvwJLY9BYUd8HnpIu4fJTZgU6kHFBlO+tKCp64Z5Om7p9lOR6 Jg== Received: from mail-ua1-f69.google.com (mail-ua1-f69.google.com [209.85.222.69]) by mx0b-00364e01.pphosted.com (PPS) with ESMTPS id 3sn20cg9xp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 23 Aug 2023 17:16:03 -0400 Received: by mail-ua1-f69.google.com with SMTP id a1e0cc1a2514c-7a03982450eso2453097241.3 for ; Wed, 23 Aug 2023 14:16:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692825363; x=1693430163; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cSaRKywWwUNAyETnZoA69xcLaIOHxYNfT0o/FRJ+e6c=; b=YgxDZl0gmvhVhBiaLN66rfkFLb418DTPScSH1nl9EK1pOae0Nl4OsjYzO6k3DqqxXc fvLOks6ptEQGf4Ajc4LOCxqmkchpdFhHWf4/Nnl4m9om8rSt0SAbgimw9sNN/VZK4UPU kqWxVTin+RYEONUClxIeQqGcFL/DOfX1VH1qlqBJiuxMx8+hxYiE67CJRpQ85zxUBwQ2 qE3gjcsMfaFX35AuIUjtqmU7gXHA7TupmlyeSYZ6aDD73XhNjA110NF161UuzzSiZSZy DC6xf4lyJBxsDIeZuaRsS2ePtPK6OKx66JYp0cJ1EdVFuAyTyYX3LbBdNPqNY1B+mgns lV+g== X-Gm-Message-State: AOJu0YxBUZ2aA80gVaK7RUET2P2WEBvR0PVpLoLq99bJR5Xh0e5L4bKj u/jPE0cukB6YSTw28PJmUMDF0vSD1xKqJ20AdInlI/rRAsJOgssWuti10wOZzET+8xelxXGJGsV cGx/OKJLaBlMgrSFpzkfb X-Received: by 2002:a05:6102:503:b0:44d:4e57:5c4f with SMTP id l3-20020a056102050300b0044d4e575c4fmr10313168vsa.33.1692825362977; Wed, 23 Aug 2023 14:16:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKRANUXArHg0fmAeL6IqKa6yCFRUb8kvaQcocFal2H6gkEaj3XTM3xInCOFmMRGKXVH5AlMSJWXKQHy5OyvUU= X-Received: by 2002:a05:6102:503:b0:44d:4e57:5c4f with SMTP id l3-20020a056102050300b0044d4e575c4fmr10313156vsa.33.1692825362743; Wed, 23 Aug 2023 14:16:02 -0700 (PDT) MIME-Version: 1.0 References: <20230816191711.39268-1-ef2648@columbia.edu> <755975d612a449027a1f605d950161ef9b62a72f.camel@redhat.com> In-Reply-To: From: Eric Feng Date: Wed, 23 Aug 2023 17:15:51 -0400 Message-ID: Subject: Re: Update on CPython Extension Module -fanalyzer plugin development To: David Malcolm Cc: gcc@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: 5QZKg-JdsCW5uFFoVH62NS0K4jUe-0dX X-Proofpoint-ORIG-GUID: 5QZKg-JdsCW5uFFoVH62NS0K4jUe-0dX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-23_15,2023-08-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 bulkscore=10 adultscore=0 mlxscore=0 mlxlogscore=925 spamscore=0 malwarescore=0 lowpriorityscore=10 clxscore=1015 impostorscore=10 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308230191 X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Aug 21, 2023 at 11:04=E2=80=AFAM David Malcolm wrote: > > On Mon, 2023-08-21 at 10:05 -0400, Eric Feng wrote: > > Hi Dave, > > > > Just wanted to give you and everyone else a short update on how > > reference count checking is going =E2=80=94 we can now observe the refc= nt > > diagnostic being emitted: > > > > rc3.c:22:10: warning: REF COUNT PROBLEM > > 22 | return list; > > | ^~~~ > > =E2=80=98create_py_object=E2=80=99: events 1-4 > > | > > | 4 | PyObject* item =3D PyLong_FromLong(3); > > | | ^~~~~~~~~~~~~~~~~~ > > | | | > > | | (1) when =E2=80=98PyLong_FromLong=E2=80= =99 succeeds > > | 5 | PyObject* list =3D PyList_New(1); > > | | ~~~~~~~~~~~~~ > > | | | > > | | (2) when =E2=80=98PyList_New=E2=80=99 s= ucceeds > > |...... > > | 14 | PyList_Append(list, item); > > | | ~~~~~~~~~~~~~~~~~~~~~~~~~ > > | | | > > | | (3) when =E2=80=98PyList_Append=E2=80=99 fails > > |...... > > | 22 | return list; > > | | ~~~~ > > | | | > > | | (4) here > > | > > > > I will fix up and refactor the logic for counting the actual ref > > count > > before coming back and refining the diagnostic to give much more > > detailed information. > > Excellent! Thanks for the update. > > Dave > Hi Dave, I've since fixed up the logic to count the actual reference counts of the PyObject* instances. Now, I'm contemplating the specific diagnostics we'd want to issue and the appropriate conditions for emitting them. With this in mind, I wanted to check in with you on the appropriate approach: To start, I'm adopting the same assumptions as cpychecker for functions returning a PyObject*. That is, I'm operating under the premise that by default such functions return a new reference upon success rather than, for example, a borrowed reference (which we can tackle later on). Given this, it's my understanding that the reference count of the returned object should be 1 if the object is newly created within the function body and incremented by 1 from what it was previously if not newly created (e.g passed in as an argument). Furthermore, the reference count for any PyObject* instances created within the function should be 0, barring situations where we're returning a collection, like a list, that includes references to these objects. Let me know what you think; thanks! Best, Eric