QT, ctypes dll and SEG Faults
Matthieu Brucher
matthieu.brucher at gmail.com
Sun Aug 17 06:55:26 EDT 2008
Hi,
If the crash occurs in __init__, why do you give us more code ?
The crash can occur because you pass a char* to your library. This
char* is not managed by your library but by Python. This means that
when the constructor is finished, the string is freed and the char* is
not valid anymore.
This is perhaps what is causing your error. I can't say more because
your code sample is too long and not well explained (what is happening
and what should happen ?)
Matthieu
2008/8/17 sapsi <saptarshi.guha at gmail.com>:
> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
More information about the Python-list
mailing list