Skip to content

Commit

Permalink
finish switching to non-macro versions of Python APIs,
Browse files Browse the repository at this point in the history
and adding wxPy APIs for things not supported by Py_LIMITED_API
  • Loading branch information
RobinD42 committed Aug 8, 2017
1 parent a5a777e commit 3e2f35d
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion etg/cmndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def run():
return;
}
self->SetPrivData(PyBytes_AS_STRING(data), PyBytes_GET_SIZE(data));
self->SetPrivData(PyBytes_AsString(data), PyBytes_Size(data));
""")

c.addAutoProperties()
Expand Down
4 changes: 2 additions & 2 deletions etg/dataview.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ def _fixupBoolGetters(method, sig):
col_obj = Py_None;
Py_INCREF(Py_None);
}
PyTuple_SET_ITEM(value, 0, item_obj);
PyTuple_SET_ITEM(value, 1, col_obj);
PyTuple_SetItem(value, 0, item_obj);
PyTuple_SetItem(value, 1, col_obj);
// PyTuple steals a reference, so we don't need to decref the items here
return value;
""")
Expand Down
2 changes: 1 addition & 1 deletion etg/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def run():
}
for (int i=0; i<count; i++) {
PyObject* s = wx2PyString(files[i]);
PyList_SET_ITEM(list, i, s);
PyList_SetItem(list, i, s);
}
return list;
""")
Expand Down
6 changes: 3 additions & 3 deletions etg/palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def run():
unsigned char* blueArray = new unsigned char[count];
for (Py_ssize_t i = 0; i < count; i++) {
PyObject* redItem = PySequence_ITEM(red, i);
PyObject* greenItem = PySequence_ITEM(green, i);
PyObject* blueItem = PySequence_ITEM(blue, i);
PyObject* redItem = PySequence_GetItem(red, i);
PyObject* greenItem = PySequence_GetItem(green, i);
PyObject* blueItem = PySequence_GetItem(blue, i);
if (!wxPyInt_Check(redItem) || !wxPyInt_Check(greenItem) || !wxPyInt_Check(blueItem)) {
PyErr_SetString(PyExc_TypeError, errMsg);
goto pch_exit;
Expand Down
2 changes: 1 addition & 1 deletion etg/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def run():
PyErr_SetString(PyExc_TypeError, "Bytes object expected");
return NULL;
}
self->Write(PyBytes_AS_STRING(data), PyBytes_GET_SIZE(data));
self->Write(PyBytes_AsString(data), PyBytes_Size(data));
RETURN_NONE();
""")

Expand Down
2 changes: 1 addition & 1 deletion etg/treelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def run():
for (size_t i=0; i<count; i++) {
wxTreeListItem* item = new wxTreeListItem(items[i]);
PyObject* obj = wxPyConstructObject((void*)item, wxT("wxTreeListItem"), true);
PyList_SET_ITEM(list, i, obj); // PyList_SET_ITEM steals a reference
PyList_SetItem(list, i, obj); // steals a reference
}
return list;
""")
Expand Down
2 changes: 1 addition & 1 deletion src/event_ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void wxPyCallback::EventThunker(wxEvent& event) {
} else {
// Call the event handler, passing the event object
tuple = PyTuple_New(1);
PyTuple_SET_ITEM(tuple, 0, arg); // steals ref to arg
PyTuple_SetItem(tuple, 0, arg); // steals ref to arg
result = PyEval_CallObject(func, tuple);
if ( result ) {
Py_DECREF(result); // result is ignored, but we still need to decref it
Expand Down
8 changes: 4 additions & 4 deletions src/stream_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ static PyObject* wxPyGetMethod(PyObject* py, char* name)
if (!PyObject_HasAttrString(py, name))
return NULL;
PyObject* o = PyObject_GetAttrString(py, name);
if (!PyMethod_Check(o) && !PyCFunction_Check(o)) {
if (!wxPyMethod_Check(o) && !PyCFunction_Check(o)) {
Py_DECREF(o);
return NULL;
}
Expand Down Expand Up @@ -116,11 +116,11 @@ class wxPyInputStream : public wxInputStream

if (sizeof(wxFileOffset) > sizeof(long))
// wxFileOffset is a 64-bit value...
PyTuple_SET_ITEM(arglist, 0, PyLong_FromLongLong(off));
PyTuple_SetItem(arglist, 0, PyLong_FromLongLong(off));
else
PyTuple_SET_ITEM(arglist, 0, wxPyInt_FromLong(off));
PyTuple_SetItem(arglist, 0, wxPyInt_FromLong(off));

PyTuple_SET_ITEM(arglist, 1, wxPyInt_FromLong(mode));
PyTuple_SetItem(arglist, 1, wxPyInt_FromLong(mode));


PyObject* result = PyEval_CallObject(m_seek, arglist);
Expand Down
10 changes: 5 additions & 5 deletions src/stream_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ static PyObject* wxPyGetMethod(PyObject* py, char* name)
if (!PyObject_HasAttrString(py, name))
return NULL;
PyObject* o = PyObject_GetAttrString(py, name);
if (!PyMethod_Check(o) && !PyCFunction_Check(o)) {
if (!wxPyMethod_Check(o) && !PyCFunction_Check(o)) {
Py_DECREF(o);
return NULL;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ class wxPyOutputStream : public wxOutputStream

wxPyThreadBlocker blocker;
PyObject* arglist = PyTuple_New(1);
PyTuple_SET_ITEM(arglist, 0, PyBytes_FromStringAndSize((char*)buffer, bufsize));
PyTuple_SetItem(arglist, 0, PyBytes_FromStringAndSize((char*)buffer, bufsize));

PyObject* result = PyEval_CallObject(m_write, arglist);
Py_DECREF(arglist);
Expand All @@ -109,11 +109,11 @@ class wxPyOutputStream : public wxOutputStream

if (sizeof(wxFileOffset) > sizeof(long))
// wxFileOffset is a 64-bit value...
PyTuple_SET_ITEM(arglist, 0, PyLong_FromLongLong(off));
PyTuple_SetItem(arglist, 0, PyLong_FromLongLong(off));
else
PyTuple_SET_ITEM(arglist, 0, wxPyInt_FromLong(off));
PyTuple_SetItem(arglist, 0, wxPyInt_FromLong(off));

PyTuple_SET_ITEM(arglist, 1, wxPyInt_FromLong(mode));
PyTuple_SetItem(arglist, 1, wxPyInt_FromLong(mode));


PyObject* result = PyEval_CallObject(m_seek, arglist);
Expand Down
4 changes: 2 additions & 2 deletions src/string.sip
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

%ConvertToTypeCode
#if wxUSE_UNICODE_WCHAR == 0
#error wxString converison can only handle WCHAR wxStrings currently
#error wxString conversion can only handle WCHAR wxStrings currently
#endif

// Code to test a PyObject for compatibility with wxString
Expand All @@ -45,7 +45,7 @@
}
}
*sipCppPtr = new wxString();
size_t len = PyUnicode_GET_SIZE(uni);
size_t len = PyUnicode_GetSize(uni);
if (len) {
wxPyUnicode_AsWideChar(uni, wxStringBuffer(**sipCppPtr, len), len);
}
Expand Down
4 changes: 2 additions & 2 deletions src/wxpybuffer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
%ConvertToTypeCode
// Code to test a PyObject for compatibility
if (!sipIsErr) {
if (PyObject_CheckBuffer(sipPy) // New buffer interface
if (wxPyObject_CheckBuffer(sipPy) // New buffer interface
|| PyObject_CheckReadBuffer(sipPy)) // or old buffer interface
return TRUE;
return FALSE;
Expand Down Expand Up @@ -58,7 +58,7 @@
%ConvertToTypeCode
// Code to test a PyObject for compatibility
if (!sipIsErr) {
if (PyObject_CheckBuffer(sipPy))
if (wxPyObject_CheckBuffer(sipPy))
return TRUE;
return FALSE;
}
Expand Down
12 changes: 11 additions & 1 deletion wxpy_api/wxpy_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ struct wxPyAPI {
void* (*p_wxPyGetCppPtr)(sipSimpleWrapper* sipPyObj);
PyObject* (*p_wxPyMethod_Self)(PyObject* method);
void (*p_wxPyReinitializeModules)();

int (*p_wxPyDateTime_Check)(PyObject *obj);
int (*p_wxPyDate_Check)(PyObject *obj);
wxDateTime* (*p_wxPyDateTime_ToWxDateTime)(PyObject *obj);
wxDateTime* (*p_wxPyDate_ToWxDateTime)(PyObject *obj);
bool (*p_wxPyMethod_Check)(PyObject *obj);
int (*p_wxPyObject_CheckBuffer)(PyObject* obj);
// Always add new items here at the end.
};

Expand Down Expand Up @@ -288,6 +289,15 @@ inline wxDateTime* wxPyDate_ToWxDateTime(PyObject *obj)
{ return wxPyGetAPIPtr()->p_wxPyDate_ToWxDateTime(obj); }



inline bool wxPyMethod_Check(PyObject *obj)
{ return wxPyGetAPIPtr()->p_wxPyMethod_Check(obj); }

inline int wxPyObject_CheckBuffer(PyObject *obj)
{ return wxPyGetAPIPtr()->p_wxPyObject_CheckBuffer(obj); }



//--------------------------------------------------------------------------
// Convenience helper for RAII-style thread blocking

Expand Down
13 changes: 10 additions & 3 deletions wxpy_api/wxpy_api.sip
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,13 @@ void* i_wxPyGetCppPtr(sipSimpleWrapper* sipPyObj) {
// Call the PyMethod_Self API, which is not available when the Python
// limited API is activated.

inline PyObject* i_wxPyMethod_Self(PyObject* method) {
PyObject* i_wxPyMethod_Self(PyObject* method) {
return PyMethod_Self(method);
}


bool i_wxPyMethod_Check(PyObject* obj) {
return PyMethod_Check(obj);
}

//--------------------------------------------------------------------------
// Cleanup and reinitialize the wxModules. This is needed because sometimes an
Expand Down Expand Up @@ -578,6 +580,10 @@ wxDateTime* i_wxPyDate_ToWxDateTime(PyObject *obj) {



int i_wxPyObject_CheckBuffer(PyObject* obj) {
return PyObject_CheckBuffer(obj);
}

//--------------------------------------------------------------------------
// An instance of the API structure
static wxPyAPI API = {
Expand All @@ -601,7 +607,8 @@ static wxPyAPI API = {
i_wxPyDateTime_Check,
i_wxPyDate_Check,
i_wxPyDateTime_ToWxDateTime,
i_wxPyDate_ToWxDateTime
i_wxPyDate_ToWxDateTime,
i_wxPyMethod_Check
};
%End

Expand Down

0 comments on commit 3e2f35d

Please sign in to comment.