Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
MyreMylar merged 6 commits intopygame:mainfromoddbookworm:freetype_segfault
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletionsrc_c/_freetype.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2046,8 +2046,34 @@ _ft_get_version(PyObject *self, PyObject *args, PyObject *kwargs)
}

if (linked) {
/*
* 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(inst->library, &major, &minor, &patch);
FT_Library_Version(lib, &major, &minor, &patch);

FT_Done_FreeType(lib);

return Py_BuildValue("iii", major, minor, patch);
}
else {
Expand Down
2 changes: 1 addition & 1 deletionsrc_c/freetype/ft_wrap.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -534,10 +534,10 @@ _PGFT_UnloadFont(FreeTypeInstance *ft, pgFontObject *fontobj)
* Library (de)initialization
*
*********************************************************/
FreeTypeInstance *inst = 0;
int
_PGFT_Init(FreeTypeInstance **_instance, int cache_size)
{
FreeTypeInstance *inst = 0;
int error;

inst = _PGFT_malloc(sizeof(FreeTypeInstance));
Expand Down
2 changes: 0 additions & 2 deletionssrc_c/freetype/ft_wrap.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -253,8 +253,6 @@ extern _FreeTypeState _modstate;
* Internal API
**********************************************************/

extern FreeTypeInstance *inst;

/**************************************** General functions ******************/
const char *
_PGFT_GetError(FreeTypeInstance *);
Expand Down
12 changes: 12 additions & 0 deletionstest/freetype_test.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1794,6 +1794,18 @@ def test_get_error(self):

self.assertIsNone(error_msg)

def test_get_version(self):
# Test that get_version() can be called before init()
# Also tests get_version
ft.quit()

# asserting not None just to have a test case
# there is no real fail condition other than
# raising an exception or a segfault, so a tuple of ints
# should be returned in all cases
self.assertIsNotNone(ft.get_version(linked=False))
self.assertIsNotNone(ft.get_version(linked=True))


if __name__ == "__main__":
unittest.main()

[8]ページ先頭

©2009-2025 Movatter.jp