[PATCH] gjs: Use enum info from GI, to support unregistered enums



-- 
Johan Bilien
<jobi via ecp fr>
Index: gi/arg.c
===================================================================
--- gi/arg.c	(revision 32)
+++ gi/arg.c	(working copy)
@@ -354,24 +354,20 @@
 
             } 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;
 
-                        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);
-
-                        g_type_class_unref(klass);
-
-                        if (v == NULL) {
+                        if (arg->v_int < g_value_info_get_value(g_enum_info_get_value((GIEnumInfo *)symbol_info, 0)) ||
+                            arg->v_int > g_value_info_get_value(g_enum_info_get_value((GIEnumInfo *)symbol_info, n_values - 1))) {
                             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;
                         }
                     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]