Re: [PATCH] gjs: Use enum info from GI, to support unregistered enums
- From: Johan Bilien <jobi via ecp fr>
- To: language-bindings gnome org
- Subject: Re: [PATCH] gjs: Use enum info from GI, to support unregistered enums
- Date: Tue, 21 Oct 2008 13:11:47 +0200
The same without a leak :)
Index: gi/arg.c
===================================================================
--- gi/arg.c (revision 32)
+++ gi/arg.c (working copy)
@@ -354,26 +354,30 @@
} else if (JSVAL_IS_NUMBER(value)) {
nullable_type = FALSE;
- if (g_type_is_a(gtype, G_TYPE_ENUM)) {
+
+ if (g_base_info_get_type(symbol_info) == GI_INFO_TYPE_ENUM) {
if (!JS_ValueToInt32(context, value, &arg->v_int)) {
wrong = TRUE;
} else {
- GEnumValue *v;
- void *klass;
+ int n_values;
+ GIValueInfo *first_value;
+ GIValueInfo *last_value;
- klass = g_type_class_ref(gtype);
+ n_values = g_enum_info_get_n_values((GIEnumInfo *)symbol_info);
- v = g_enum_get_value(G_ENUM_CLASS(klass),
- arg->v_int);
+ first_value = g_enum_info_get_value((GIEnumInfo *)symbol_info, 0);
+ last_value = g_enum_info_get_value((GIEnumInfo *)symbol_info, n_values - 1);
- g_type_class_unref(klass);
-
- if (v == NULL) {
+ if (arg->v_int < g_value_info_get_value(first_value) ||
+ arg->v_int > g_value_info_get_value(last_value)) {
gjs_throw(context,
"%d is not a valid value for enumeration %s",
- arg->v_int, g_type_name(gtype));
+ arg->v_int, g_base_info_get_name(symbol_info));
wrong = TRUE;
}
+
+ g_base_info_unref((GIBaseInfo *)first_value);
+ g_base_info_unref((GIBaseInfo *)last_value);
}
} else if (g_type_is_a(gtype, G_TYPE_FLAGS)) {
if (!JS_ValueToInt32(context, value, &arg->v_int)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]