Python brokeness???

Arinté shouldbe at message.com
Thu Jul 6 08:35:31 EDT 2000


I have an embedded app with a call like this:
PyObject *open(PyObject* self,PyObject* args){
 long ret(1);

 g_lastDevice = pyposs.getDeviceFromPy(args);
 if(!g_lastDevice){
  PyErr_Clear();
  PyErr_SetString(PyExc_TypeError,"No Device");
  return NULL;
 }
 else
 {
  PyObject* deqme =Py_BuildValue("i",0);
  PyObject* comm =PyObject_GetItem(args, deqme);
  PosArgEx* p=createArgs(comm);
  ret = g_lastDevice->open(p);
  if(p){
   createPyArgs(comm,p);
   delete p;
  }
   ioctls.getIOCtls(g_lastDevice->getName());
 }
 PyErr_Clear();
 return Py_BuildValue("i",ret);
}

Now, before I put that PyErr_Clear in the script that I ran with a
range(-1,10) used to give error len() of unsized object or give me
IndexError: string index out of range.  Here is the script

import PossDevice
import poss

1 poss.initialize( PossDevice.Enumerate )
2 diz = PossDevice.QueryDevices(1,11,35)
3 diz.open()
4 diz.ioctl("POS_SYS_ACQUIRE_DEVICE",0)
z = range(-1,14)
for i in z:
 print i

I figured out that it was open by taking away line 4, then 3, then 2, then
putting 3 back in.  So, I first did a check on PyErr_Occurred, but it didn't
give an error, but the script did.  So, I just left PyErr_Clear in without
checking and it worked.  BTW, I get the len() of unsized error if I leave
the ioctl and the open in  (ioctl and open are calls to the c++ app).

I like python and I am not trying to troll or tear it down, so please no
flames.  If any of the functions fail in my c++ app (like  g_lastDevice =
pyposs.getDeviceFromPy(args);) I expect a crash, but these are nigh
foolproof (emphasis on nigh).

thanx for any info.






More information about the Python-list mailing list