Deutsch English Français Italiano |
<vssqkv$3v4ts$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Lawrence D'Oliveiro <ldo@nz.invalid> Newsgroups: comp.lang.c Subject: Re: do { quit; } else { } Date: Sun, 6 Apr 2025 02:58:39 -0000 (UTC) Organization: A noiseless patient Spider Lines: 27 Message-ID: <vssqkv$3v4ts$2@dont-email.me> References: <vspbjh$8dvd$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sun, 06 Apr 2025 04:58:40 +0200 (CEST) Injection-Info: dont-email.me; posting-host="c047f83780d867d0a7ba2f0a8fb3be95"; logging-data="4166588"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/YuFXo3+ybnPhKJwJzL4a" User-Agent: Pan/0.162 (Pokrosvk) Cancel-Lock: sha1:io58LhwztPUoSxvoGGI01+3Iz80= Bytes: 1664 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 */