- Notifications
You must be signed in to change notification settings - Fork3.9k
Segfault fix in freetype.get_version#3567
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
47b1d7a fixed segfault
oddbookworm2945644 ran formatter
oddbookworm4c452ae cleaned up freetype and changed exception type
oddbookworm4526ab2 added comment explaining code and test for freetype.get_version
oddbookworm53cd9bf formatted
oddbookworm5796d96 edited test
oddbookwormFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
28 changes: 27 additions & 1 deletionsrc_c/_freetype.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2046,8 +2046,34 @@ _ft_get_version(PyObject *self, PyObject *args, PyObject *kwargs) | ||
| } | ||
| if (linked) { | ||
Starbuck5 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| /* | ||
| * The FreeType library is being initialized here separately from the | ||
| * initialization of the `pygame.freetype` module so that the linked | ||
| * version can always be obtained. This does not affect the | ||
| * initialization state of `pygame.freetype` itself. | ||
| * | ||
| * The reason this is needed is because if freetype has not been | ||
| * initialized, then a segmentation fault can happen. The alternative | ||
| * would be to return something predefined to mean something akin to | ||
| * "Unknown", but as this function is meant for debugging purposes, it | ||
| * seems like a good idea to always be able to retrieve the linked | ||
| * FreeType version. | ||
| */ | ||
| FT_Library lib; | ||
| int err = FT_Init_FreeType(&lib); | ||
| if (err) { | ||
| PyErr_SetString(PyExc_RuntimeError, | ||
| "FreeType could not be initialized"); | ||
| FT_Done_FreeType(lib); | ||
| return NULL; | ||
| } | ||
| FT_Int major, minor, patch; | ||
| FT_Library_Version(lib, &major, &minor, &patch); | ||
| FT_Done_FreeType(lib); | ||
| return Py_BuildValue("iii", major, minor, patch); | ||
| } | ||
| else { | ||
2 changes: 1 addition & 1 deletionsrc_c/freetype/ft_wrap.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletionssrc_c/freetype/ft_wrap.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletionstest/freetype_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.