[Python-Dev] Cleanup for O&

"Martin v. Löwis" martin at v.loewis.de
Sun May 17 07:03:14 CEST 2009


Issue 6012 proposes to add cleanup support for O& converters;
a first client for this would be PyUnicode_FSConverter. Using
cleanup is always necessary if the conversion function allocates
memory, and a later argument converter fails. The memory allocated
must then be released.

There are three options currently to provide such a function:
1. Make a code O&& with two function pointers. I find that
   too tedious to use.
2. Introduce a new code O$, that takes a O&-style function which,
   in addition, can also be called with a NULL PyObject*, meaning
   that it should cleanup.
3. Extend O& so that its function pointers also support the cleanup
   mode (NULL first argument). Conversion functions that need cleanup
   would have to return a special constant rather than the usual value
   of 1.

In addition, there is also the approach introduced in issue 5990:
4. Users of a conversion function that requires cleanup need to
   initialize the output pointer to NULL, and then release memory
   explicitly when the argument conversion fails.

Which of these do you like best?

Regards,
Martin


More information about the Python-Dev mailing list