[wxPython] Probable error in stc.cpp (wxStyledTextCtrl)

This buglet causes a crash on wxStyledTextCtrl.AddRefDocument
is invoked.

Short form: wxPython/contrib/stc/contrib/src/stc/stc.cpp needs to be
patched in AddRefDocument and ReleaseDocument so that the
correct parameter is passed. The params should be
(msg,0,docpointer) but currently they are (msg,docpointer).

Wordy version:

I am trying to use SetDocPointer/GetDocPointer/AddRefDocument
and I found that my app crashed when AddRefDocument was called
from a Python statement such as

self.dp = self.edit.GetDocPointer()
self.edit.AddRefDocument(self.dp)

Having a source distro set up with MS VC++, started Python and my app
thru VC++ and let the crash show me where the error was.

It's in contrib/stc/contrib/src/stc/scintilla/src/Document.cxx:

// Increase reference count and return its previous value.
int Document::AddRef() {
return refCount++;
}

but the 'this' at that point was 0, so of course it crashed.
ANYWAY, to make a long story short, I traced back up
thru the stack-context and saw that what was happening is
that the lparam input to the WndProc seems to be zero
and that the wparam, which should be zero is the doc
pointer.

This affects stc.cpp:

···

------------------------------------------------------------------------------
// Extend life of document.
void wxStyledTextCtrl::AddRefDocument(void* docPointer) {
                           SendMsg(2376, (long)docPointer);
}

// Release a reference to the document, deleting document if it fades to black.
void wxStyledTextCtrl::ReleaseDocument(void* docPointer) {
                           SendMsg(2377, (long)docPointer);
-------------------------------------------------------------------------------

In BOTH these cases, the SendMsg should look like

SendMsg(###,0,(long)docPointer)

as is done correctly in SetDocPointer:

// Change the document object used.
void wxStyledTextCtrl::SetDocPointer(void* docPointer) {
                           SendMsg(2358, 0, (long)docPointer);
}

This way wparam is 0 and lparam is the docPointer.

I am using a source tree downloaded from CVS several weeks ago,
and looking at it right now via ViewCVS this buglet is still present.
I patched the src and the prob went away, altho I am not using
ReleaseDocument() so could not test it.

I also posted this to the SourceForge wxWindows tracker, but
it disappeared... Hmm.

Regards,
Jeff Sasmor
#--------------------------------
Jeff Sasmor
jeff@sasmor.com

I also posted this to the SourceForge wxWindows tracker, but
it disappeared... Hmm.

Because I fixed it and closed the bug report. <grin>

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Wow, that's service. <grin><grin>

···

#--------------------------------
Jeff Sasmor
jeff@sasmor.com
----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Thursday, August 08, 2002 6:26 PM
Subject: Re: [wxPython] Probable error in stc.cpp (wxStyledTextCtrl)

I also posted this to the SourceForge wxWindows tracker, but
it disappeared... Hmm.

Because I fixed it and closed the bug report. <grin>

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

In the Scintilla docs it says that you can:

SCI_SETDOCPOINTER(0) switches to a new empty document

If you actually try this (SetDocPointer), you get an error:

Inappropriate argument type: Type error in argument 2 of
wxStyledTextCtrl_SetDocPointer. Expected _void_p.

Traceback (innermost last):

File "c:\Documents and Settings\jms\Desktop\PyFrame\P1.py", line 144, in ?
  App2.run()
File "c:\Documents and Settings\jms\Desktop\PyFrame\pf\Controllers\App2.py", line 957, in run
      app.MainLoop()
File "c:\Documents and Settings\jms\Desktop\PyFrame\wxPython\wx.py", line 1666, in MainLoop
          wxPyApp.MainLoop(self)
File "c:\Documents and Settings\jms\Desktop\PyFrame\wxPython\wx.py", line 86, in MainLoop
          val = apply(wxc.wxPyApp_MainLoop,(self,) + _args, _kwargs)
File "c:\Documents and Settings\jms\Desktop\PyFrame\pf\Controllers\databaseView.py", line 734, in OnLeftClick
        self.showContentsOfANode(node,item)
File "c:\Documents and Settings\jms\Desktop\PyFrame\pf\Controllers\databaseView.py", line 241, in showContentsOfANode
          viewer.RefreshView(1)
File "c:\Documents and Settings\jms\Desktop\PyFrame\pf\FileSystem\Document.py", line 263, in RefreshView
          self.edit.SetDocPointer(0)
File "c:\Documents and Settings\jms\Desktop\PyFrame\wxPython\stc_.py", line 802, in SetDocPointer
          val = apply(stc_c.wxStyledTextCtrl_SetDocPointer,(self,) + _args, _kwargs)

I think that the workaround for this is using CreateNewDocument which returns a
document pointer, then use SetDocPointer to set this new doc into the editor.

I was going to try using wxPyTypeCast to create a _void_p type but I think passing
a void pointer set to zero would just crash the program.

It would be more correct to check for a value of Zero passed in and let that pass...

···

#--------------------------------
Jeff Sasmor
jeff@sasmor.com

In the Scintilla docs it says that you can:

SCI_SETDOCPOINTER(0) switches to a new empty document

If you actually try this (SetDocPointer), you get an error:

Inappropriate argument type: Type error in argument 2 of
wxStyledTextCtrl_SetDocPointer. Expected _void_p.

Try calling it with None. The SWIG typemaps should convert it to NULL, with
is a void pointer with value zero.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

You're right, that works!
Thanx

···

#--------------------------------
Jeff Sasmor
jeff@sasmor.com
----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, August 09, 2002 1:35 PM
Subject: Re: [wxPython] Another sort-of error in stc.cpp (wxStyledTextCtrl)

In the Scintilla docs it says that you can:

SCI_SETDOCPOINTER(0) switches to a new empty document

If you actually try this (SetDocPointer), you get an error:

Inappropriate argument type: Type error in argument 2 of
wxStyledTextCtrl_SetDocPointer. Expected _void_p.

Try calling it with None. The SWIG typemaps should convert it to NULL, with
is a void pointer with value zero.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users