[QScintilla] Python SendScintilla with a pointer

VA dev+pyqt at indigo.re
Sat Jun 4 17:35:28 BST 2016


Hello,

I'm not sure this is the right mailing list, so direct me if I'm not on
the right one.

I'm using Python 2, PyQt 5.6 and the Python bindings of QScintilla.
I need to get the styled text of an annotation, but unfortunately,
QScintilla (and moreover the Python bindings) does not have a wrapper
for SCI_ANNOTATIONGETSTYLES, so I'm trying to wrap it myself in Python.

For easier testing purpose, I first tried to wrap myself
SCI_ANNOTATIONGETTEXT, which is wrapped by annotation(), so I can adapt
the QScintilla C++ code to Python:

bufsize = self.SendScintilla(self.SCI_ANNOTATIONGETTEXT, line, 0L) + 1
buf = ctypes.create_string_buffer(bufsize)
addr = ctypes.addressof(buf)
self.SendScintilla(self.SCI_ANNOTATIONGETTEXT, line, ptr)
return buf.value

But the second SendScintilla call segfaults on my machine. I delved and
found that on my machine (32 bits OS), for small bufsize (if <= 16),
addr is a Python 'long', as it is between 1<<31 and 1<<32.

When the segfault, here's what the gdb backtrace starts with:

#0  __memcpy_sse2_unaligned () at
../sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S:668
#1  0xb035d6ff in Editor::BytesResult (lParam=-1, val=0x89eca50 "aaaa1",
len=4) at ../src/Editor.cpp:5330
#2  0xb03628e9 in Editor::WndProc (this=0x882cb70, iMessage=2541,
wParam=0, lParam=-1) at ../src/Editor.cpp:7381
#3  0xb038ae2c in ScintillaBase::WndProc (this=0x882cb70, iMessage=2541,
wParam=0, lParam=-1) at ../src/ScintillaBase.cpp:1067
#4  0xb0270f36 in QsciScintillaQt::WndProc (this=0x882cb68,
iMessage=2541, wParam=0, lParam=-1) at ScintillaQt.cpp:176
#5  0xb02376b1 in QsciScintillaBase::SendScintilla (this=0x883f428,
msg=2541, wParam=0, lParam=-1) at qsciscintillabase.cpp:171

The reason can be clearly seen with lParam equal to -1, while it should
be equal to the address I passed. If I wrap "addr" in a sip.voidptr, the
segfault is the same, with lParam still equal to -1.

So for reasons beyond my understanding, lParam has been erroneously
converted to -1, even when using a sip.voidptr. I noticed the QScintilla
Python bindings accept Python 'int' but not Python 'long'.

I don't know whether it's sip or the QScintilla Python bindings which
should be fixed but there is a problem.

Thanks


More information about the QScintilla mailing list