From d563f1eadb965de5dc09536cc8c6263277b864fe Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Fri, 28 Oct 2016 17:42:00 +0200 Subject: [PATCH] Fix Issue #587: Segfault in Matcher, due to simple error in the state machine. --- spacy/matcher.pyx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spacy/matcher.pyx b/spacy/matcher.pyx index de7622dca..7279b003c 100644 --- a/spacy/matcher.pyx +++ b/spacy/matcher.pyx @@ -1,4 +1,5 @@ # cython: profile=True +# cython: infer_types=True from __future__ import unicode_literals from os import path @@ -277,6 +278,8 @@ cdef class Matcher: # we over-write them (q doesn't advance) for state in partials: action = get_action(state.second, token) + if action == PANIC: + raise Exception("Error selecting action in matcher") while action == ADVANCE_ZERO: state.second += 1 action = get_action(state.second, token) @@ -288,6 +291,7 @@ cdef class Matcher: elif action == REJECT: pass elif action == ADVANCE: + partials[q] = state partials[q].second += 1 q += 1 elif action == ACCEPT: @@ -307,6 +311,8 @@ cdef class Matcher: # Check whether we open any new patterns on this token for pattern in self.patterns: action = get_action(pattern, token) + if action == PANIC: + raise Exception("Error selecting action in matcher") while action == ADVANCE_ZERO: pattern += 1 action = get_action(pattern, token)