static JSBool boxed_field_setter (JSContext *context, JSObject *obj, jsid id, JSBool strict, jsval *value) { Boxed *priv; GIFieldInfo *field_info; gboolean success = FALSE; priv = priv_from_js(context, obj); if (!priv) return JS_FALSE; field_info = get_field_info(context, priv, id); if (!field_info) return JS_FALSE; if (priv->gboxed == NULL) { /* direct access to proto field */ gjs_throw(context, "Can't set field %s.%s on prototype", g_base_info_get_name ((GIBaseInfo *)priv->info), g_base_info_get_name ((GIBaseInfo *)field_info)); goto out; } success = boxed_set_field_from_value (context, priv, field_info, *value); out: g_base_info_unref ((GIBaseInfo *)field_info); return success; }
void list_headerline() { struct index_elem *e; int x_pos = 1, width; char *str = NULL; #if defined(A_BOLD) && defined(A_NORMAL) attrset(A_BOLD); #endif for(e = index_elements; e; e = e->next) if(e->type == INDEX_TEXT) x_pos += strwidth(e->d.text); else if(e->type == INDEX_FIELD) { get_field_info(e->d.field.id, NULL, &str, NULL); width = e->d.field.len ? abs(e->d.field.len) : strwidth(str); if(width + x_pos > COLS) width = bytes2width(str, COLS - x_pos); mvaddnstr(2, x_pos, str, width); x_pos += width; } else assert(0); #if defined(A_BOLD) && defined(A_NORMAL) attrset(A_NORMAL); #endif }
gint field_score (gint field) { FieldInfo *info = get_field_info (field); gint rval = 0; if (info) { return info->score_func (field); } return rval; }
void get_list_field(int item, struct index_elem *e, struct list_field *res) { char *s; res->data = s = NULL; do { /* find first non-empty field data in the alternate fields list */ s = db_fget_byid(item, e->d.field.id); } while(!(s && *s) && ((e = e->d.field.next) != NULL)); if(!e || !s || !*s) return; res->data = s; get_field_info(e->d.field.id, NULL, NULL, &res->type); }
static void generic_interface_init (gpointer iface, gpointer data) { GIInterfaceInfo *info = data; GIStructInfo *struct_info; gint n, i; struct_info = g_interface_info_get_iface_struct (info); n = g_interface_info_get_n_vfuncs (info); for (i = 0; i < n; i++) { GIVFuncInfo *vfunc_info; const gchar *vfunc_name; GIFieldInfo *field_info; gint field_offset; GITypeInfo *field_type_info; gchar *perl_method_name; GPerlI11nPerlCallbackInfo *callback_info; vfunc_info = g_interface_info_get_vfunc (info, i); vfunc_name = g_base_info_get_name (vfunc_info); /* FIXME: g_vfunc_info_get_offset does not seem to work here. */ field_info = get_field_info (struct_info, vfunc_name); g_assert (field_info); field_offset = g_field_info_get_offset (field_info); field_type_info = g_field_info_get_type (field_info); perl_method_name = g_ascii_strup (vfunc_name, -1); callback_info = create_perl_callback_closure_for_named_sub ( field_type_info, perl_method_name); dwarn ("installing vfunc %s as %s at offset %d (vs. %d) inside %p\n", vfunc_name, perl_method_name, field_offset, g_vfunc_info_get_offset (vfunc_info), iface); G_STRUCT_MEMBER (gpointer, iface, field_offset) = callback_info->closure; g_base_info_unref (field_type_info); g_base_info_unref (field_info); g_base_info_unref (vfunc_info); } g_base_info_unref (struct_info); }
static JSBool boxed_field_getter (JSContext *context, JSObject *obj, jsid id, jsval *value) { Boxed *priv; GIFieldInfo *field_info; GITypeInfo *type_info; GArgument arg; gboolean success = FALSE; priv = priv_from_js(context, obj); if (!priv) return JS_FALSE; field_info = get_field_info(context, priv, id); if (!field_info) return JS_FALSE; type_info = g_field_info_get_type (field_info); if (priv->gboxed == NULL) { /* direct access to proto field */ gjs_throw(context, "Can't get field %s.%s from a prototype", g_base_info_get_name ((GIBaseInfo *)priv->info), g_base_info_get_name ((GIBaseInfo *)field_info)); goto out; } if (!g_type_info_is_pointer (type_info) && g_type_info_get_tag (type_info) == GI_TYPE_TAG_INTERFACE) { GIBaseInfo *interface_info = g_type_info_get_interface(type_info); if (g_base_info_get_type (interface_info) == GI_INFO_TYPE_STRUCT || g_base_info_get_type (interface_info) == GI_INFO_TYPE_BOXED) { success = get_nested_interface_object (context, obj, priv, field_info, type_info, interface_info, value); g_base_info_unref ((GIBaseInfo *)interface_info); goto out; } g_base_info_unref ((GIBaseInfo *)interface_info); } if (!g_field_info_get_field (field_info, priv->gboxed, &arg)) { gjs_throw(context, "Reading field %s.%s is not supported", g_base_info_get_name ((GIBaseInfo *)priv->info), g_base_info_get_name ((GIBaseInfo *)field_info)); goto out; } if (!gjs_value_from_g_argument (context, value, type_info, &arg, TRUE)) goto out; success = TRUE; out: g_base_info_unref ((GIBaseInfo *)field_info); g_base_info_unref ((GIBaseInfo *)type_info); return success; }