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
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