QT, ctypes dll and SEG Faults

sapsi saptarshi.guha at gmail.com
Sun Aug 17 00:17:25 EDT 2008


On Aug 16, 11:37 pm, sapsi <saptarshi.g... at gmail.com> wrote:
> Hello,
> Below is a small class using ctypes and libspectre to read a
> postscript file.
> My program is a PyQT 4.4 application  and when the user clicks on a
> entry in a QTableWidget, i run
>
> PostScriptImage( filename_as_contained_in_clicked_tableWidgetItem )
> However on i get a segfault while trying document_load.
> Surprisingly, before i run sys.exit(app.exec_()) (i.e before the app
> starts) if run PostScriptImage(command_line_specified_ps_file) it
> works!
>
> I know the ctypes so file works with QT since i wrote an application
> using it, but i hadn't separated the ctypes stuff into separate class
> (i.e the spectre code was in the widget method).
>
> Any ideas why the crash?
>
> Regards
> Saptarshi
> --Python Code--
> class PostScriptImage:
>     def __init__(self,filename):
>         print "Doc New"
>         self.document=libspec.spectre_document_new()
>         print "Load Doc" , filename
>         #############crashed in the following
> line#########################
>         libspec.spectre_document_load(self.document,filename)
>         print "Done load doc"
>         if libspec.spectre_document_status(self.document):
>             return False
>         self.scale=[1.0,1.0]
>         self.quicksetup()
>
>     def quicksetup(self):
>         print "RC"
>         rc=libspec.spectre_render_context_new()
>         print "Get 0th Page"
>         page=libspec.spectre_document_get_page (self.document, 0)
>         if libspec.spectre_document_status(self.document):
>             raise Exception("Spectre:Setup Document Error")
>         w= c_int()
>         h= c_int()
>         print "Page Size"
>         libspec.spectre_page_get_size(page, byref(w),byref(h))
>         self.initialSize=(h.value*1.0,w.value*1.0)
>         self.initialAspect=float(h.value)/float(w.value)
>
> self.npages=libspec.spectre_document_get_n_pages(self.document)

To answer my own question, partially, i found out if i replace
filename with a hard coded value it doesn't crash.
Now why is that? Does python lose the reference? Should i store
filename as attributed of the object?
Regards
Saptarshi



More information about the Python-list mailing list