From: Klaus Kämpf Date: Mon, 6 Dec 2010 12:38:32 +0000 (+0100) Subject: Complete callbacks support (Python, Ruby) X-Git-Tag: BASE-SuSE-Code-12_2-Branch~36 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=75f229e2e5fe0eb858aa71819150f27c16f95627;p=platform%2Fupstream%2Flibzypp-bindings.git Complete callbacks support (Python, Ruby) --- diff --git a/swig/Callbacks.i b/swig/Callbacks.i index fec4335..2452f2e 100644 --- a/swig/Callbacks.i +++ b/swig/Callbacks.i @@ -14,6 +14,65 @@ */ %{ +#include + +static Target_Type +target_call(Target_Type instance, const char *name, int argc, ... ) +{ + va_list ap; + va_start(ap, argc); + printf("Calling %p->%s with %d args\n", (void *)instance, name, argc); +#if defined(SWIGPYTHON) + /* + * Python call with multiple args is like Array + */ + Target_Type argv = Target_SizedArray(argc); + while(argc-- > 0) { + Target_Append(argv, va_arg(ap, Target_Type)); + } + + PyObject *pyfunc = PyObject_GetAttrString(instance, name); + PyObject *result = NULL; + + if (pyfunc == NULL) + { + PyErr_Print(); + PyErr_Clear(); + goto cleanup; + } + if (! PyCallable_Check(pyfunc)) + { + goto cleanup; + } + + result = PyObject_CallObject(pyfunc, argv); + if (PyErr_Occurred()) + { + PyErr_Clear(); + goto cleanup; + } + +cleanup: + if (pyfunc) Py_DecRef(pyfunc); +#endif +#if defined(SWIGRUBY) + /* + * Ruby call with multiple args is like argc/argv + */ + Target_Type *argv = (Target_Type *)alloca(argc * sizeof(Target_Type)); + Target_Type *argvp = argv; + int i = argc; + while(i-- > 0) { + *argvp++ = va_arg(ap, Target_Type); + } + VALUE result = rb_funcall3( instance, rb_intern(name), argc, argv ); +#endif +#if defined(SWIGPERL) + Target_Type result = Target_Null; +#endif + va_end(ap); + return result; +} /* * Patch message @@ -83,40 +142,13 @@ struct RemoveResolvableReportReceiver : public zypp::callback::ReceiveReport