gjs r111 - trunk/gi
- From: otaylor svn gnome org
- To: svn-commits-list gnome org
- Subject: gjs r111 - trunk/gi
- Date: Wed, 19 Nov 2008 22:30:29 +0000 (UTC)
Author: otaylor
Date: Wed Nov 19 22:30:29 2008
New Revision: 111
URL: http://svn.gnome.org/viewvc/gjs?rev=111&view=rev
Log:
Generalize argument functions to allow using for fields
This patch slightly modifies the functions in arg.h to allow using
for field storage as well. It does a general rename of ..._g_arg_...
to ..._g_argument_... to make it clear that what's being referred
to is GArgument not GIArgInfo.
gjs_value_to_g_arg_with_type_info() is exposed and renamed to
gjs_value_to_g_argument and the boolean argument is changed to an
enum (should improve the error messages a bit for existing uses.)
gjs_value_to_g_arg is renamed to gjs_value_to_arg() since it *is*
specific to GIArgInfo.
Modified:
trunk/gi/arg.c
trunk/gi/arg.h
trunk/gi/function.c
trunk/gi/repo.c
Modified: trunk/gi/arg.c
==============================================================================
--- trunk/gi/arg.c (original)
+++ trunk/gi/arg.c Wed Nov 19 22:30:29 2008
@@ -32,14 +32,6 @@
#include <util/log.h>
-static JSBool gjs_value_to_g_arg_with_type_info(JSContext *context,
- jsval value,
- GITypeInfo *type_info,
- const char *arg_name,
- gboolean is_return_value,
- gboolean may_be_null,
- GArgument *arg);
-
JSBool
_gjs_flags_value_is_valid(JSContext *context,
GFlagsClass *klass,
@@ -136,13 +128,13 @@
* gobject-introspection needs to tell us this.
* Always say they can't for now.
*/
- if (!gjs_value_to_g_arg_with_type_info(context,
- elem,
- param_info,
- "list element",
- FALSE,
- FALSE,
- &elem_arg)) {
+ if (!gjs_value_to_g_argument(context,
+ elem,
+ param_info,
+ NULL,
+ GJS_ARGUMENT_LIST_ELEMENT,
+ FALSE,
+ &elem_arg)) {
return JS_FALSE;
}
@@ -225,14 +217,32 @@
}
}
-static JSBool
-gjs_value_to_g_arg_with_type_info(JSContext *context,
- jsval value,
- GITypeInfo *type_info,
- const char *arg_name,
- gboolean is_return_value,
- gboolean may_be_null,
- GArgument *arg)
+static gchar *
+get_argument_display_name(const char *arg_name,
+ GjsArgumentType arg_type)
+{
+ switch (arg_type) {
+ case GJS_ARGUMENT_ARGUMENT:
+ return g_strdup_printf("Argument '%s'", arg_name);
+ case GJS_ARGUMENT_RETURN_VALUE:
+ return g_strdup("Return value");
+ case GJS_ARGUMENT_FIELD:
+ return g_strdup_printf("Field '%s'", arg_name);
+ case GJS_ARGUMENT_LIST_ELEMENT:
+ return g_strdup("List element");
+ }
+
+ g_assert_not_reached ();
+}
+
+JSBool
+gjs_value_to_g_argument(JSContext *context,
+ jsval value,
+ GITypeInfo *type_info,
+ const char *arg_name,
+ GjsArgumentType arg_type,
+ gboolean may_be_null,
+ GArgument *arg)
{
GITypeTag type_tag;
gboolean wrong;
@@ -603,29 +613,32 @@
if (G_UNLIKELY(wrong)) {
if (report_type_mismatch) {
- gjs_throw(context, "Expected type %s for %s '%s' but got type '%s' %p",
+ gchar *display_name = get_argument_display_name (arg_name, arg_type);
+ gjs_throw(context, "Expected type %s for %s but got type '%s' %p",
g_type_tag_to_string(type_tag),
- is_return_value ? "return value" : "argument",
- arg_name,
+ display_name,
JS_GetTypeName(context,
JS_TypeOfValue(context, value)),
JSVAL_IS_OBJECT(value) ? JSVAL_TO_OBJECT(value) : NULL);
+ g_free (display_name);
}
return JS_FALSE;
} else if (G_UNLIKELY(out_of_range)) {
- gjs_throw(context, "value is out of range for %s '%s' type %s",
- is_return_value ? "return value" : "argument",
- arg_name,
+ gchar *display_name = get_argument_display_name (arg_name, arg_type);
+ gjs_throw(context, "value is out of range for %s (type %s)",
+ display_name,
g_type_tag_to_string(type_tag));
+ g_free (display_name);
return JS_FALSE;
} else if (nullable_type &&
arg->v_pointer == NULL &&
!may_be_null) {
+ gchar *display_name = get_argument_display_name (arg_name, arg_type);
gjs_throw(context,
- "%s '%s' (type %s) may not be null",
- is_return_value ? "Return value" : "Argument",
- arg_name,
+ "%s (type %s) may not be null",
+ display_name,
g_type_tag_to_string(type_tag));
+ g_free (display_name);
return JS_FALSE;
} else {
return JS_TRUE;
@@ -633,10 +646,10 @@
}
JSBool
-gjs_value_to_g_arg(JSContext *context,
- jsval value,
- GIArgInfo *arg_info,
- GArgument *arg)
+gjs_value_to_arg(JSContext *context,
+ jsval value,
+ GIArgInfo *arg_info,
+ GArgument *arg)
{
GITypeInfo *type_info;
gboolean result;
@@ -644,13 +657,14 @@
type_info = g_arg_info_get_type(arg_info);
result =
- gjs_value_to_g_arg_with_type_info(context, value,
- type_info,
- g_base_info_get_name( (GIBaseInfo*) arg_info),
- g_arg_info_is_return_value(arg_info),
- g_arg_info_may_be_null(arg_info),
- arg);
-
+ gjs_value_to_g_argument(context, value,
+ type_info,
+ g_base_info_get_name( (GIBaseInfo*) arg_info),
+ (g_arg_info_is_return_value(arg_info) ?
+ GJS_ARGUMENT_RETURN_VALUE : GJS_ARGUMENT_ARGUMENT),
+ g_arg_info_may_be_null(arg_info),
+ arg);
+
g_base_info_unref((GIBaseInfo*) type_info);
return result;
@@ -689,8 +703,8 @@
for ( ; list != NULL; list = list->next) {
arg.v_pointer = list->data;
- if (!gjs_value_from_g_arg(context, &elem,
- param_info, &arg))
+ if (!gjs_value_from_g_argument(context, &elem,
+ param_info, &arg))
goto out;
if (!JS_DefineElement(context, obj,
@@ -704,8 +718,8 @@
for ( ; slist != NULL; slist = slist->next) {
arg.v_pointer = slist->data;
- if (!gjs_value_from_g_arg(context, &elem,
- param_info, &arg))
+ if (!gjs_value_from_g_argument(context, &elem,
+ param_info, &arg))
goto out;
if (!JS_DefineElement(context, obj,
@@ -726,10 +740,10 @@
}
JSBool
-gjs_value_from_g_arg (JSContext *context,
- jsval *value_p,
- GITypeInfo *type_info,
- GArgument *arg)
+gjs_value_from_g_argument (JSContext *context,
+ jsval *value_p,
+ GITypeInfo *type_info,
+ GArgument *arg)
{
GITypeTag type_tag;
@@ -1021,10 +1035,10 @@
GArgument elem;
elem.v_pointer = list->data;
- if (!gjs_g_arg_release(context,
- GI_TRANSFER_EVERYTHING,
- param_info,
- &elem)) {
+ if (!gjs_g_argument_release(context,
+ GI_TRANSFER_EVERYTHING,
+ param_info,
+ &elem)) {
/* no way to recover here, and errors should
* not be possible.
*/
@@ -1070,10 +1084,10 @@
GArgument elem;
elem.v_pointer = slist->data;
- if (!gjs_g_arg_release(context,
- GI_TRANSFER_EVERYTHING,
- param_info,
- &elem)) {
+ if (!gjs_g_argument_release(context,
+ GI_TRANSFER_EVERYTHING,
+ param_info,
+ &elem)) {
/* no way to recover here, and errors should
* not be possible.
*/
@@ -1098,10 +1112,10 @@
}
JSBool
-gjs_g_arg_release(JSContext *context,
- GITransfer transfer,
- GITypeInfo *type_info,
- GArgument *arg)
+gjs_g_argument_release(JSContext *context,
+ GITransfer transfer,
+ GITypeInfo *type_info,
+ GArgument *arg)
{
GITypeTag type_tag;
@@ -1118,10 +1132,10 @@
}
JSBool
-gjs_g_arg_release_in_arg(JSContext *context,
- GITransfer transfer,
- GITypeInfo *type_info,
- GArgument *arg)
+gjs_g_argument_release_in_arg(JSContext *context,
+ GITransfer transfer,
+ GITypeInfo *type_info,
+ GArgument *arg)
{
GITypeTag type_tag;
Modified: trunk/gi/arg.h
==============================================================================
--- trunk/gi/arg.h (original)
+++ trunk/gi/arg.h Wed Nov 19 22:30:29 2008
@@ -32,22 +32,39 @@
G_BEGIN_DECLS
-JSBool gjs_value_to_g_arg (JSContext *context,
- jsval value,
- GIArgInfo *arg_info,
- GArgument *arg);
-JSBool gjs_value_from_g_arg (JSContext *context,
- jsval *value_p,
- GITypeInfo *type_info,
- GArgument *arg);
-JSBool gjs_g_arg_release (JSContext *context,
- GITransfer transfer,
- GITypeInfo *type_info,
- GArgument *arg);
-JSBool gjs_g_arg_release_in_arg (JSContext *context,
- GITransfer transfer,
- GITypeInfo *type_info,
- GArgument *arg);
+/* Different roles for a GArgument */
+typedef enum {
+ GJS_ARGUMENT_ARGUMENT,
+ GJS_ARGUMENT_RETURN_VALUE,
+ GJS_ARGUMENT_FIELD,
+ GJS_ARGUMENT_LIST_ELEMENT
+} GjsArgumentType;
+
+JSBool gjs_value_to_arg (JSContext *context,
+ jsval value,
+ GIArgInfo *arg_info,
+ GArgument *arg);
+
+JSBool gjs_value_to_g_argument (JSContext *context,
+ jsval value,
+ GITypeInfo *type_info,
+ const char *arg_name,
+ GjsArgumentType argument_type,
+ gboolean may_be_null,
+ GArgument *arg);
+
+JSBool gjs_value_from_g_argument (JSContext *context,
+ jsval *value_p,
+ GITypeInfo *type_info,
+ GArgument *arg);
+JSBool gjs_g_argument_release (JSContext *context,
+ GITransfer transfer,
+ GITypeInfo *type_info,
+ GArgument *arg);
+JSBool gjs_g_argument_release_in_arg (JSContext *context,
+ GITransfer transfer,
+ GITypeInfo *type_info,
+ GArgument *arg);
JSBool _gjs_flags_value_is_valid (JSContext *context,
GFlagsClass *klass,
Modified: trunk/gi/function.c
==============================================================================
--- trunk/gi/function.c (original)
+++ trunk/gi/function.c Wed Nov 19 22:30:29 2008
@@ -204,8 +204,8 @@
if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) {
GArgument in_value;
- if (!gjs_value_to_g_arg(context, argv[argv_pos], arg_info,
- &in_value)) {
+ if (!gjs_value_to_arg(context, argv[argv_pos], arg_info,
+ &in_value)) {
failed = TRUE;
}
@@ -271,17 +271,17 @@
if (return_tag != GI_TYPE_TAG_VOID) {
if (invoke_ok &&
- !gjs_value_from_g_arg(context, &return_values[next_rval],
- return_info, &return_arg)) {
+ !gjs_value_from_g_argument(context, &return_values[next_rval],
+ return_info, &return_arg)) {
failed = TRUE;
}
/* Free GArgument, the jsval should have ref'd or copied it */
if (invoke_ok &&
- !gjs_g_arg_release(context,
- g_callable_info_get_caller_owns((GICallableInfo*) info),
- return_info,
- &return_arg))
+ !gjs_g_argument_release(context,
+ g_callable_info_get_caller_owns((GICallableInfo*) info),
+ return_info,
+ &return_arg))
failed = TRUE;
++next_rval;
@@ -307,10 +307,10 @@
if (direction == GI_DIRECTION_IN) {
g_assert(in_args_pos < expected_in_argc);
- if (!gjs_g_arg_release_in_arg(context,
- g_arg_info_get_ownership_transfer(arg_info),
- arg_type_info,
- &in_args[in_args_pos]))
+ if (!gjs_g_argument_release_in_arg(context,
+ g_arg_info_get_ownership_transfer(arg_info),
+ arg_type_info,
+ &in_args[in_args_pos]))
failed = TRUE;
++in_args_pos;
@@ -322,19 +322,19 @@
g_assert(out_args_pos < expected_out_argc);
if (invoke_ok &&
- !gjs_value_from_g_arg(context,
- &return_values[next_rval],
- arg_type_info,
- out_args[out_args_pos].v_pointer)) {
+ !gjs_value_from_g_argument(context,
+ &return_values[next_rval],
+ arg_type_info,
+ out_args[out_args_pos].v_pointer)) {
failed = TRUE;
}
/* Free GArgument, the jsval should have ref'd or copied it */
if (invoke_ok &&
- !gjs_g_arg_release(context,
- g_arg_info_get_ownership_transfer(arg_info),
- arg_type_info,
- out_args[out_args_pos].v_pointer))
+ !gjs_g_argument_release(context,
+ g_arg_info_get_ownership_transfer(arg_info),
+ arg_type_info,
+ out_args[out_args_pos].v_pointer))
failed = TRUE;
if (direction == GI_DIRECTION_INOUT)
Modified: trunk/gi/repo.c
==============================================================================
--- trunk/gi/repo.c (original)
+++ trunk/gi/repo.c Wed Nov 19 22:30:29 2008
@@ -329,7 +329,7 @@
type_info = g_constant_info_get_type(info);
g_constant_info_get_value(info, &garg);
- if (!gjs_value_from_g_arg(context, &value, type_info, &garg)) {
+ if (!gjs_value_from_g_argument(context, &value, type_info, &garg)) {
g_base_info_unref((GIBaseInfo*) type_info);
return JS_FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]