Crash in python while run from U3 device

P

Philippe C. Martin

Hi,

I am currently porting some of my applications to U3 (www.u3.com) and I do
get a crash in ...objects\frameobject.c: PyFrameObject *back =
tstate->frame.

The point of the current test is to get a python function called on a U3
device event. (U3 only work with Windows currently).

My C stub callback does get called but crashes when it tries to call the
python function.



***************************
This is the function that registers the callback (actual dll prototype in
header):
***************************
static PyObject *s_callback=NULL;
/******************************************************************/
/******************************************************************/
/* HRESULT dapiRegisterCallback ( HSESSION hSession ,wchar_t*
pszConnectionString ,DAPI_CALLBACK pCallBack,void* pEx ,HCALLBACK*
hCallback) */
/******************************************************************/
/******************************************************************/

static PyObject *Py_dapiRegisterCallback(PyObject *p_self, PyObject *p_args)
{
HRESULT l_result;
HSESSION l_hSession;
wchar_t* l_pszConnectionString;
PyObject *l_tmp_cb;
//PyObject cs;
void* l_pEx;
HCALLBACK l_hCallback;

if
(!PyArg_ParseTuple(p_args,"iuOi",&l_hSession,&l_pszConnectionString,&l_tmp_cb,&l_pEx) )
{
BAD_PARAM;
return NULL;
}
//l_pszConnectionString = PyObject_Unicode(cs);
Py_XINCREF(l_tmp_cb);
Py_XDECREF(s_callback);
s_callback=l_tmp_cb;
l_result =
dapiRegisterCallback(l_hSession,l_pszConnectionString,Stub_Callback,l_pEx,&l_hCallback);

CHECK_RESULT;

return Py_BuildValue("l",l_hCallback);

}

***************************************
This is the stub callback that crashes:
***************************************
void _stdcall Stub_Callback(HDEVICE p_dev, DWORD p_event, void *p_pEx)
{
PyObject *l_result;
PyObject *l_arg_list;

l_arg_list = Py_BuildValue("(iii)", p_dev,p_event,p_pEx);
l_result = PyEval_CallObject(s_callback, l_arg_list); /*No crash if I
comment this line*/
Py_DECREF(l_arg_list);
}


*****************************************
This is the python source
*****************************************
(cs, and s have a correct value ... I think )
import u3
def mf(a,b,c):
print 'CB'

h=u3.dapiRegisterCallback(s, cs, mf, 0)




Any help _greatly_ appreciated.

Regards,

Philippe
 
P

Philippe C. Martin

Philippe said:
Hi,

I am currently porting some of my applications to U3 (www.u3.com) and I do
get a crash in ...objects\frameobject.c: PyFrameObject *back =
tstate->frame.

The point of the current test is to get a python function called on a U3
device event. (U3 only work with Windows currently).

My C stub callback does get called but crashes when it tries to call the
python function.



***************************
This is the function that registers the callback (actual dll prototype in
header):
***************************
static PyObject *s_callback=NULL;
/******************************************************************/
/******************************************************************/
/* HRESULT dapiRegisterCallback ( HSESSION hSession ,wchar_t*
pszConnectionString ,DAPI_CALLBACK pCallBack,void* pEx ,HCALLBACK*
hCallback) */
/******************************************************************/
/******************************************************************/

static PyObject *Py_dapiRegisterCallback(PyObject *p_self, PyObject
*p_args)
{
HRESULT l_result;
HSESSION l_hSession;
wchar_t* l_pszConnectionString;
PyObject *l_tmp_cb;
//PyObject cs;
void* l_pEx;
HCALLBACK l_hCallback;

if
(!PyArg_ParseTuple(p_args,"iuOi",&l_hSession,&l_pszConnectionString,&l_tmp_cb,&l_pEx)
)
{
BAD_PARAM;
return NULL;
}
//l_pszConnectionString = PyObject_Unicode(cs);
Py_XINCREF(l_tmp_cb);
Py_XDECREF(s_callback);
s_callback=l_tmp_cb;
l_result =
dapiRegisterCallback(l_hSession,l_pszConnectionString,Stub_Callback,l_pEx,&l_hCallback);

CHECK_RESULT;

return Py_BuildValue("l",l_hCallback);

}
PS: the crash is in PyFrame_New

Thanks,

Philippe
 
P

Philippe C. Martin

PS: I should add that the U3 device does not actually run Python, but copies
it to the PC and launches it: I'm almost certain this is a bug in my code.

Help please !

Regards,

Philippe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top