wxPoint* wxPoint_LIST_helper(PyObject* source, int *count) { // The length of the sequence is returned in count. if (!PySequence_Check(source)) { PyErr_SetString(PyExc_TypeError, "Expected a sequence of length-2 sequences."); return NULL; } *count = PySequence_Length(source); if (*count < 0) { PyErr_SetString(PyExc_TypeError, "Sequence returned a bogus length."); return NULL; } wxPoint* temp = new wxPoint[*count]; if (!temp) { PyErr_SetString(PyExc_MemoryError, "Unable to allocate temporary array"); return NULL; } int fast = PyList_Check(source); for (int x=0; x<*count; x++) { PyObject* o; if (fast) { o = PyList_GET_ITEM(source, x); } else { o = PySequence_GetItem(source, x); if (o == NULL) { delete temp; PyErr_SetString(PyExc_TypeError, "Expected a sequence of length-2 sequences."); return NULL; } } if (PyTuple_Check(o) && PyTuple_Size(o) == 2) { PyObject* o1 = PyTuple_GET_ITEM(o, 0); PyObject* o2 = PyTuple_GET_ITEM(o, 1); // This should really check for integers, not numbers -- but that would break code. if (!PyNumber_Check(o1) || !PyNumber_Check(o2)) { if (!fast) Py_DECREF(o); delete temp; PyErr_SetString(PyExc_TypeError, "Expected a sequence of length-2 sequences."); return NULL; } temp[x].x = PyInt_AsLong(o1); temp[x].y = PyInt_AsLong(o2); } else if (PySequence_Check(o) && PySequence_Length(o) == 2) { PyObject* o1 = PySequence_GetItem(o, 0); PyObject* o2 = PySequence_GetItem(o, 1); // This should really check for integers, not numbers -- but that would break code. if (!PyNumber_Check(o1) || !PyNumber_Check(o2)) { Py_DECREF(o1); Py_DECREF(o2); if (!fast) Py_DECREF(o); delete temp; PyErr_SetString(PyExc_TypeError, "Expected a sequence of length-2 sequences."); return NULL; } temp[x].x = PyInt_AsLong(o1); temp[x].y = PyInt_AsLong(o2); Py_DECREF(o1); Py_DECREF(o2); } else if (PyInstance_Check(o)) { wxPoint* ptr; if (SWIG_GetPtrObj(o, (void **)&ptr, "_wxPoint_p")) { if (!fast) Py_DECREF(o); delete temp; PyErr_SetString(PyExc_TypeError, "Expected a sequence of length-2 sequences."); return NULL; } temp[x] = *ptr; } else { delete temp; PyErr_SetString(PyExc_TypeError, "Expected a sequence of length-2 sequences."); return NULL; } if (!fast) Py_DECREF(o); } return temp; }