pyfst
pyfst copied to clipboard
Segmentation fault in copy constructor of StdTransducer
Although I cannot find it in the API description (http://pyfst.github.io/api.html) it looks like there exists a copy constructor for the StdTransducer and StdAcceptor classes. However, when I am trying to initialize a new object like that I get a segmentation fault. Example:
>>> import fst
>>> x= fst.StdTransducer()
>>> x.add_arc(0,0,'1','0')
>>> x[0].final = True
>>> y = fst.StdTransducer(x)
Segmentation fault: 11
Is this a bug, or I am doing something unexpected for the library?
Thanks!
That looks like it should work to me, given the code in line 338 oneward in _fst.pyx.tpl
.
On Fri, Sep 18, 2015 at 6:04 PM, GeorgeArgyros [email protected] wrote:
Although I cannot find it in the API description ( http://pyfst.github.io/api.html) it looks like there exists a copy constructor for the StdTransducer and StdAcceptor classes. However, when I am trying to initialize a new object like that I get a segmentation fault. Example:
import fst x= fst.StdTransducer() x.add_arc(0,0,'1','0') x[0].final = True y = fst.StdTransducer(x) Segmentation fault: 11
Is this a bug, or I am doing something unexpected for the library?
Thanks!
— Reply to this email directly or view it on GitHub https://github.com/vchahun/pyfst/issues/25.
Yes, this is how I figured out that a copy constructor exists in the first place. However, I am getting the seg fault mentioned above. I am running pyfst on OSX Yosemite btw.
I can replicate the segmentation fault.
You are correct that such behavior is indicated to be supported by the cython code. However, looking at https://github.com/vchahun/pyfst/blob/master/fst/init.py#L8, the initialization function that is actually used does not match the one in cython code. Namely, it does not anticipate a source parameter. Also, notice that https://github.com/vchahun/pyfst/blob/master/fst/_fst.pyx.tpl#L342 does not actually try and copy the source FST, but rather tries to copy itself. Since up to that point, self.fst has not been assigned yet, I believe that is what produces the segmentation fault.
I tried to fix this behavior but unfortunately couldn't. An easy workaround is to use:
>>> import fst
>>> x= fst.StdTransducer()
>>> x.add_arc(0,0,'1','0')
>>> x[0].final = True
>>> y = x.copy()