Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Gort, klaatu nikto barada." -- The Day the Earth Stood Still


devel / comp.lang.python / Re: PyObject_CallFunctionObjArgs segfaults

SubjectAuthor
o Re: PyObject_CallFunctionObjArgs segfaultsMRAB

1
Re: PyObject_CallFunctionObjArgs segfaults

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: python@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: PyObject_CallFunctionObjArgs segfaults
Date: Fri, 30 Sep 2022 01:33:54 +0100
Lines: 115
Message-ID: <mailman.505.1664498037.20444.python-list@python.org>
References: <ND8xHA---3-2@tutanota.com>
<fbd7fcc1-6095-e381-4721-bc5c09975202@mrabarnett.plus.com>
<ND9prTQ--3-2@tutanota.com-ND9qgBV----2> <ND9zJoA--7-2@tutanota.com>
<b60d1d3b-1381-8646-fd43-15496bf993dd@mrabarnett.plus.com>
<NDAPOvd--3-2@tutanota.com>
<aadf0f47-468b-158e-a0fc-82bb72fa2b98@mrabarnett.plus.com>
<4e8fa90c-6f59-1999-93bc-2a31ba14c12e@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de PMJPVKih7P5VRNdNZkL/iwFSLCR9U0gJ/i2EoZRdq1rw==
Return-Path: <python@mrabarnett.plus.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=plus.com header.i=@plus.com header.b=E/BOxA3b;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.006
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'comments': 0.03;
'from:addr:python': 0.09; 'received:192.168.1.64': 0.09; '[snip]':
0.16; 'comment.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16;
'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'received:plus.net': 0.16; 'reference,': 0.16; 'solved': 0.16;
'wrote:': 0.16; 'api': 0.17; 'values': 0.17; 'probably': 0.17;
'to:addr:python-list': 0.20; "i've": 0.22; 'problem,': 0.22;
'skip:p 30': 0.23; 'anyone': 0.25; 'else': 0.27; 'it,': 0.29;
'header:User-Agent:1': 0.30; 'needed,': 0.32;
'received:192.168.1': 0.32; 'but': 0.32; 'hold': 0.33; 'header:In-
Reply-To:1': 0.34; "it's": 0.37; 'received:192.168': 0.37;
'could': 0.38; 'means': 0.38; 'helps': 0.60; 'reference': 0.60;
'received:212': 0.62; 'once': 0.63; 'longer': 0.71; 'required)':
0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1664498035; bh=ZdddfqILnjwd4EX4/15VcXtfvFmmoPfTg3XDQzeoIvY=;
h=Date:Subject:To:References:From:In-Reply-To;
b=E/BOxA3bA+XcyrY+wj3HIc7iHCYvpoyZgyNiSIZvOdfI8hJVnDfTB35xqYSSlXqB5
ifeSJmUvebFKuhmS/Xi2ECQp0siDAwiraa3Qc8ePS8b8Mu24SXBkwI87msJ/7T8qwj
OR+ZKK1pFJvfMytp86UGlYaDW6CKSIJDVEbhLs7pFuAxCQBscTCstx+yqYy3wKXkoF
6b2lcFQDmXpRxYMG5Sy9IGh6ak9DtBr7jh6w/EEnYKNR29tENSHPQmDWmbuV4ow5pV
HQxZ6Lzqq6kfILRZ5b/oEqMzWX6Ut5q1zBjQMoVFzdsPNqAqlaPvyPShfJVGFli8hF
TbBS5CsPySD1w==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=VODOIvDX c=1 sm=1 tr=0 ts=63363973
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=88bQf-Rr20jH_dmX-a8A:9 a=QEXdDO2ut3YA:10
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.0
Content-Language: en-GB
In-Reply-To: <aadf0f47-468b-158e-a0fc-82bb72fa2b98@mrabarnett.plus.com>
X-CMAE-Envelope: MS4xfOBzh9qNImIuE20GGRj54vaW1dDhQcHSDnqhFdRwvgpbCl5gG15SZec7KrCsR98QDIq2ySdjkfOpcaWFRkdvXwgRT4Mw1/WxET5jzcpY0Zn2vzaUjQmc
5SeaD7MFk438Lq3HPPe5Acgsei18XRe6lNfEyiQCD0ROgN1AixMz6wN4BTsIM0FzlJpQaO5fI+PZZExnFvIalyr6Bw1oUpSRCRg=
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: <4e8fa90c-6f59-1999-93bc-2a31ba14c12e@mrabarnett.plus.com>
X-Mailman-Original-References: <ND8xHA---3-2@tutanota.com>
<fbd7fcc1-6095-e381-4721-bc5c09975202@mrabarnett.plus.com>
<ND9prTQ--3-2@tutanota.com-ND9qgBV----2> <ND9zJoA--7-2@tutanota.com>
<b60d1d3b-1381-8646-fd43-15496bf993dd@mrabarnett.plus.com>
<NDAPOvd--3-2@tutanota.com>
<aadf0f47-468b-158e-a0fc-82bb72fa2b98@mrabarnett.plus.com>
 by: MRAB - Fri, 30 Sep 2022 00:33 UTC

On 2022-09-30 01:02, MRAB wrote:
> On 2022-09-29 23:41, Jen Kris wrote:
>>
>> I just solved this C API problem, and I’m posting the answer to help
>> anyone else who might need it.
>>
[snip]

What I like to do is write comments that state which variables hold a
reference, followed by '+' if it's a new reference (incref'ed) and '?'
if it could be null. '+?' means that it's probably a new reference but
could be null. Once I know that it's not null, I can remove the '?', and
once I've decref'ed it (if required) and no longer need it, I remobe it
from the comment.

Clearing up references, as soon as they're not needed, helps to keep the
number of current references more manageable.

int64_t Get_LibModules(int64_t * return_array) {
PyObject * pName_random = PyUnicode_FromString("random");
//> pName_random+?
if (!pName_random) {
PyErr_Print();
return 1;
}

//> pName_random+
PyObject * pMod_random = PyImport_Import(pName_random);
//> pName_random+ pMod_random+?
Py_DECREF(pName_random);
//> pMod_random+?
if (!pMod_random) {
PyErr_Print();
return 1;
}

//> pMod_random+
PyObject * pAttr_seed = PyObject_GetAttrString(pMod_random, "seed");
//> pMod_random+ pAttr_seed?
if (!pAttr_seed) {
Py_DECREF(pMod_random);
PyErr_Print();
return 1;
}

//> pMod_random+ pAttr_seed
PyObject * pAttr_randrange = PyObject_GetAttrString(pMod_random,
"randrange");
//> pMod_random+ pAttr_seed pAttr_randrange?
Py_DECREF(pMod_random);
//> pAttr_seed pAttr_randrange?
if (!pAttr_randrange) {
PyErr_Print();
return 1;
}

//> pAttr_seed pAttr_randrange
return_array[0] = (int64_t)pAttr_seed;
return_array[1] = (int64_t)pAttr_randrange;

return 0;
}

int64_t C_API_2(PyObject * pAttr_seed, Py_ssize_t value_1) {
PyObject * value_ptr = PyLong_FromLong(value_1);
//> value_ptr+?
if (!!value_ptr) {
PyErr_Print();
return 1;
}

//> value_ptr+
PyObject * p_seed_calc = PyObject_CallFunctionObjArgs(pAttr_seed,
value_ptr, NULL);
//> value_ptr+ p_seed_calc+?
Py_DECREF(value_ptr);
//> p_seed_calc+?
if (!p_seed_calc) {
PyErr_Print();
return 1;
}

//> p_seed_calc+
Py_DECREF(p_seed_calc);
return 0;
}

int64_t C_API_12(PyObject * pAttr_randrange, Py_ssize_t value_1) {
PyObject * value_ptr = PyLong_FromLong(value_1);
//> value_ptr+?
if (!value_ptr) {
PyErr_Print();
return 1;
}

//> value_ptr+
PyObject * p_randrange_calc =
PyObject_CallFunctionObjArgs(pAttr_randrange, value_ptr, NULL);
//> value_ptr+ p_randrange_calc+?
Py_DECREF(value_ptr);
//> p_randrange_calc+?
if (!p_randrange_calc) {
PyErr_Print();
return 1;
}

//Prepare return values
//> p_randrange_calc+
return_val = PyLong_AsLong(p_randrange_calc);
Py_DECREF(p_randrange_calc);

return return_val;
}


devel / comp.lang.python / Re: PyObject_CallFunctionObjArgs segfaults

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor