[Info-vax] BASIC (and Horizon)
Lawrence D'Oliveiro
ldo at nz.invalid
Thu Feb 1 18:59:49 EST 2024
On Thu, 1 Feb 2024 18:40:00 -0500, Arne Vajhøj wrote:
>> const bool parsed_ok = PyArg_ParseTuple(args, "Os", &items, &msg);
>> if (!parsed_ok)
>> {
>> return NULL;
>> }
>>
> That is a common coding convention.
How do you handle nesting? Remember this part?
if (PyDict_SetItem(tempresult, first, second) < 0)
break;
If you did a return instead at that point, it would leak memory.
Note also the handover of ownership after all successful allocations, at
the end of the block:
} /*for*/
if (PyErr_Occurred())
break;
/* all done */
result = tempresult;
tempresult = NULL; /* so I don’t dispose of it yet */
This way, the cleanup at the end does not need to distinguish between
success and failure returns:
Py_XDECREF(tempresult);
return
result;
More information about the Info-vax
mailing list