From 0f2a32479cee90dafb7b60fab7de7d77b2f2a628 Mon Sep 17 00:00:00 2001 From: "Marshall T. Vandegrift" Date: Mon, 15 Dec 2008 22:40:43 -0500 Subject: [PATCH] I've been getting the occasional segfault from the fontconfig code. I noticed that the return values for some of the functions in the segfaulting area where visible in Python as integers, despite most likely frequently being larger than sys.maxint (on my 64-bit platform). Explicitly typing the seemingly offending values appears to have corrected the issue. --- src/calibre/utils/fontconfig.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/calibre/utils/fontconfig.py b/src/calibre/utils/fontconfig.py index 9a6ba01992..8633cb3473 100644 --- a/src/calibre/utils/fontconfig.py +++ b/src/calibre/utils/fontconfig.py @@ -111,9 +111,12 @@ class FcValue(Structure): ('u', _FcValue) ] +class FcObjectSet(Structure): pass + lib = load_library() +lib.FcPatternBuild.restype = POINTER(FcPattern) lib.FcPatternCreate.restype = c_void_p -lib.FcObjectSetCreate.restype = c_void_p +lib.FcObjectSetCreate.restype = POINTER(FcObjectSet) lib.FcFontSetDestroy.argtypes = [POINTER(FcFontSet)] lib.FcFontList.restype = POINTER(FcFontSet) lib.FcNameUnparse.argtypes = [POINTER(FcPattern)] @@ -238,7 +241,7 @@ def files_for_family(family, normalize=True): join() if isinstance(family, unicode): family = family.encode(preferred_encoding) - family_pattern = lib.FcPatternBuild(0, 'family', FcTypeString, family, 0) + family_pattern = lib.FcPatternBuild(0, 'family', FcTypeString, family, None) if not family_pattern: raise RuntimeError('Allocation failure') #lib.FcPatternPrint(family_pattern) @@ -256,8 +259,8 @@ def files_for_family(family, normalize=True): fonts = {} fs = lib.FcFontList(0, family_pattern, oset) font_set = fs.contents - file = pointer(create_string_buffer(chr(0), 5000)) - full_name = pointer(create_string_buffer(chr(0), 200)) + file = pointer(create_string_buffer(5000)) + full_name = pointer(create_string_buffer(200)) weight = c_int(0) slant = c_int(0) fname = ''