[pygobject/invoke-rewrite] [gi] do arg counting in new invoke
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/invoke-rewrite] [gi] do arg counting in new invoke
- Date: Wed, 19 Jan 2011 12:14:50 +0000 (UTC)
commit cbaba6357937cbed3ebd34d2db1cdd59d37df118
Author: John (J5) Palmieri <johnp redhat com>
Date: Wed Jan 19 07:14:18 2011 -0500
[gi] do arg counting in new invoke
gi/pygi-cache.c | 2 ++
gi/pygi-cache.h | 14 ++++++++------
gi/pygi-invoke-state-struct.h | 2 +-
gi/pygi-invoke.c | 20 +++++++++++++++++++-
4 files changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index d5afc04..ea40aa8 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -113,6 +113,8 @@ _function_cache_new_from_function_info(GIFunctionInfo *function_info)
GIFunctionInfoFlags flags;
fc = g_slice_new0(PyGIFunctionCache);
+
+ fc->name = g_base_info_get_name((GIBaseInfo *)function_info);
flags = g_function_info_get_flags(function_info);
fc->is_method = flags & GI_FUNCTION_IS_METHOD;
fc->is_constructor = flags & GI_FUNCTION_IS_CONSTRUCTOR;
diff --git a/gi/pygi-cache.h b/gi/pygi-cache.h
index 853666d..8141932 100644
--- a/gi/pygi-cache.h
+++ b/gi/pygi-cache.h
@@ -71,8 +71,8 @@ struct _PyGIArgCache
GDestroyNotify destroy_notify;
- gint c_arg_index;
- gint py_arg_index;
+ gssize c_arg_index;
+ gssize py_arg_index;
};
typedef struct _PyGISequenceCache
@@ -112,6 +112,8 @@ typedef struct _PyGICallbackCache
struct _PyGIFunctionCache
{
+ const gchar *name;
+
gboolean is_method;
gboolean is_constructor;
@@ -120,10 +122,10 @@ struct _PyGIFunctionCache
GSList *out_args;
/* counts */
- guint n_in_args;
- guint n_out_args;
- guint n_args;
- guint n_py_args;
+ gssize n_in_args;
+ gssize n_out_args;
+ gssize n_args;
+ gssize n_py_args;
};
void _pygi_arg_cache_clear (PyGIArgCache *cache);
diff --git a/gi/pygi-invoke-state-struct.h b/gi/pygi-invoke-state-struct.h
index 22ac8ea..068fb66 100644
--- a/gi/pygi-invoke-state-struct.h
+++ b/gi/pygi-invoke-state-struct.h
@@ -10,7 +10,7 @@ G_BEGIN_DECLS
typedef struct _PyGIInvokeState
{
PyObject *py_in_args;
- gint n_py_in_args;
+ gssize n_py_in_args;
GIArgument **args;
GIArgument *in_args;
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index b4359c1..1669024 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -961,6 +961,16 @@ _invoke_marshal_in_args(PyGIInvokeState *state, PyGIFunctionCache *cache)
int i, in_count, out_count;
in_count = 0;
out_count = 0;
+
+ if (state->n_py_in_args > cache->n_py_args) {
+ PyErr_Format(PyExc_TypeError,
+ "%s() takes exactly %zd arguments (%zd given)",
+ cache->name,
+ cache->n_py_args,
+ state->n_py_in_args);
+ return FALSE;
+ }
+
for (i = 0; i < cache->n_args; i++) {
GIArgument *c_arg;
PyGIArgCache *arg_cache = cache->args_cache[i];
@@ -975,7 +985,15 @@ _invoke_marshal_in_args(PyGIInvokeState *state, PyGIFunctionCache *cache)
if (arg_cache->aux_type > 0)
continue;
- /* FIXME: get default or throw error if there aren't enough pyargs */
+ if (arg_cache->py_arg_index >= state->n_py_in_args) {
+ PyErr_Format(PyExc_TypeError,
+ "%s() takes exactly %zd arguments (%zd given)",
+ cache->name,
+ cache->n_py_args,
+ state->n_py_in_args);
+ return FALSE;
+ }
+
py_arg =
PyTuple_GET_ITEM(state->py_in_args,
arg_cache->py_arg_index);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]