Skip to content

Instantly share code, notes, and snippets.

@neuro-sys
Created February 24, 2013 22:25
Show Gist options
  • Select an option

  • Save neuro-sys/5025991 to your computer and use it in GitHub Desktop.

Select an option

Save neuro-sys/5025991 to your computer and use it in GitHub Desktop.
tedious and fuckly error checking
char * py_call_module(char * name, struct irc_t * irc)
{
struct py_module_t * mod;
PyObject * p_args;
PyObject * p_val;
char * ret;
if (!(mod = g_hash_table_lookup(mod_hash_map, name)))
return NULL;
if (!(p_args = PyTuple_New(2)))
return NULL;
if (!(p_val = PyString_FromString(irc->from)))
return NULL;
if (PyTuple_SetItem(p_args, 0, p_val) != 0)
return NULL;
if (!(p_val = PyString_FromString(irc->request)))
return NULL;
if (PyTuple_SetItem(p_args, 1, p_val) != 0)
return NULL;
if (!(p_val = PyObject_CallObject(mod->pFunc, p_args)))
return NULL;
if(!(ret = PyString_AsString(p_val)))
return NULL;
return strdup(PyString_AsString(p_val));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment