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

Fix segfault when passing empty StringIO/File object to Font #2548

Merged
merged 10 commits into from
Nov 6, 2023

Conversation

MyreMylar
Copy link
Member

@MyreMylar MyreMylar commented Nov 4, 2023

Related to #2295

Also fixes freetype submodule's Font to track submodule generation on __new__ instead of on __init__ for more reliable performance of the unit tests with uninitialized Font objects. Previously I was getting different results running on the CI versus locally.

@MyreMylar MyreMylar added the font pygame.font label Nov 4, 2023
@MyreMylar MyreMylar requested a review from a team as a code owner November 4, 2023 21:53
@MyreMylar
Copy link
Member Author

I also fixed two unrelated freetype module tests here that I noticed were failing locally while testing - but were not failing on the CI.

At some point a fix that was added for a quit() and init() segfault and the way the tests multithread on the CI causes these two particular tests which I changed, which use a class level __new__ constructor, to give one exception on the CI (that the module has been quit before the 'font' is created) and a different exception locally (the exceptions these tests were originally designed to capture).

It is not a real functional change but it means we can get these tests to pass both locally and on the CI.

@MyreMylar MyreMylar changed the title Fix segfault when passing empty String/File object to Font Fix segfault when passing empty StringIO/File object to Font Nov 5, 2023
test/freetype_test.py Outdated Show resolved Hide resolved
Copy link
Member

@ankith26 ankith26 left a comment

Choose a reason for hiding this comment

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

Thanks! Approving this PR because this LGTM, but I wonder if this is something that should also be fixed upstream on SDL_ttf if this is an issue on their end?

Copy link
Member

@ankith26 ankith26 left a comment

Choose a reason for hiding this comment

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

Another improvement idea, we should use SDL_RWsize(source) instead of doing source->size(source). Shorter and also looks more robust

@MyreMylar
Copy link
Member Author

Another improvement idea, we should use SDL_RWsize(source) instead of doing source->size(source). Shorter and also looks more robust

This function is available since SDL 2.0.10.
https://wiki.libsdl.org/SDL2/SDL_RWsize

@ankith26 ankith26 added this to the 2.4.0 milestone Nov 6, 2023
@ankith26 ankith26 added the bugfix PR that fixes bug label Nov 6, 2023
@ankith26 ankith26 merged commit 1e6e651 into main Nov 6, 2023
29 checks passed
@ankith26 ankith26 deleted the font-segfault-empty-StringIO branch November 6, 2023 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix PR that fixes bug font pygame.font
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants