summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Kämpf <kkaempf@suse.de>2011-08-09 16:10:23 +0200
committerKlaus Kämpf <kkaempf@suse.de>2011-08-09 16:10:23 +0200
commitce7ea4030365facae0e3bbc32ee77937595b97ff (patch)
tree752a995b6aeb5c69bff30ceb084e2c0731e75602
parent212de44c84d40fa875fe948430b69c5cceb16536 (diff)
downloadlibzypp-bindings-ce7ea4030365facae0e3bbc32ee77937595b97ff.tar.gz
libzypp-bindings-ce7ea4030365facae0e3bbc32ee77937595b97ff.tar.bz2
libzypp-bindings-ce7ea4030365facae0e3bbc32ee77937595b97ff.zip
Fix the 'remove start' callback'
-rw-r--r--swig/Callbacks.i22
-rw-r--r--swig/python/tests/commit_callbacks.py7
2 files changed, 25 insertions, 4 deletions
diff --git a/swig/Callbacks.i b/swig/Callbacks.i
index 2452f2e..d4186aa 100644
--- a/swig/Callbacks.i
+++ b/swig/Callbacks.i
@@ -26,9 +26,17 @@ target_call(Target_Type instance, const char *name, int argc, ... )
/*
* 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));
+ Target_Type argv = PyTuple_New(argc);
+ int i;
+ for (i = 0; i < argc; ++i)
+ {
+ PyObject* arg = va_arg(ap, PyObject*);
+ if (arg == NULL)
+ {
+ arg = Py_None;
+ Py_IncRef(arg);
+ }
+ PyTuple_SET_ITEM(argv, i, arg);
}
PyObject *pyfunc = PyObject_GetAttrString(instance, name);
@@ -36,24 +44,29 @@ target_call(Target_Type instance, const char *name, int argc, ... )
if (pyfunc == NULL)
{
+ printf("%s not defined\n", name);
PyErr_Print();
PyErr_Clear();
goto cleanup;
}
if (! PyCallable_Check(pyfunc))
{
+ printf("%s not callable\n", name);
goto cleanup;
}
result = PyObject_CallObject(pyfunc, argv);
if (PyErr_Occurred())
{
+ printf("%s returned error\n", name);
+ PyErr_Print();
PyErr_Clear();
goto cleanup;
}
cleanup:
if (pyfunc) Py_DecRef(pyfunc);
+ if (argv) Py_DecRef(argv);
#endif
#if defined(SWIGRUBY)
/*
@@ -142,7 +155,8 @@ struct RemoveResolvableReportReceiver : public zypp::callback::ReceiveReport<zyp
Target_Type instance;
- virtual void start( const zypp::Resolvable *resolvable )
+/* virtual void start( const zypp::Resolvable *resolvable ) */
+ virtual void start( Resolvable::constPtr resolvable )
{
Target_Type r = SWIG_NewPointerObj((void *)&(*resolvable), SWIGTYPE_p_zypp__Resolvable, 0);
Target_Type result = target_call(instance, "removal_start", 1, r );
diff --git a/swig/python/tests/commit_callbacks.py b/swig/python/tests/commit_callbacks.py
index ff002ae..02202c9 100644
--- a/swig/python/tests/commit_callbacks.py
+++ b/swig/python/tests/commit_callbacks.py
@@ -12,8 +12,12 @@ sys.path.insert(0, cwd + "/../../../build/swig/python")
import zypp
+removals = 0
+
class CommitReceiver:
def removal_start(self, resolvable):
+ global removals
+ removals += 1
print "Starting to remove ", resolvable
class CommitCallbacksTestCase(unittest.TestCase):
@@ -37,8 +41,11 @@ class CommitCallbacksTestCase(unittest.TestCase):
for item in Z.pool():
print "Emitting removal of ", item.resolvable()
commit_callbacks_emitter.remove_start(item.resolvable())
+ print "Done"
break
+ assert removals == 1
+
commit_callbacks.disconnect()
# print "disconnected"
assert None == commit_callbacks.receiver()