X Tutup
Skip to content

Add convenient C API for flushing a file #109611

@serhiy-storchaka

Description

@serhiy-storchaka

When working on the replacement of PySys_GetObject() I noticed a large number of sites (23) that call the flush() method of a file, check the result for error, and decref the returned object. It takes 7 lines of code and requires a temporary variable. There are many variations in writing the same code, so you need to read it carefully to recognize the pattern and ensure that it is correct.

I propose to add convenient function _PyFile_Flush() which calls the method and returns -1 on error and 0 on success. It allows to get rid of temporary variable and write the same code in 3 lines, including the closing }. It is also more recognizable.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup