Skip to content

Commit e4543fa

Browse files
committed
Fixed a couple of function definitions
1 parent ca31917 commit e4543fa

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

getdns.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ PyTypeObject getdns_ContextType = {
143143
(initproc)context_init, /* tp_init */
144144
};
145145

146+
pthread_t runner_thread;
147+
146148

147149
/*
148150
* A shim to sit between the event callback function
@@ -161,7 +163,7 @@ callback_shim(getdns_context *context, getdns_callback_type_t type, getdns_dict
161163

162164
callback_data = (pygetdns_libevent_callback_data *)u;
163165
getdns_runner = callback_data->callback_func;
164-
if (!PyCallable_Check(getdns_runner)) { /* XXX */
166+
if (!PyCallable_Check(getdns_runner)) {
165167
printf("callback not runnable\n");
166168
return;
167169
}
@@ -185,9 +187,10 @@ callback_shim(getdns_context *context, getdns_callback_type_t type, getdns_dict
185187
* __main__
186188
*/
187189

188-
void
189-
marshall_query(pygetdns_async_args_blob *blob)
190+
void *
191+
marshall_query(void *void_blob)
190192
{
193+
pygetdns_async_args_blob *blob = (pygetdns_async_args_blob *)void_blob;
191194
PyObject *ret;
192195

193196
if ((ret = dispatch_query(blob->context_capsule, blob->name,
@@ -196,6 +199,7 @@ marshall_query(pygetdns_async_args_blob *blob)
196199
PyErr_SetString(getdns_error, GETDNS_RETURN_GENERIC_ERROR_TEXT);
197200
pthread_exit(0);
198201
}
202+
return 0;
199203
}
200204

201205

@@ -352,7 +356,6 @@ do_query(PyObject *context_capsule,
352356
PyObject *main_module;
353357
PyObject *main_dict;
354358
PyObject *getdns_runner;
355-
pthread_t runner_thread;
356359
pygetdns_async_args_blob *async_blob;
357360
char *u;
358361

@@ -373,8 +376,11 @@ do_query(PyObject *context_capsule,
373376
async_blob->type = request_type;
374377
async_blob->extensions = extensions_obj;
375378
async_blob->userarg = (pygetdns_libevent_callback_data *)malloc(sizeof(pygetdns_libevent_callback_data));
376-
u = malloc(1024);
377-
strncpy(u, userarg, strlen(userarg)+1);
379+
if (userarg) {
380+
u = malloc(1024);
381+
strncpy(u, userarg, strlen(userarg)+1);
382+
} else
383+
u = 0;
378384
async_blob->userarg->userarg = u;
379385
async_blob->tid = tid;
380386
async_blob->callback = malloc(256); /* XXX magic number */
@@ -393,6 +399,12 @@ static struct PyMethodDef getdns_methods[] = {
393399
{ 0, 0, 0 }
394400
};
395401

402+
static void
403+
cleanup(void)
404+
{
405+
pthread_join(runner_thread, NULL);
406+
}
407+
396408

397409
PyMODINIT_FUNC
398410
initgetdns(void)
@@ -412,6 +424,7 @@ initgetdns(void)
412424
Py_INCREF(&getdns_ContextType);
413425
PyModule_AddObject(g, "Context", (PyObject *)&getdns_ContextType);
414426
PyModule_AddStringConstant(g, "__version__", PYGETDNS_VERSION);
427+
Py_AtExit(cleanup);
415428
/*
416429
* return value constants
417430
*/

pygetdns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ PyObject *context_get_num_pending_requests(PyObject *self, PyObject *args, PyObj
127127
PyObject *context_process_async(PyObject *self, PyObject *args, PyObject *keywds);
128128
getdns_dict *getdnsify_addressdict(PyObject *pydict);
129129
void context_dealloc(getdns_ContextObject *self);
130-
void marshall_query(pygetdns_async_args_blob *blog);
130+
void *marshall_query(void *blob);
131131
PyObject *dispatch_query(PyObject *context_capsule, void *name, uint16_t request_type,
132132
PyDictObject *extensions_obj, void *userarg, getdns_transaction_t tid, char *callback);
133133

0 commit comments

Comments
 (0)