Skip to content

Make PyInitConfig_Free(NULL) a no-op #125234

@serhiy-storchaka

Description

@serhiy-storchaka

Feature or enhancement

I think that it would simplify the code if make PyInitConfig_Free(NULL) a no-op. Currently it requires the argument to be non-NULL. This would simplify the code:

PyInitConfig *config = NULL;
// some code
if (error_occurred) {
    goto Error;
}
config = PyInitConfig_Create();
if (config == NULL) {
    goto Error;
}
// some other code
if (error_occurred) {
    goto Error;
}
// more code
Error:
// release resources
if (config == NULL) {
    PyInitConfig_Free(config);
}
// release resources

Most Python resources are represented as Python objects, so Py_XDECREF(NULL) works for them. PyMem_Free(NULL) and PyRawMem_Free(NULL) work for raw memory blocks. PyInitConfig_Free() is one of few (or only one) API that cannot be used in such idiom.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixestopic-C-APItype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions