From 85a9e820dc94d4bf44414fb2caea894fc9c95480 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 8 Jan 2016 21:36:42 +0900 Subject: [PATCH] Fix Sphinx crashes if mecab initialization failed --- CHANGES | 3 ++- sphinx/search/ja.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 70c1e9fa8..8979c4049 100644 --- a/CHANGES +++ b/CHANGES @@ -39,7 +39,8 @@ Bugs fixed * #1580: Fix paragraphs in longtable don't work in Latex output * #1366: Fix centered image not centered in latex * #1860: Fix man page using ``:samp:`` with braces - font doesn't reset -* #1610 Sphinx crashes in japanese indexing in some systems. +* #1610: Sphinx crashes in japanese indexing in some systems +* Fix Sphinx crashes if mecab initialization failed Release 1.3.3 (released Dec 2, 2015) ==================================== diff --git a/sphinx/search/ja.py b/sphinx/search/ja.py index 5ccff34b6..3acbb649a 100644 --- a/sphinx/search/ja.py +++ b/sphinx/search/ja.py @@ -29,6 +29,7 @@ try: except ImportError: native_module = False +from sphinx.errors import SphinxError from sphinx.search import SearchLanguage @@ -93,7 +94,9 @@ class MecabBinder(object): self.ctypes_libmecab.mecab_new2.restype = ctypes.c_void_p self.ctypes_libmecab.mecab_sparse_tostr.argtypes = (ctypes.c_void_p, ctypes.c_char_p) self.ctypes_libmecab.mecab_sparse_tostr.restype = ctypes.c_char_p - self.ctypes_mecab = ctypes.c_void_p(self.ctypes_libmecab.mecab_new2(param.encode(fs_enc))) + self.ctypes_mecab = self.ctypes_libmecab.mecab_new2(param.encode(fs_enc)) + if self.ctypes_mecab is None: + raise SphinxError('mecab initialization failed') def __del__(self): if self.ctypes_libmecab: