[egenix-users] SIGSEGV in mxTextTools when using AppendToTagobj

RICHARD MOSELEY dickie.moseley at virgin.net
Thu May 17 11:12:10 CEST 2012

I have just been spending time compiling the mxTextTools library into the
latest version of the SimpleParse package in a python 2.7.3 virtualenv. The
original packaged mxTextTools was 2.1.0 from 2003, so I decided to use the
latest 3.2.4 package instead; after making all the appropriate changes and
compiling, I then ran the test suite that is in the SimpleParse package,
after running a few of the test the program failed with a SIGSEGV.

I tracked down the problem test to the testAppendToTagobj1 test in the
mx_flag.py suite of tests and more specifically the testAppendToTagobj1
test, I took the test out of the test suite and created a simple test file
as follows:

from simpleparse.stt.TextTools import *
class Test(object):
  worked = ""
  def append(self, value):
    worked = value
tagobj = Test()
result = tag('abbaabccd',((tagobj,AllIn+AppendToTagobj,'ab',0),),0)
print result

When this is run from within the virtualenv I got the following error:

(oratools)rmos at spot$ python /tmp/chktext.py
Fatal Python error: stt/TextTools/mxTextTools/mxte_impl.h:1301 object at
0x242f5b0 has negative ref count -1

Reviewing the code around the stated line 1301 in mxte_impl.h gives the
following code within the TE_HANDLE_MATCH function:

if (flags & MATCH_APPENDTAG) {
        if (PyList_Check(tagobj)) {
            if (PyList_Append(tagobj, w)) {
                goto onError;
        else {
            PyObject *result;
            result = PyEval_CallMethod(tagobj, "append", "(O)", w);
            if (result == NULL)
                goto onError;
        Py_DECREF(w);   <-- INCORRECT
        return 0;
The problem with the code is that in the case of the tag object not beign a
list the temporary 'w' object is DECREF'ed twice if the append is

I commented out the extra call of Py_DECREF(w) and reran the test script,
and it returned:

(oratools)rmos at spot2: python /tmp/chktext.py
(1, [], 6)

which is what is by the original test.

I though that I should share this with you, in the hope that this will
remove at least one cause of SIGSEGV in the mxTextTools package.

Richard Moseley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /mailman-archives/egenix-users/attachments/20120517/7b339b1a/attachment.htm

More information about the egenix-users mailing list