[PyQt] sipConvertToInstance failing after sipCanConvertToInstance succeeds.

Diez B. Roggisch deets at web.de
Tue Jul 21 10:07:19 BST 2009


On Tuesday 21 July 2009 10:43:14 Phil Thompson wrote:
> On Tue, 21 Jul 2009 09:26:39 +0200, "Diez B. Roggisch" <deets at web.de>
>
> wrote:
> > Hi,
> >
> > well, the subject pretty much says it. The below code exectutes fine in
> > the debugger until it reaches the line
> >
> > 	  irr::video::S3DVertex *vertex = (irr::video::S3DVertex
> > *)sipConvertToInstance(py_vertex, S3DVertexType, NULL, SIP_NOT_NONE,
> > NULL, &err);
> >
> >
> > where "err" then gets some seemingly random value & the program
> > terminates. The if-statement below the line doesn't work and was a
> > feeble attempt at error-handling - a subject that is given not much more
> > information in the whole
> >
> > http://www.riverbankcomputing.com/static/Docs/sip4/c_api.html
> >
> > page.
> >
> > Any suggestions? Ah, python is 2.6 on osx, SIP is 4.7.9.
> >
> >
> > Diez
> >
> >
> > void append(SIP_PYLIST, SIP_PYLIST);
> > %MethodCode
> >        PyObject *py_vertices = a0;
> >        PyObject *py_indices = a1;
> >        irr::u32 numVertices = PyList_Size(py_vertices);
> >        irr::video::S3DVertex *vertices = (irr::video::S3DVertex
> > *)sipMalloc(sizeof(irr::video::S3DVertex) * numVertices);
> >        irr::u32 numIndices = PyList_Size(py_indices);
> >        irr::u16 *indices = (irr::u16*)sipMalloc(sizeof(irr::u16) *
> > numIndices);
> >
> >        sipWrapperType *S3DVertexType =
> > sipFindClass("irr::video::S3DVertex");
> >
> >        int err;
> >
> >        for(irr::u32 i=0; i < numVertices; i++) {
> > 	PyObject *py_vertex = PyList_GetItem(py_vertices, i);
> > 	if(sipCanConvertToInstance(py_vertex, S3DVertexType, SIP_NOT_NONE)) {
> > 	  irr::video::S3DVertex *vertex = (irr::video::S3DVertex
> > *)sipConvertToInstance(py_vertex, S3DVertexType, NULL, SIP_NOT_NONE,
> > NULL, &err);
> > 	  if(err) {
> > 	    return -1;
> > 	  }
> > 	  vertices[i] = *vertex;
> > 	} // TODO: raise an exception here!
> >        }
> >
> >        for(irr::u32 i=0; i < numIndices; i++) {
> > 	PyObject *py_index = PySequence_GetItem(py_indices, i);
> > 	irr::u16 indices[3];
> > 	for(int j=0; j < 3; j++) {
> > 	  PyObject *item = PySequence_GetItem(py_index, j);
> > 	  if(PyLong_Check(item)) {
> > 	    indices[j] = (irr::u16)PyLong_AsLong(item);
> > 	  } else {
> > 	    // TODO: raise an exception here!
> > 	  }
> > 	}
> >        }
> >        sipCpp->append((void*)vertices, numVertices, indices, numIndices);
> >        sipFree(indices);
> >        sipFree(vertices);
> > %End
>
> What is S3DVertexType? I would expect it to start with 'sipClass_'.

It's a wrapped structure, with the original name "irr::video::S3DVertex". 
After reading the aforementioned docs, I was under the impression that I need 
to get a sipTypeDef to check & convert. At least pointers of that kind are 
taken from sipConvertToInstance and sipCanConvertToInstance.

Diez


More information about the PyQt mailing list