[sword-devel] Python segfaults on OS X using Sword
Ben Morgan
benpmorgan at gmail.com
Thu Feb 7 15:43:59 MST 2008
Hi,
Try this:
filtermgr = Sword.MarkupFilterMgr(Sword.FMT_OSIS)
filtermgr.thisown = False
instead of just this:
filtermgr = Sword.MarkupFilterMgr(Sword.FMT_OSIS)
When you pass it in, SWORD will delete it in the SWMgr destructor,
which is where the segfault has happened. However, SWIG will already
have deleted it because it found no references to it in python. You
have to tell swig not to delete it, and setting thisown to false will
do that. This is true for any sword objects you create from python,
but pass into sword classes which will clean them up.
When you find it segfaulting, there is a good chance that SWIG has
cleaned up something it shouldn't have.
God Bless,
Ben
-------------------------------------------------------------------------------------------
The Lord is not slow to fulfill his promise as some count slowness,
but is patient toward you, not wishing that any should perish,
but that all should reach repentance.
2 Peter 3:9 (ESV)
On Feb 8, 2008 2:07 AM, Jon Brisbin <jon at jbrisbin.com> wrote:
> I'm experimenting with the Python SWIG interface built from 1.5.10
> source on OS X 10.5.1. If I do things from the command line,
> interactively, all seems well. But if I run the following script, it
> segfaults Python with the following stack trace:
>
> SCRIPT:
>
> #!/usr/bin/python
> import Sword
> from Ft.Xml import InputSource, Sax
>
> class element_counter:
> def startDocument(self):
> self.ecount = 0
>
> def startElementNS(self, name, qname, attribs):
> self.ecount += 1
>
> parser = Sax.CreateParser()
> handler = element_counter()
> parser.setContentHandler(handler)
>
> filtermgr = Sword.MarkupFilterMgr(Sword.FMT_OSIS)
> mgr = Sword.SWMgr("/Users/jbrisbin/Library/sword/share/sword", True,
> filtermgr, True, False)
> mod = mgr.getModule("ESV")
> key = Sword.SWKey("Jn 3:16")
> mod.setKey(key)
>
> txt = '<?xml version="1.0"?>' + mod.RenderText()
> print txt
>
> factory = InputSource.DefaultFactory
> isrc = factory.fromString(txt)
> parser.parse(isrc)
> print "Elements counted:", handler.ecount
>
>
> STACKTRACE:
>
> Process: Python [52417]
> Path: /System/Library/Frameworks/Python.framework/Versions/
> 2.5/Resources/Python.app/Contents/MacOS/Python
> Identifier: Python
> Version: ??? (???)
> Code Type: X86 (Native)
> Parent Process: bash [52282]
>
> Date/Time: 2008-02-07 09:00:06.923 -0600
> OS Version: Mac OS X 10.5.1 (9B18)
> Report Version: 6
>
> Exception Type: EXC_BAD_ACCESS (SIGSEGV)
> Exception Codes: KERN_INVALID_ADDRESS at 0x00000000c0000007
> Crashed Thread: 0
>
> Thread 0 Crashed:
> 0 libsword-1.5.10.dylib 0x00594155 sword::SWMgr::~SWMgr() +
> 181
> 1 _Sword.so 0x00407a55 _wrap_delete_SWMgr + 303
> (Sword.cxx:1216)
> 2 org.python.python 0x0011fd5d PyObject_Call + 50
> 3 org.python.python 0x00120056
> PyObject_CallFunctionObjArgs + 70
> 4 _Sword.so 0x004158e9 PySwigObject_dealloc +
> 109 (Sword.cxx:1441)
> 5 org.python.python 0x0014788d _PyDict_Next + 279
> 6 org.python.python 0x0015d20a PyType_GenericNew + 1258
> 7 org.python.python 0x00146e76 PyDict_New + 1286
> 8 org.python.python 0x001473ea PyDict_SetItem + 255
> 9 org.python.python 0x0014a930 _PyModule_Clear + 413
> 10 org.python.python 0x0019d649 PyImport_Cleanup + 518
> 11 org.python.python 0x001a7787 Py_Finalize + 247
> 12 org.python.python 0x001b3d4f Py_Main + 3395
> 13 org.python.pythonapp 0x00001fca 0x1000 + 4042
>
> Thread 0 crashed with X86 Thread State (32-bit):
> eax: 0xc0000003 ebx: 0x005940ab ecx: 0x00000000 edx: 0x00378710
> edi: 0x0037af70 esi: 0x0037dc20 ebp: 0xbffff2c8 esp: 0xbffff290
> ss: 0x0000001f efl: 0x00010202 eip: 0x00594155 cs: 0x00000017
> ds: 0x0000001f es: 0x0000001f fs: 0x00000000 gs: 0x00000037
> cr2: 0xc0000007
>
> Binary Images:
> 0x1000 - 0x1ffe org.python.pythonapp 2.5.0 (2.5.0a0)
> <fccdb19d43071ba163b93b4fddd2a7d0> /System/Library/Frameworks/
> Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python
> 0xa3000 - 0xa8fff _socket.so ??? (???)
> <8a76493385dadf7704e8bc24262283d1> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_socket.so
> 0xaf000 - 0xb0fff _ssl.so ??? (???)
> <3aceee1559e328aeebd7d8c581672440> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_ssl.so
> 0xc7000 - 0xc8ffc _locale.so ??? (???)
> <e4f2d3f735f04b48639c3b4a165bce10> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_locale.so
> 0x118000 - 0x1e3ffb org.python.python 2.5 (2.5)
> <ce7182a9e975861a321dfeeca76f54db> /System/Library/Frameworks/
> Python.framework/Versions/2.5/Python
> 0x230000 - 0x232fff operator.so ??? (???)
> <a215c2c29d729159721cdf5dbe9bb12a> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/operator.so
> 0x23d000 - 0x23fffb _struct.so ??? (???)
> <b434ba0164e7837947859e5d28ccacb1> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_struct.so
> 0x243000 - 0x244fff time.so ??? (???)
> <abe3cbc29d1200671a826ed5639404c6> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/time.so
> 0x24a000 - 0x24bfff cStringIO.so ??? (???)
> <43a7d4df1bbeb69a4e75917070d41bd0> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/cStringIO.so
> 0x24f000 - 0x251ffd strop.so ??? (???)
> <368d8f646651c0bb5e77f518587296b9> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/strop.so
> 0x297000 - 0x2c2ffb libcurl.4.dylib ??? (???)
> <54ada27deb3b4ff7043d8836264eca0d> /usr/lib/libcurl.4.dylib
> 0x2d5000 - 0x2d6ffe binascii.so ??? (???)
> <534f894f5102efd2c66cea89278b4224> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/binascii.so
> 0x2db000 - 0x2dcffd _hashlib.so ??? (???)
> <f2f4363127b079545d6ec42234490f4f> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_hashlib.so
> 0x2e0000 - 0x2e3ffe _sha256.so ??? (???)
> <6dba0a1bf62501099cd13fb386547538> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_sha256.so
> 0x2e7000 - 0x2f4ffd _sha512.so ??? (???)
> <391fac08716595df15fe628d13da119a> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_sha512.so
> 0x2f8000 - 0x2f9fff math.so ??? (???)
> <d96fd9d52167d2a1cc33fa704762c167> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/math.so
> 0x400000 - 0x4e4fff +_Sword.so ??? (???)
> <cb8413a737cd514b02712dae17aedef9> /Users/jbrisbin/Projects/scriptures/
> ws/_Sword.so
> 0x57f000 - 0x633fff +libsword-1.5.10.dylib ??? (???) /Users/
> jbrisbin/Library/sword/lib/libsword-1.5.10.dylib
> 0x7d8000 - 0x7d9fff _random.so ??? (???)
> <f1a90330f912b3724902282313c60ef1> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_random.so
> 0x7dd000 - 0x7ddffd fcntl.so ??? (???)
> <55376a4a0ccdc8557363a1fb16d59ba9> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/fcntl.so
> 0x7e1000 - 0x7e1ffd _bisect.so ??? (???)
> <b20350d6a0912cc9c972abd47dfb1beb> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_bisect.so
> 0x7e5000 - 0x7e6ffd +XmlString.so ??? (???)
> <23267d9e13e3f7d065f8077723403b87> /Library/Python/2.5/site-packages/
> Ft/Xml/Lib/XmlString.so
> 0x7eb000 - 0x7f0ffe pyexpat.so ??? (???)
> <d54bdc9a7ccbfb80f2b9f068af162592> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/pyexpat.so
> 0x7f5000 - 0x7f6fff collections.so ??? (???)
> <81a9e184cbc9bfb7b66baaac805f7eb7> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/collections.so
> 0x7fa000 - 0x7fbffc +cStreamWriter.so ??? (???)
> <208ec26bdc2d4c90513a3dbfed6ff536> /Library/Python/2.5/site-packages/
> Ft/Xml/Lib/cStreamWriter.so
> 0x1000000 - 0x109dfef +libclucene.0.dylib ??? (???)
> <3624d0a164b182729af38da3ce042033> /Users/jbrisbin/Library/clucene/lib/
> libclucene.0.dylib
> 0x11d0000 - 0x11eefe3 libexpat.1.dylib ??? (???)
> <eff8a63a23a7d07af62b36fdb329e393> /usr/lib/libexpat.1.dylib
> 0x11fa000 - 0x11fbffe termios.so ??? (???)
> <553bff6fb6aa97220a99ca64cbf0fd0e> /System/Library/Frameworks/
> Python.framework/Versions/2.5/lib/python2.5/lib-dynload/termios.so
> 0x1400000 - 0x143efe7 +cDomlettec.so ??? (???)
> <b8ab8284d10e474865733d3efd282be3> /Library/Python/2.5/site-packages/
> Ft/Xml/cDomlettec.so
> 0x8fe00000 - 0x8fe2d883 dyld 95.3 (???)
> <3896c718b33f3e065e199a659baf1a2b> /usr/lib/dyld
> 0x90091000 - 0x900eeffb libstdc++.6.dylib ??? (???)
> <04b812dcec670daa8b7d2852ab14be60> /usr/lib/libstdc++.6.dylib
> 0x90976000 - 0x9099afeb libssl.0.9.7.dylib ??? (???)
> <acee7fc534674498dcac211318aa23e8> /usr/lib/libssl.0.9.7.dylib
> 0x9099b000 - 0x90af5fe3 libSystem.B.dylib ??? (???)
> <08d9ec2f36455fc197b9b44adf62f304> /usr/lib/libSystem.B.dylib
> 0x91046000 - 0x91054ffd libz.1.dylib ??? (???)
> <5ddd8539ae2ebfd8e7cc1c57525385c7> /usr/lib/libz.1.dylib
> 0x91c3c000 - 0x91c43fe9 libgcc_s.1.dylib ??? (???)
> <a9ab135a5f81f6e345527df87f51bfc9> /usr/lib/libgcc_s.1.dylib
> 0x91eb8000 - 0x91f68fff edu.mit.Kerberos 6.0.11 (6.0.11)
> <33c25789baedcd70a7e24881775dd9ad> /System/Library/Frameworks/
> Kerberos.framework/Versions/A/Kerberos
> 0x93378000 - 0x93379fef libmathCommon.A.dylib ??? (???) /usr/lib/
> system/libmathCommon.A.dylib
> 0x9337a000 - 0x9342cffb libcrypto.0.9.7.dylib ??? (???)
> <330b0e48e67faffc8c22dfc069ca7a47> /usr/lib/libcrypto.0.9.7.dylib
> 0x94638000 - 0x94662fef libauto.dylib ??? (???)
> <d468bc4a8a69343f1748c293db1b57fb> /usr/lib/libauto.dylib
> 0x94f0f000 - 0x94feefff libobjc.A.dylib ??? (???)
> <5eda47fec2d0e7853b3506aa1fd2dafa> /usr/lib/libobjc.A.dylib
> 0x9535b000 - 0x95524fef com.apple.security 5.0.1 (32736)
> <8c9eda0fcc1d8a571543025ac900715f> /System/Library/Frameworks/
> Security.framework/Versions/A/Security
> 0x95a76000 - 0x95ba8fe7 com.apple.CoreFoundation 6.5 (476)
> <8bfebc0dbad6fc33bea0fa00a1b9ec37> /System/Library/Frameworks/
> CoreFoundation.framework/Versions/A/CoreFoundation
> 0x95c47000 - 0x95d7fff7 libicucore.A.dylib ??? (???)
> <afcea652ff2ec36885b2c81c57d06d4c> /usr/lib/libicucore.A.dylib
> 0x96587000 - 0x965a5fff libresolv.9.dylib ??? (???)
> <8538164a282c147c3543550ae49d4bd4> /usr/lib/libresolv.9.dylib
> 0xfffe8000 - 0xfffebfff libobjc.A.dylib ??? (???) /usr/lib/
> libobjc.A.dylib
> 0xffff0000 - 0xffff1780 libSystem.B.dylib ??? (???) /usr/lib/
> libSystem.B.dylib
>
>
> Thanks!
>
> Jon Brisbin
> http://jbrisbin.com
>
>
>
>
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page
>
More information about the sword-devel
mailing list