[pygi] Fix passing callbacks as constructor args
- From: Tomeu Vizoso <tomeuv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygi] Fix passing callbacks as constructor args
- Date: Wed, 5 May 2010 16:31:16 +0000 (UTC)
commit 17fa1289b1e2ed841dd5de09a2ec7c25d401886e
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date: Mon May 3 19:13:46 2010 +0200
Fix passing callbacks as constructor args
https://bugzilla.gnome.org/show_bug.cgi?id=617551
gi/pygi-callbacks.c | 3 ++-
gi/pygi-callbacks.h | 1 +
gi/pygi-invoke.c | 7 +++++--
tests/test_everything.py | 21 +++++++++++++++++++++
4 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/gi/pygi-callbacks.c b/gi/pygi-callbacks.c
index 7f5de9b..50bd62a 100644
--- a/gi/pygi-callbacks.c
+++ b/gi/pygi-callbacks.c
@@ -144,6 +144,7 @@ _pygi_scan_for_callbacks (GIFunctionInfo *function_info,
gboolean
_pygi_create_callback (GIBaseInfo *function_info,
gboolean is_method,
+ gboolean is_constructor,
int n_args,
Py_ssize_t py_argc,
PyObject *py_argv,
@@ -176,7 +177,7 @@ _pygi_create_callback (GIBaseInfo *function_info,
py_user_data = NULL;
/* if its a method then we need to skip over 'self' */
- if (is_method)
+ if (is_method || is_constructor)
py_argv_pos = 1;
else
py_argv_pos = 0;
diff --git a/gi/pygi-callbacks.h b/gi/pygi-callbacks.h
index 4b98e3d..c2b137e 100644
--- a/gi/pygi-callbacks.h
+++ b/gi/pygi-callbacks.h
@@ -34,6 +34,7 @@ gboolean _pygi_scan_for_callbacks (GIFunctionInfo *self,
gboolean _pygi_create_callback (GIFunctionInfo *self,
gboolean is_method,
+ gboolean is_constructor,
int n_args,
Py_ssize_t py_argc,
PyObject *py_argv,
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 68db678..0373a0d 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -106,13 +106,16 @@ _prepare_invocation_state (struct invocation_state *state,
{
gsize i;
- if (!_pygi_scan_for_callbacks (function_info, state->is_method,
+ if (!_pygi_scan_for_callbacks (function_info,
+ state->is_method,
&state->callback_index, &state->user_data_index,
&state->destroy_notify_index))
return FALSE;
if (state->callback_index != G_MAXUINT8) {
- if (!_pygi_create_callback (function_info, state->is_method,
+ if (!_pygi_create_callback (function_info,
+ state->is_method,
+ state->is_constructor,
state->n_args, state->n_py_args,
py_args, state->callback_index,
state->user_data_index,
diff --git a/tests/test_everything.py b/tests/test_everything.py
index de016e9..ecdbd9f 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -182,3 +182,24 @@ class TestCallbacks(unittest.TestCase):
self.assertEquals(Everything.test_callback_destroy_notify(callback, 42), 42)
self.assertTrue(TestCallbacks.called)
self.assertEquals(Everything.test_callback_thaw_notifications(), 42)
+
+ def testCallbackInMethods(self):
+ object_ = Everything.TestObj()
+
+ def callback():
+ TestCallbacks.called = True
+
+ TestCallbacks.called = False
+ object_.instance_method_callback(callback)
+ self.assertTrue(TestCallbacks.called)
+
+ TestCallbacks.called = False
+ Everything.TestObj.static_method_callback(callback)
+ self.assertTrue(TestCallbacks.called)
+
+ def callbackWithUserData(user_data):
+ TestCallbacks.called = True
+
+ TestCallbacks.called = False
+ obj_ = Everything.TestObj.new_callback(callbackWithUserData, None)
+ self.assertTrue(TestCallbacks.called)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]