Sujet : Re: do { quit; } else { }
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.cDate : 06. Apr 2025, 03:58:39
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vssqkv$3v4ts$2@dont-email.me>
References : 1
User-Agent : Pan/0.162 (Pokrosvk)
On Fri, 4 Apr 2025 16:23:30 -0300, Thiago Adams wrote:
What do you think of this control block?
Stick to standard C:
1: Initialize a pointer variable to `NULL`
2: Allocate memory for the pointer (this might fail)
3: Correctly free the pointer memory, regardless of allocation
success/failure
Specifically:
PyObject * obj = NULL; /* step 1 */
do /*once*/
{
... possible other stuff ...
allocate obj; /* step 2 */
if (PyErr_Occurred())
break;
... possible other stuff using obj ...
/* all done */
result = tempresult;
tempresult = NULL; /* so I don’t dispose of it yet */
}
while (false);
Py_XDECREF(obj); /* step 3 */