static void * _get_func(GIObjectInfo *info, SymbolGetter getter) { const char* symbol; GSList *parents = NULL, *l; GIObjectInfo *parent_info; gpointer func = NULL; parent_info = g_base_info_ref (info); while (parent_info != NULL) { parents = g_slist_prepend (parents, parent_info); parent_info = g_object_info_get_parent (parent_info); } for (l = parents; l; l = l->next) { parent_info = l->data; symbol = getter (parent_info); if (symbol == NULL) continue; g_typelib_symbol (((GIRealInfo *)parent_info)->typelib, symbol, (gpointer*) &func); if (func) break; } g_slist_free_full (parents, (GDestroyNotify) g_base_info_unref); return func; }
static PyObject * _wrap_g_object_info_get_parent (PyGIBaseInfo *self) { GIBaseInfo *info; PyObject *py_info; info = (GIBaseInfo *) g_object_info_get_parent ( (GIObjectInfo*) self->info); if (info == NULL) { Py_RETURN_NONE; } py_info = _pygi_info_new (info); g_base_info_unref (info); return py_info; }
/* a hook on getting a property; set value_p to override property's value. * Return value is JS_FALSE on OOM/exception. */ static JSBool param_get_prop(JSContext *context, JSObject *obj, jsid id, jsval *value_p) { JSBool success; Param *priv; GParamSpec *pspec; char *name; GType gtype; GIObjectInfo *info = NULL, *parent_info = NULL; GIFieldInfo *field_info = NULL; GITypeInfo *type_info = NULL; GIArgument arg; if (!gjs_get_string_id(context, id, &name)) return JS_TRUE; /* not something we affect, but no error */ priv = priv_from_js(context, obj); if (priv == NULL) { g_free(name); return JS_FALSE; /* wrong class */ } success = JS_FALSE; pspec = priv->gparam; gtype = G_TYPE_FROM_INSTANCE(pspec); info = (GIObjectInfo*)g_irepository_find_by_gtype(g_irepository_get_default(), gtype); if (info == NULL) { /* We may have a non-introspectable GParamSpec subclass here. Just return VOID. */ *value_p = JSVAL_VOID; success = JS_TRUE; goto out; } parent_info = g_object_info_get_parent(info); field_info = find_field_info(info, name); if (field_info == NULL) { /* Try it on the parent GParamSpec for generic GParamSpec properties. */ field_info = find_field_info(parent_info, name); } if (field_info == NULL) { *value_p = JSVAL_VOID; success = JS_TRUE; goto out; } type_info = g_field_info_get_type(field_info); if (!g_field_info_get_field(field_info, priv->gparam, &arg)) { gjs_throw(context, "Reading field %s.%s is not supported", g_base_info_get_name(info), g_base_info_get_name((GIBaseInfo*)field_info)); goto out; } if (!gjs_value_from_g_argument(context, value_p, type_info, &arg, TRUE)) goto out; success = JS_TRUE; out: if (field_info != NULL) g_base_info_unref((GIBaseInfo*)field_info); if (type_info != NULL) g_base_info_unref((GIBaseInfo*)type_info); if (info != NULL) g_base_info_unref((GIBaseInfo*)info); if (parent_info != NULL) g_base_info_unref((GIBaseInfo*)parent_info); g_free(name); return success; }