GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-30555: Fix WindowsConsoleIO errors in the presence of fd redirection by segevfiner · Pull Request #1927 · python/cpython Conversation
| |||||||||||||||||||||||||||||||||
|
@segevfiner, thanks for your PR! By analyzing the history of the files in this pull request, we identified @zooba, @benjaminp and @serhiy-storchaka to be potential reviewers. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Most of the reference leaks are due to initializing Some of the reported ref leaks are from calling |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
_Py_get_osfhandle, _Py_get_osfhandle_noraise, _Py_open_osfhandle, and _Py_open_osfhandle_noraise could be added in Python/fileutils.c. These CRT functions are called in fileutils.c, msvcrtmodule.c, posixmodule.c, mmapmodule.c, myreadline.c, _testconsole.c, and here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
Do you wish me to:
?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I implemented this, with the full replacement in a separate commit just in case it's frowned upon by a core developer during review.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@eryksun So the leaks are real than, nice find! 😄 I can submit a PR/issue with your suggested fix if it helps you or just leave it to you. Why would calling EDIT: I can also apply your fix right here if you wish me to. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It should be ok to fix the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…tion This works by not caching the handle and instead getting the handle from the file descriptor each time, so that if the actual handle changes by fd redirection closing/opening the console handle beneath our feet, we will keep working correctly. I think I also fixed some resource handling issues along the way since ucrt/msvcrt fds *own* the HANDLEs they use and this module tried to close them itself.
The change in test_winconsoleio.py is only to avoid the ref leak in `sys.getwindowsversion`.
ac3af9e to
aaf6020
Compare
| PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking); | ||
| #endif /* !MS_WINDOWS */ | ||
| #else /* MS_WINDOWS */ | ||
| PyAPI_FUNC(intptr_t) _Py_get_osfhandle_noraise(int fd); |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I thought one of benefits would be using HANDLE in the signature instead of intptr_t, to avoid all of the casts. I guess we can't. How about void * like _PyOS_SigintEvent?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think CPython explicity doesn't include Windows.h anywhere in it's public headers. fileutils.h is included by Python.h so I don't think I can really include Windows.h there. Ae such I don't have HANDLE defined and assuming that someone included Windows.h by himself before this header breaks horribly of course.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
HANDLE is a typedef for void *, so we can use void * instead, like _PyOS_SigintEvent does.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
50ff023 to
7727bc5
Compare
| @@ -167,15 +167,7 @@ static long | |||
| msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags) | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The clinic definition could be updated here, e.g. to use a HANDLE type based on void *:
class HANDLE_converter(CConverter):
type = 'void *'
format_unit = '"_Py_PARSE_INTPTR"'
class HANDLE_return_converter(CReturnConverter):
type = 'void *'
def render(self, function, data):
self.declare(data)
self.err_occurred_if("_return_value == INVALID_HANDLE_VALUE", data)
data.return_conversion.append(
'return_value = PyLong_FromVoidPtr(_return_value);\n')
Then change the open_osfhandle parameter to handle: HANDLE and the get_osfhandle return type to -> HANDLE.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…consoleio-fd-redirection
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…consoleio-fd-redirection
|
Merged from master due to argument clinic changes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…consoleio-fd-redirection
…consoleio-fd-redirection
…consoleio-fd-redirection
c3953d5 to
2d252ab
Compare
…consoleio-fd-redirection
Co-authored-by: Eryk Sun <[email protected]>
|
Thanks for persisting with this, and sorry for taking so long! Let's put it in and deal with any fallout in 3.10 before backporting. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @segevfiner for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @segevfiner for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @segevfiner and @zooba, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry @segevfiner and @zooba, I had trouble checking out the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @segevfiner for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @segevfiner for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @segevfiner and @zooba, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry @segevfiner and @zooba, I had trouble checking out the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.