@@ -173,12 +173,11 @@ callback_shim(getdns_context *context, getdns_callback_type_t type, getdns_dict
173173 return ;
174174 /* need to throw exceptiion XXX */
175175 }
176-
177176 /* Python callback prototype: */
178177 /* callback(context, callback_type, response, userarg, tid) */
179178 state = PyGILState_Ensure ();
180- PyObject_CallFunction (getdns_runner , "OHOsl " , context , type , response ,
181- callback_data -> userarg , tid );
179+ PyObject_CallFunction (getdns_runner , "OHOsi " , context , type , response ,
180+ callback_data -> userarg , ( int ) tid );
182181 PyGILState_Release (state );
183182}
184183
@@ -255,7 +254,7 @@ dispatch_query(PyObject *context_capsule,
255254 uint16_t request_type ,
256255 PyDictObject * extensions_obj ,
257256 void * userarg ,
258- long tid ,
257+ int tid ,
259258 char * callback )
260259
261260{
@@ -346,7 +345,6 @@ dispatch_query(PyObject *context_capsule,
346345 return NULL ;
347346 }
348347
349- callback_data -> userarg = userarg ;
350348 if ((ret = getdns_extension_set_libevent_base (context , gen_event_base )) != GETDNS_RETURN_GOOD ) {
351349 PyErr_SetString (getdns_error , GETDNS_RETURN_GENERIC_ERROR_TEXT );
352350 return NULL ;
@@ -409,6 +407,7 @@ do_query(PyObject *context_capsule,
409407 PyObject * getdns_runner ;
410408 pthread_t runner_thread ;
411409 pygetdns_async_args_blob * async_blob ;
410+ char * u ;
412411
413412 if ((main_module = PyImport_AddModule ("__main__" )) == 0 ) {
414413 PyErr_SetString (getdns_error , "No __main__" );
@@ -423,16 +422,18 @@ do_query(PyObject *context_capsule,
423422 async_blob = (pygetdns_async_args_blob * )malloc (sizeof (pygetdns_async_args_blob ));
424423 async_blob -> context_capsule = context_capsule ;
425424 async_blob -> name = malloc (256 ); /* XXX magic number */
426- strncpy (async_blob -> name , name , strlen (name ));
425+ strncpy (async_blob -> name , name , strlen (name )+ 1 );
427426 async_blob -> type = request_type ;
428427 async_blob -> extensions = extensions_obj ;
429- async_blob -> userarg = userarg ;
428+ async_blob -> userarg = (pygetdns_libevent_callback_data * )malloc (sizeof (pygetdns_libevent_callback_data ));
429+ u = malloc (1024 );
430+ strncpy (u , userarg , strlen (userarg )+ 1 );
431+ async_blob -> userarg -> userarg = u ;
430432 async_blob -> tid = tid ;
431433 async_blob -> callback = malloc (256 ); /* XXX magic number */
432434 strncpy (async_blob -> callback , callback , strlen (callback ));
433435 async_blob -> runner = getdns_runner ;
434436 async_blob -> userarg -> callback_func = getdns_runner ;
435-
436437 Py_BEGIN_ALLOW_THREADS ;
437438 pthread_create (& runner_thread , NULL , (void * )marshall_query , (void * )async_blob );
438439 pthread_detach (runner_thread );
0 commit comments