mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-08 04:50:07 +01:00
Merge pull request #557 from RobinD42/fix-issue550
Return None when trying to make a memoryview buffer with a NULL pointer
This commit is contained in:
@@ -22,7 +22,12 @@ Changes in this release include the following:
|
||||
tweaks in the AUI_MDI sample in the demo. (#540)
|
||||
|
||||
* Added a wx.BUILD_TYPE value to distinguish between development, snapshot,
|
||||
and release builds. The value is also appended to wx.PlatformInfo.
|
||||
and release builds. The value is also appended to wx.PlatformInfo. (Thanks
|
||||
Mesalu!)
|
||||
|
||||
* Fix crash when trying to fetch multiple items from a composite data object
|
||||
in wx.DropTarget.OnData. (#550) Also fixed the CustomDragAndDrop sample to
|
||||
not fail on Python 2.7.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from six.moves import cPickle
|
||||
import pickle
|
||||
import wx
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@@ -72,7 +72,7 @@ class DoodlePad(wx.Window):
|
||||
|
||||
def StartDragOpperation(self):
|
||||
# pickle the lines list
|
||||
linesdata = cPickle.dumps(self.lines, 1)
|
||||
linesdata = pickle.dumps(self.lines)
|
||||
|
||||
# create our own data format and use it in a
|
||||
# custom data object
|
||||
@@ -97,10 +97,10 @@ class DoodlePad(wx.Window):
|
||||
data.Add(bdata)
|
||||
|
||||
# And finally, create the drop source and begin the drag
|
||||
# and drop opperation
|
||||
# and drop operation
|
||||
dropSource = wx.DropSource(self)
|
||||
dropSource.SetData(data)
|
||||
self.log.WriteText("Begining DragDrop\n")
|
||||
self.log.WriteText("Beginning DragDrop\n")
|
||||
result = dropSource.DoDragDrop(wx.Drag_AllowMove)
|
||||
self.log.WriteText("DragDrop completed: %d\n" % result)
|
||||
|
||||
@@ -156,12 +156,14 @@ class DoodleDropTarget(wx.DropTarget):
|
||||
if self.GetData():
|
||||
# convert it back to a list of lines and give it to the viewer
|
||||
linesdata = self.data.GetData()
|
||||
lines = cPickle.loads(linesdata)
|
||||
self.dv.SetLines(lines)
|
||||
if linesdata:
|
||||
lines = pickle.loads(linesdata.tobytes())
|
||||
self.dv.SetLines(lines)
|
||||
|
||||
# what is returned signals the source what to do
|
||||
# with the original data (move, copy, etc.) In this
|
||||
# case we just return the suggested value given to us.
|
||||
# case we again just return the suggested value given
|
||||
# to us.
|
||||
return d
|
||||
|
||||
|
||||
@@ -297,7 +299,6 @@ if __name__ == '__main__':
|
||||
|
||||
class TestApp(wx.App):
|
||||
def OnInit(self):
|
||||
wx.InitAllImageHandlers()
|
||||
self.MakeFrame()
|
||||
return True
|
||||
|
||||
|
||||
@@ -453,12 +453,17 @@ bool i_wxPyCheckForApp(bool raiseException) {
|
||||
|
||||
PyObject* i_wxPyMakeBuffer(void* ptr, Py_ssize_t len, bool readOnly=false) {
|
||||
// GIL should already be held
|
||||
Py_buffer view;
|
||||
int flags = PyBUF_FORMAT|PyBUF_ND;
|
||||
if (!readOnly)
|
||||
flags |= PyBUF_WRITABLE;
|
||||
PyBuffer_FillInfo(&view, NULL, ptr, len, readOnly ? 1:0, flags);
|
||||
return PyMemoryView_FromBuffer(&view);
|
||||
if (ptr && len) {
|
||||
Py_buffer view;
|
||||
int flags = PyBUF_FORMAT|PyBUF_ND;
|
||||
if (!readOnly)
|
||||
flags |= PyBUF_WRITABLE;
|
||||
PyBuffer_FillInfo(&view, NULL, ptr, len, readOnly ? 1:0, flags);
|
||||
return PyMemoryView_FromBuffer(&view);
|
||||
} else {
|
||||
Py_INCREF(Py_None); return Py_None;
|
||||
// return PyBytes_FromString(""); TODO: None or an empty string?
|
||||
}
|
||||
|
||||
// // TODO: Consider using a sip.array object instead, like this:
|
||||
// // Create a sip.array of bytes, and then convert to a memoryview which is
|
||||
|
||||
Reference in New Issue
Block a user