Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-46315: Use fopencookie() to avoid dup() in _PyTokenizer_FindEncodingFilename #32033

Merged
merged 4 commits into from
Mar 22, 2022

Conversation

tiran
Copy link
Member

@tiran tiran commented Mar 21, 2022

@pablogsal pablogsal added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 21, 2022
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @pablogsal for commit 6be12fc 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 21, 2022
// cookie is just the fd
borrowed b;
b.fd = fd;
return fopencookie(b.cookie, "r", cookie_io);
Copy link
Member

Choose a reason for hiding this comment

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

fopencookie is a non-standard GNU extension. Is this available in all platforms targetted by web assembly? Does this need a configure check?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had a configure check in my first version of the patch. I got rid of it because it makes no sense. Both WASI and Emscripten use musl libc as upper half of libc and it always provides fdopencookie.

I wish their was a more elegant way to solve the problem. _PyTokenizer_FindEncodingFilename uses a FILE pointer instead of a file descriptor.

Copy link
Member

Choose a reason for hiding this comment

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

Ugh, I am honestly not very happy with the amount of extra code, but I understand why is needed.

@tiran
Copy link
Member Author

tiran commented Mar 22, 2022

The failing tests on macOS ARM64 and FreeBSD are unrelated to my changes.

Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

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

The code looks good to me, but I had no way to test it myself, so I am not formally approving. Feel free to land if you want though

@tiran tiran changed the title bpo-46315: Use fdopencookie() to avoid dup() in _PyTokenizer_FindEncodingFilename bpo-46315: Use fopencookie() to avoid dup() in _PyTokenizer_FindEncodingFilename Mar 22, 2022
@tiran
Copy link
Member Author

tiran commented Mar 22, 2022

I can shorten the code. fopencookie handles NULL function pointers correctly. Our code only needs a read callback.

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.

4 participants