Skip to content

gh-149474: use Py_fopen in Binary{Reader,Writer} for audit hook and path-like support#149524

Open
maurycy wants to merge 3 commits intopython:mainfrom
maurycy:remote-debugger-fopen
Open

gh-149474: use Py_fopen in Binary{Reader,Writer} for audit hook and path-like support#149524
maurycy wants to merge 3 commits intopython:mainfrom
maurycy:remote-debugger-fopen

Conversation

@maurycy
Copy link
Copy Markdown
Contributor

@maurycy maurycy commented May 8, 2026

As a bonus: PEP 446... so that's a hat-trick: 519 + 578 + 446!

Closes #149474

reader->fd = -1; /* Explicit initialization for cleanup safety */
#endif

reader->filename = PyMem_Malloc(strlen(filename) + 1);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's even no single reader of reader->filename

return NULL;
}

writer->filename = PyMem_Malloc(strlen(filename) + 1);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's even no single reader of writer->filename

@maurycy
Copy link
Copy Markdown
Contributor Author

maurycy commented May 8, 2026

cc @ZeroIntensity @sobolevn (you +1 my comment)

Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

/* Add file descriptor-level hints for better kernel I/O scheduling */
#if defined(__linux__) && defined(POSIX_FADV_SEQUENTIAL)
(void)posix_fadvise(reader->fd, 0, 0, POSIX_FADV_SEQUENTIAL);
(void)posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: os_posix_fadvise_impl has two implementation details that this place does not: Py_BEGIN_ALLOW_THREADS is set and async_err = PyErr_CheckSignals() is checked.

Do we need to do this here?


if (writer->fp) {
fclose(writer->fp);
Py_fclose(writer->fp);
Copy link
Copy Markdown
Member

@sobolevn sobolevn May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: why don't we check the return code here? Because the returned type is void?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_remote_debugging.BinaryWriter() bypasses file-open audit hooks (PEP 578)

2 participants