From 0f2a32479cee90dafb7b60fab7de7d77b2f2a628 Mon Sep 17 00:00:00 2001 From: "Marshall T. Vandegrift" Date: Mon, 15 Dec 2008 22:40:43 -0500 Subject: [PATCH 1/2] 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 = '' From c82d2d5d13a3a8aef6473bc01cb6d791313fc883 Mon Sep 17 00:00:00 2001 From: "Marshall T. Vandegrift" Date: Tue, 16 Dec 2008 17:58:20 -0500 Subject: [PATCH 2/2] Fix 32-bit correctness error. --- src/calibre/utils/lzx/compressor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/utils/lzx/compressor.c b/src/calibre/utils/lzx/compressor.c index ee4436d4d6..cf3c3f6e92 100644 --- a/src/calibre/utils/lzx/compressor.c +++ b/src/calibre/utils/lzx/compressor.c @@ -175,7 +175,7 @@ mark_frame(void *context, uint32_t uncomp, uint32_t comp) PyObject *rtable = self->rtable; PyObject *entry = NULL; - entry = Py_BuildValue("(LL)", uncomp, comp); + entry = Py_BuildValue("(II)", uncomp, comp); if (entry) { PyList_Append(rtable, entry); Py_DECREF(entry);