static PyObject * _wrap_g_value_info_get_value (PyGIBaseInfo *self) { glong value; value = g_value_info_get_value ( (GIValueInfo *) self->info); return PYGLIB_PyLong_FromLong (value); }
/* * Handle definition of enums in a namespace. * Each enum class gets an object containing * a value for each member, all in uppercase * i.e. Gtk.WindowType.NORMAL */ static void seed_gi_importer_handle_enum(JSContextRef ctx, JSObjectRef namespace_ref, GIEnumInfo* info, JSValueRef* exception) { JSObjectRef enum_class; guint num_vals, i, j; gsize name_len; gint value; // TODO: investigate what's up with the glong/gint mystery here gchar* name; GIValueInfo* val; enum_class = JSObjectMake(ctx, 0, 0); num_vals = g_enum_info_get_n_values(info); seed_object_set_property(ctx, namespace_ref, g_base_info_get_name((GIBaseInfo*) info), enum_class); for (i = 0; i < num_vals; i++) { val = g_enum_info_get_value((GIEnumInfo*) info, i); value = g_value_info_get_value(val); name = g_strdup(g_base_info_get_name((GIBaseInfo*) val)); name_len = strlen(name); JSValueRef value_ref; value_ref = JSValueMakeNumber(ctx, value); JSValueProtect(ctx, (JSValueRef) value_ref); for (j = 0; j < name_len; j++) { if (name[j] == '-') name[j] = '_'; name[j] = g_ascii_toupper(name[j]); } seed_object_set_property(ctx, enum_class, name, value_ref); g_free(name); g_base_info_unref((GIBaseInfo*) val); } }
*/ #include "girwriter.h" void write_value_info( const gchar *namespace, GIValueInfo *info, Xml *file) { const gchar *name; gint64 value; gchar *value_str; gboolean deprecated; name = g_base_info_get_name((GIBaseInfo *) info); value = g_value_info_get_value(info); deprecated = g_base_info_is_deprecated((GIBaseInfo *) info); xml_start_element(file, "member"); value_str = g_strdup_printf ("%" G_GINT64_FORMAT, value); xml_printf(file, " name=\"%s\" value=\"%s\"", name, value_str); g_free(value_str); if (deprecated) xml_printf(file, " deprecated=\"1\""); write_attributes(file, (GIBaseInfo*) info); xml_end_element(file, "member"); }
static gboolean _pygi_marshal_from_py_interface_enum (PyGIInvokeState *state, PyGICallableCache *callable_cache, PyGIArgCache *arg_cache, PyObject *py_arg, GIArgument *arg, gpointer *cleanup_data) { PyObject *py_long; long c_long; gint is_instance; PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; GIBaseInfo *interface = NULL; is_instance = PyObject_IsInstance (py_arg, iface_cache->py_type); py_long = PYGLIB_PyNumber_Long (py_arg); if (py_long == NULL) { PyErr_Clear(); goto err; } c_long = PYGLIB_PyLong_AsLong (py_long); Py_DECREF (py_long); /* Write c_long into arg */ interface = g_type_info_get_interface (arg_cache->type_info); assert(g_base_info_get_type (interface) == GI_INFO_TYPE_ENUM); if (!gi_argument_from_c_long(arg, c_long, g_enum_info_get_storage_type ((GIEnumInfo *)interface))) { g_assert_not_reached(); g_base_info_unref (interface); return FALSE; } /* If this is not an instance of the Enum type that we want * we need to check if the value is equivilant to one of the * Enum's memebers */ if (!is_instance) { int i; gboolean is_found = FALSE; for (i = 0; i < g_enum_info_get_n_values (iface_cache->interface_info); i++) { GIValueInfo *value_info = g_enum_info_get_value (iface_cache->interface_info, i); gint64 enum_value = g_value_info_get_value (value_info); g_base_info_unref ( (GIBaseInfo *)value_info); if (c_long == enum_value) { is_found = TRUE; break; } } if (!is_found) goto err; } g_base_info_unref (interface); return TRUE; err: if (interface) g_base_info_unref (interface); PyErr_Format (PyExc_TypeError, "Expected a %s, but got %s", iface_cache->type_name, Py_TYPE (py_arg)->tp_name); return FALSE; }