void * _pygi_boxed_alloc (GIBaseInfo *info, gsize *size_out) { gsize size; /* FIXME: Remove when bgo#622711 is fixed */ if (g_registered_type_info_get_g_type (info) == G_TYPE_VALUE) { size = sizeof (GValue); } else { switch (g_base_info_get_type (info)) { case GI_INFO_TYPE_UNION: size = g_union_info_get_size ( (GIUnionInfo *) info); break; case GI_INFO_TYPE_BOXED: case GI_INFO_TYPE_STRUCT: size = g_struct_info_get_size ( (GIStructInfo *) info); break; default: PyErr_Format (PyExc_TypeError, "info should be Boxed or Union, not '%d'", g_base_info_get_type (info)); return NULL; } } if( size_out != NULL) *size_out = size; return g_slice_alloc0 (size); }
int lgi_type_get_name (lua_State *L, GIBaseInfo *info) { GSList *list = NULL, *i; int n = 1; lua_pushstring (L, g_base_info_get_namespace (info)); if (g_base_info_get_type (info) == GI_INFO_TYPE_CALLBACK) /* Avoid duplicate name for callbacks. */ info = g_base_info_get_container (info); /* Add names on the whole path, but in reverse order. */ for (; info != NULL; info = g_base_info_get_container (info)) if (!GI_IS_TYPE_INFO (info)) list = g_slist_prepend (list, info); for (i = list; i != NULL; i = g_slist_next (i)) { if (g_base_info_get_type (i->data) != GI_INFO_TYPE_TYPE) { lua_pushstring (L, "."); lua_pushstring (L, g_base_info_get_name (i->data)); n += 2; } } g_slist_free (list); return n; }
PyObject * _wrap_g_callable_info_invoke (PyGIBaseInfo *self, PyObject *py_args, PyObject *kwargs) { if (self->cache == NULL) { PyGIFunctionCache *function_cache; GIInfoType type = g_base_info_get_type (self->info); if (type == GI_INFO_TYPE_FUNCTION) { GIFunctionInfoFlags flags; flags = g_function_info_get_flags ( (GIFunctionInfo *)self->info); if (flags & GI_FUNCTION_IS_CONSTRUCTOR) { function_cache = pygi_constructor_cache_new (self->info); } else if (flags & GI_FUNCTION_IS_METHOD) { function_cache = pygi_method_cache_new (self->info); } else { function_cache = pygi_function_cache_new (self->info); } } else if (type == GI_INFO_TYPE_VFUNC) { function_cache = pygi_vfunc_cache_new (self->info); } else if (type == GI_INFO_TYPE_CALLBACK) { g_error ("Cannot invoke callback types"); } else { function_cache = pygi_method_cache_new (self->info); } self->cache = (PyGICallableCache *)function_cache; if (self->cache == NULL) return NULL; } return pygi_callable_info_invoke (self->info, py_args, kwargs, self->cache, NULL); }
bool gjs_lookup_interface_constructor(JSContext *context, GType gtype, JS::MutableHandleValue value_p) { JSObject *constructor; GIBaseInfo *interface_info; interface_info = g_irepository_find_by_gtype(NULL, gtype); if (interface_info == NULL) { gjs_throw(context, "Cannot expose non introspectable interface %s", g_type_name(gtype)); return false; } g_assert(g_base_info_get_type(interface_info) == GI_INFO_TYPE_INTERFACE); constructor = gjs_lookup_generic_constructor(context, interface_info); if (G_UNLIKELY (constructor == NULL)) return false; g_base_info_unref(interface_info); value_p.setObject(*constructor); return true; }
PyObject * _pygi_marshal_to_py_interface_enum (PyGIInvokeState *state, PyGICallableCache *callable_cache, PyGIArgCache *arg_cache, GIArgument *arg) { PyObject *py_obj = NULL; PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; GIBaseInfo *interface; long c_long; interface = g_type_info_get_interface (arg_cache->type_info); g_assert (g_base_info_get_type (interface) == GI_INFO_TYPE_ENUM); if (!gi_argument_to_c_long(arg, &c_long, g_enum_info_get_storage_type ((GIEnumInfo *)interface))) { return NULL; } if (iface_cache->g_type == G_TYPE_NONE) { py_obj = PyObject_CallFunction (iface_cache->py_type, "l", c_long); } else { py_obj = pyg_enum_from_gtype (iface_cache->g_type, c_long); } g_base_info_unref (interface); return py_obj; }
GICallableInfo * peas_gi_get_method_info (GType iface_type, const gchar *method_name) { GIRepository *repo; GIBaseInfo *iface_info; GIFunctionInfo *func_info; repo = g_irepository_get_default (); iface_info = g_irepository_find_by_gtype (repo, iface_type); if (iface_info == NULL) { g_warning ("Type not found in introspection: '%s'", g_type_name (iface_type)); return NULL; } switch (g_base_info_get_type (iface_info)) { case GI_INFO_TYPE_OBJECT: func_info = g_object_info_find_method ((GIObjectInfo *) iface_info, method_name); break; case GI_INFO_TYPE_INTERFACE: func_info = g_interface_info_find_method ((GIInterfaceInfo *) iface_info, method_name); break; default: func_info = NULL; } g_base_info_unref (iface_info); return (GICallableInfo *) func_info; }
static JSBool fundamental_instance_new_resolve_interface(JSContext *context, JS::HandleObject obj, JS::MutableHandleObject objp, Fundamental *proto_priv, char *name) { GIFunctionInfo *method_info; JSBool ret; GType *interfaces; guint n_interfaces; guint i; ret = JS_TRUE; interfaces = g_type_interfaces(proto_priv->gtype, &n_interfaces); for (i = 0; i < n_interfaces; i++) { GIBaseInfo *base_info; GIInterfaceInfo *iface_info; base_info = g_irepository_find_by_gtype(g_irepository_get_default(), interfaces[i]); if (base_info == NULL) continue; /* An interface GType ought to have interface introspection info */ g_assert(g_base_info_get_type(base_info) == GI_INFO_TYPE_INTERFACE); iface_info = (GIInterfaceInfo *) base_info; method_info = g_interface_info_find_method(iface_info, name); g_base_info_unref(base_info); if (method_info != NULL) { if (g_function_info_get_flags (method_info) & GI_FUNCTION_IS_METHOD) { if (gjs_define_function(context, obj, proto_priv->gtype, (GICallableInfo *) method_info)) { objp.set(obj); } else { ret = JS_FALSE; } } g_base_info_unref((GIBaseInfo *) method_info); } } g_free(interfaces); return ret; }
static PyObject * _wrap_g_enum_info_is_flags (PyGIBaseInfo *self) { GIInfoType info_type = g_base_info_get_type ((GIBaseInfo *) self->info); if (info_type == GI_INFO_TYPE_ENUM) { Py_RETURN_FALSE; } else if (info_type == GI_INFO_TYPE_FLAGS) { Py_RETURN_TRUE; } else { g_assert_not_reached(); } }
static void prepare_invocation_info (GPerlI11nInvocationInfo *iinfo, GICallableInfo *info) { gint orig_n_args; guint i; dwarn ("invoke: %s\n" " n_args: %d\n", g_base_info_get_name (info), g_callable_info_get_n_args (info)); iinfo->interface = info; iinfo->is_function = GI_IS_FUNCTION_INFO (info); iinfo->is_vfunc = GI_IS_VFUNC_INFO (info); iinfo->is_callback = (g_base_info_get_type (info) == GI_INFO_TYPE_CALLBACK); iinfo->is_signal = GI_IS_SIGNAL_INFO (info); dwarn (" is_function = %d, is_vfunc = %d, is_callback = %d\n", iinfo->is_function, iinfo->is_vfunc, iinfo->is_callback); orig_n_args = g_callable_info_get_n_args (info); g_assert (orig_n_args >= 0); iinfo->n_args = (guint) orig_n_args; if (iinfo->n_args) { iinfo->arg_infos = gperl_alloc_temp (sizeof (GITypeInfo*) * iinfo->n_args); iinfo->arg_types = gperl_alloc_temp (sizeof (GITypeInfo*) * iinfo->n_args); iinfo->aux_args = gperl_alloc_temp (sizeof (GIArgument) * iinfo->n_args); } else { iinfo->arg_infos = NULL; iinfo->arg_types = NULL; iinfo->aux_args = NULL; } for (i = 0 ; i < iinfo->n_args ; i++) { iinfo->arg_infos[i] = g_callable_info_get_arg (info, (gint) i); iinfo->arg_types[i] = g_arg_info_get_type (iinfo->arg_infos[i]); } iinfo->return_type_info = g_callable_info_get_return_type (info); iinfo->has_return_value = GI_TYPE_TAG_VOID != g_type_info_get_tag (iinfo->return_type_info); iinfo->return_type_ffi = g_type_info_get_ffi_type (iinfo->return_type_info); iinfo->return_type_transfer = g_callable_info_get_caller_owns (info); iinfo->callback_infos = NULL; iinfo->array_infos = NULL; iinfo->free_after_call = NULL; }
static void initialize_receiver(VALUE receiver, GITypeInfo *info, GIArgument *value) { GIBaseInfo *interface_info; GIInfoType interface_type; if (g_type_info_get_tag(info) != GI_TYPE_TAG_INTERFACE) { rb_raise(rb_eRuntimeError, "TODO: returned value isn't interface"); } interface_info = g_type_info_get_interface(info); interface_type = g_base_info_get_type(interface_info); g_base_info_unref(interface_info); switch (interface_type) { case GI_INFO_TYPE_OBJECT: G_INITIALIZE(receiver, value->v_pointer); break; case GI_INFO_TYPE_STRUCT: G_INITIALIZE(receiver, value->v_pointer); break; case GI_INFO_TYPE_INVALID: case GI_INFO_TYPE_FUNCTION: case GI_INFO_TYPE_CALLBACK: case GI_INFO_TYPE_BOXED: case GI_INFO_TYPE_ENUM: case GI_INFO_TYPE_FLAGS: case GI_INFO_TYPE_INTERFACE: case GI_INFO_TYPE_CONSTANT: case GI_INFO_TYPE_INVALID_0: rb_raise(rb_eRuntimeError, "TODO: returned value isn't object, struct or union"); break; case GI_INFO_TYPE_UNION: G_INITIALIZE(receiver, value->v_pointer); break; case GI_INFO_TYPE_VALUE: case GI_INFO_TYPE_SIGNAL: case GI_INFO_TYPE_VFUNC: case GI_INFO_TYPE_PROPERTY: case GI_INFO_TYPE_FIELD: case GI_INFO_TYPE_ARG: case GI_INFO_TYPE_TYPE: case GI_INFO_TYPE_UNRESOLVED: default: rb_raise(rb_eRuntimeError, "TODO: returned value isn't object, struct or union"); break; } }
static PyObject * _pygi_marshal_to_py_interface_flags (PyGIInvokeState *state, PyGICallableCache *callable_cache, PyGIArgCache *arg_cache, GIArgument *arg, gpointer *cleanup_data) { PyObject *py_obj = NULL; PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; GIBaseInfo *interface; long c_long; interface = g_type_info_get_interface (arg_cache->type_info); g_assert (g_base_info_get_type (interface) == GI_INFO_TYPE_FLAGS); if (!gi_argument_to_c_long(arg, &c_long, g_enum_info_get_storage_type ((GIEnumInfo *)interface))) { g_base_info_unref (interface); return NULL; } g_base_info_unref (interface); if (iface_cache->g_type == G_TYPE_NONE) { /* An enum with a GType of None is an enum without GType */ PyObject *py_type = pygi_type_import_by_gi_info (iface_cache->interface_info); PyObject *py_args = NULL; if (!py_type) return NULL; py_args = PyTuple_New (1); if (PyTuple_SetItem (py_args, 0, PyLong_FromLong (c_long)) != 0) { Py_DECREF (py_args); Py_DECREF (py_type); return NULL; } py_obj = PyObject_CallFunction (py_type, "l", c_long); Py_DECREF (py_args); Py_DECREF (py_type); } else { py_obj = pyg_flags_from_gtype (iface_cache->g_type, (guint)c_long); } return py_obj; }
static gboolean _pygi_marshal_from_py_interface_flags (PyGIInvokeState *state, PyGICallableCache *callable_cache, PyGIArgCache *arg_cache, PyObject *py_arg, GIArgument *arg, gpointer *cleanup_data) { PyObject *py_long; unsigned long c_ulong; gint is_instance; PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; GIBaseInfo *interface; 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_ulong = PYGLIB_PyLong_AsUnsignedLong (py_long); Py_DECREF (py_long); /* only 0 or argument of type Flag is allowed */ if (!is_instance && c_ulong != 0) goto err; /* Write c_long into arg */ interface = g_type_info_get_interface (arg_cache->type_info); g_assert (g_base_info_get_type (interface) == GI_INFO_TYPE_FLAGS); if (!gi_argument_from_c_long(arg, c_ulong, g_enum_info_get_storage_type ((GIEnumInfo *)interface))) { g_base_info_unref (interface); return FALSE; } g_base_info_unref (interface); return TRUE; err: PyErr_Format (PyExc_TypeError, "Expected a %s, but got %s", iface_cache->type_name, Py_TYPE (py_arg)->tp_name); return FALSE; }
/* Retrieves pointer to GIArgument in given array, given that array contains elements of type ti. */ static gssize array_get_elt_size (GITypeInfo *ti) { gssize size = sizeof (gpointer); if (!g_type_info_is_pointer (ti)) { switch (g_type_info_get_tag (ti)) { #define HANDLE_ELT(nameupper, nametype) \ case GI_TYPE_TAG_ ## nameupper: \ return sizeof (nametype); HANDLE_ELT(BOOLEAN, gboolean); HANDLE_ELT(INT8, gint8); HANDLE_ELT(UINT8, guint8); HANDLE_ELT(INT16, gint16); HANDLE_ELT(UINT16, guint16); HANDLE_ELT(INT32, gint32); HANDLE_ELT(UINT32, guint32); HANDLE_ELT(UNICHAR, guint32); HANDLE_ELT(INT64, gint64); HANDLE_ELT(UINT64, guint64); HANDLE_ELT(FLOAT, gfloat); HANDLE_ELT(DOUBLE, gdouble); HANDLE_ELT(GTYPE, GType); #undef HANDLE_ELT case GI_TYPE_TAG_INTERFACE: { GIBaseInfo *info = g_type_info_get_interface (ti); GIInfoType type = g_base_info_get_type (info); if (type == GI_INFO_TYPE_STRUCT) size = g_struct_info_get_size (info); else if (type == GI_INFO_TYPE_UNION) size = g_union_info_get_size (info); g_base_info_unref (info); break; } default: break; } } return size; }
static gboolean gobject_based_p(GIBaseInfo *info) { GIBaseInfo *container_info; GIRegisteredTypeInfo *registered_type_info; container_info = g_base_info_get_container(info); if (g_base_info_get_type(container_info) != GI_INFO_TYPE_STRUCT) { return TRUE; } registered_type_info = (GIRegisteredTypeInfo *)container_info; if (g_registered_type_info_get_type_init(registered_type_info)) { return TRUE; } return FALSE; }
static gboolean source_func_p(GIArgInfo *info) { GITypeInfo type_info; GIBaseInfo *interface_info; GICallableInfo *callback_info; GITypeInfo return_type_info; GIArgInfo first_arg_info; GITypeInfo first_arg_type_info; g_arg_info_load_type(info, &type_info); if (g_type_info_get_tag(&type_info) != GI_TYPE_TAG_INTERFACE) { return FALSE; } interface_info = g_type_info_get_interface(&type_info); if (g_base_info_get_type(interface_info) != GI_INFO_TYPE_CALLBACK) { g_base_info_unref(interface_info); return FALSE; } callback_info = (GICallableInfo *)interface_info; g_callable_info_load_return_type(callback_info, &return_type_info); if (g_type_info_get_tag(&return_type_info) != GI_TYPE_TAG_BOOLEAN) { g_base_info_unref(interface_info); return FALSE; } if (g_callable_info_get_n_args(interface_info) != 1) { g_base_info_unref(interface_info); return FALSE; } g_callable_info_load_arg(interface_info, 0, &first_arg_info); g_arg_info_load_type(&first_arg_info, &first_arg_type_info); if (g_type_info_get_tag(&first_arg_type_info) != GI_TYPE_TAG_VOID) { g_base_info_unref(interface_info); return FALSE; } g_base_info_unref(interface_info); return TRUE; }
int main(int argc, char **argv) { GIRepository *repo; GITypelib *ret; GIBaseInfo *info; GIArgument in_arg[1]; GIArgument ret_arg; GError *error; gboolean invoke_return; repo = g_irepository_get_default (); error = NULL; ret = g_irepository_require (repo, "GLib", NULL, 0, &error); g_assert (ret != NULL); g_assert (error == NULL); info = g_irepository_find_by_name (repo, "GLib", "file_read_link"); g_assert (info != NULL); g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_FUNCTION); g_assert (g_function_info_get_flags ((GIFunctionInfo *)info) & GI_FUNCTION_THROWS); in_arg[0].v_string = g_strdup ("non-existent-file/hope"); error = NULL; invoke_return = g_function_info_invoke ((GIFunctionInfo *)info, in_arg, 1, NULL, 0, &ret_arg, &error); g_free(in_arg[0].v_string); g_assert (invoke_return == FALSE); g_assert (error != NULL); g_assert (error->domain == G_FILE_ERROR); g_assert (error->code == G_FILE_ERROR_NOENT); exit(0); }
static void rb_gi_in_argument_free_interface(GIArgument *argument, GITypeInfo *type_info) { GIBaseInfo *interface_info; GIInfoType interface_type; interface_info = g_type_info_get_interface(type_info); interface_type = g_base_info_get_type(interface_info); if (interface_type == GI_INFO_TYPE_STRUCT) { GType gtype; gtype = g_registered_type_info_get_g_type(interface_info); if (gtype == G_TYPE_VALUE) { GValue *gvalue = argument->v_pointer; g_value_unset(gvalue); xfree(argument->v_pointer); } } g_base_info_unref(interface_info); }
PyGICClosure* _pygi_destroy_notify_create (void) { if (!global_destroy_notify) { PyGICClosure *destroy_notify = g_slice_new0 (PyGICClosure); g_assert (destroy_notify); GIBaseInfo* glib_destroy_notify = g_irepository_find_by_name (NULL, "GLib", "DestroyNotify"); g_assert (glib_destroy_notify != NULL); g_assert (g_base_info_get_type (glib_destroy_notify) == GI_INFO_TYPE_CALLBACK); destroy_notify->closure = g_callable_info_prepare_closure ( (GICallableInfo*) glib_destroy_notify, &destroy_notify->cif, _pygi_destroy_notify_callback_closure, NULL); global_destroy_notify = destroy_notify; } return global_destroy_notify; }
/** * g_type_info_get_ffi_type: * @info: A #GITypeInfo * * Returns: A #ffi_type corresponding to the platform default C ABI for @info. */ ffi_type * g_type_info_get_ffi_type (GITypeInfo *info) { gboolean is_enum = FALSE; GIBaseInfo *iinfo; if (g_type_info_get_tag (info) == GI_TYPE_TAG_INTERFACE) { iinfo = g_type_info_get_interface (info); switch (g_base_info_get_type (iinfo)) { case GI_INFO_TYPE_ENUM: case GI_INFO_TYPE_FLAGS: is_enum = TRUE; break; default: break; } g_base_info_unref (iinfo); } return gi_type_tag_get_ffi_type_internal (g_type_info_get_tag (info), g_type_info_is_pointer (info), is_enum); }
PyObject * _pygi_info_new (GIBaseInfo *info) { GIInfoType info_type; PyTypeObject *type = NULL; PyGIBaseInfo *self; info_type = g_base_info_get_type (info); switch (info_type) { case GI_INFO_TYPE_INVALID: PyErr_SetString (PyExc_RuntimeError, "Invalid info type"); return NULL; case GI_INFO_TYPE_FUNCTION: type = &PyGIFunctionInfo_Type; break; case GI_INFO_TYPE_CALLBACK: type = &PyGICallbackInfo_Type; break; case GI_INFO_TYPE_STRUCT: type = &PyGIStructInfo_Type; break; case GI_INFO_TYPE_BOXED: type = &PyGIBoxedInfo_Type; break; case GI_INFO_TYPE_ENUM: case GI_INFO_TYPE_FLAGS: type = &PyGIEnumInfo_Type; break; case GI_INFO_TYPE_OBJECT: type = &PyGIObjectInfo_Type; break; case GI_INFO_TYPE_INTERFACE: type = &PyGIInterfaceInfo_Type; break; case GI_INFO_TYPE_CONSTANT: type = &PyGIConstantInfo_Type; break; case GI_INFO_TYPE_UNION: type = &PyGIUnionInfo_Type; break; case GI_INFO_TYPE_VALUE: type = &PyGIValueInfo_Type; break; case GI_INFO_TYPE_SIGNAL: type = &PyGISignalInfo_Type; break; case GI_INFO_TYPE_VFUNC: type = &PyGIVFuncInfo_Type; break; case GI_INFO_TYPE_PROPERTY: type = &PyGIPropertyInfo_Type; break; case GI_INFO_TYPE_FIELD: type = &PyGIFieldInfo_Type; break; case GI_INFO_TYPE_ARG: type = &PyGIArgInfo_Type; break; case GI_INFO_TYPE_TYPE: type = &PyGITypeInfo_Type; break; case GI_INFO_TYPE_UNRESOLVED: type = &PyGIUnresolvedInfo_Type; break; default: g_assert_not_reached(); break; } self = (PyGIBaseInfo *) type->tp_alloc (type, 0); if (self == NULL) { return NULL; } self->info = g_base_info_ref (info); return (PyObject *) self; }
static void create_native_closure (GType interface_type, GIInterfaceInfo *iface_info, GIVFuncInfo *vfunc_info, MethodImpl *impl) { GIFunctionInfo *invoker_info; GIStructInfo *struct_info; GIFieldInfo *field_info; GITypeInfo *type_info; GICallbackInfo *callback_info; guint n_fields, i; gboolean found_field_info; invoker_info = g_vfunc_info_get_invoker (vfunc_info); if (invoker_info == NULL) { g_debug ("No invoker for VFunc '%s.%s'", g_base_info_get_name (iface_info), g_base_info_get_name (vfunc_info)); return; } struct_info = g_interface_info_get_iface_struct (iface_info); n_fields = g_struct_info_get_n_fields (struct_info); found_field_info = FALSE; for (i = 0; i < n_fields; i++) { field_info = g_struct_info_get_field (struct_info, i); if (strcmp (g_base_info_get_name (field_info), g_base_info_get_name (vfunc_info)) == 0) { found_field_info = TRUE; break; } g_base_info_unref (field_info); } if (!found_field_info) { g_debug ("No struct field for VFunc '%s.%s'", g_base_info_get_name (iface_info), g_base_info_get_name (vfunc_info)); g_base_info_unref (struct_info); g_base_info_unref (invoker_info); return; } type_info = g_field_info_get_type (field_info); g_assert (g_type_info_get_tag (type_info) == GI_TYPE_TAG_INTERFACE); callback_info = g_type_info_get_interface (type_info); g_assert (g_base_info_get_type (callback_info) == GI_INFO_TYPE_CALLBACK); impl->interface_type = interface_type; impl->invoker_info = invoker_info; impl->method_name = g_base_info_get_name (invoker_info); impl->closure = g_callable_info_prepare_closure (callback_info, &impl->cif, handle_method_impl, impl); impl->struct_offset = g_field_info_get_offset (field_info); g_base_info_unref (callback_info); g_base_info_unref (type_info); g_base_info_unref (field_info); g_base_info_unref (struct_info); }
static void implement_interface_methods (gpointer iface, GType proxy_type) { GType exten_type = G_TYPE_FROM_INTERFACE (iface); guint i; GArray *impls; g_debug ("Implementing interface '%s' for proxy type '%s'", g_type_name (exten_type), g_type_name (proxy_type)); impls = g_type_get_qdata (exten_type, method_impl_quark ()); if (impls == NULL) { GIInterfaceInfo *iface_info; guint n_vfuncs; iface_info = g_irepository_find_by_gtype (NULL, exten_type); g_return_if_fail (iface_info != NULL); g_return_if_fail (g_base_info_get_type (iface_info) == GI_INFO_TYPE_INTERFACE); n_vfuncs = g_interface_info_get_n_vfuncs (iface_info); impls = g_array_new (FALSE, TRUE, sizeof (MethodImpl)); g_array_set_size (impls, n_vfuncs); for (i = 0; i < n_vfuncs; i++) { GIVFuncInfo *vfunc_info; vfunc_info = g_interface_info_get_vfunc (iface_info, i); create_native_closure (exten_type, iface_info, vfunc_info, &g_array_index (impls, MethodImpl, i)); g_base_info_unref (vfunc_info); } g_type_set_qdata (exten_type, method_impl_quark (), impls); g_base_info_unref (iface_info); } for (i = 0; i < impls->len; i++) { MethodImpl *impl = &g_array_index (impls, MethodImpl, i); gpointer *method_ptr; if (impl->closure == NULL) continue; method_ptr = G_STRUCT_MEMBER_P (iface, impl->struct_offset); *method_ptr = impl->closure; g_debug ("Implemented '%s.%s' at %d (%p) with %p", g_type_name (exten_type), impl->method_name, impl->struct_offset, method_ptr, impl->closure); } g_debug ("Implemented interface '%s' for '%s' proxy", g_type_name (exten_type), g_type_name (proxy_type)); }
void gy_value_set_iarg(GValue* pval, GITypeInfo * info, int iarg) { GY_DEBUG("in gy_value_set_iarg\n"); GITypeTag type = g_type_info_get_tag(info); GIBaseInfo * itrf; switch (type) { case GI_TYPE_TAG_BOOLEAN: g_value_set_boolean(pval, ygets_c(iarg)); break; case GI_TYPE_TAG_INT8: g_value_set_schar(pval, ygets_c(iarg)); break; case GI_TYPE_TAG_UINT8: g_value_set_uchar(pval, ygets_c(iarg)); break; case GI_TYPE_TAG_INT16: case GI_TYPE_TAG_INT32: g_value_set_int(pval, ygets_i(iarg)); break; case GI_TYPE_TAG_UINT16: case GI_TYPE_TAG_UINT32: g_value_set_uint(pval, ygets_i(iarg)); break; case GI_TYPE_TAG_INT64: g_value_set_int64(pval, ygets_l(iarg)); break; case GI_TYPE_TAG_UINT64: g_value_set_uint64(pval, ygets_l(iarg)); break; case GI_TYPE_TAG_FLOAT: g_value_set_float(pval, ygets_f(iarg)); break; case GI_TYPE_TAG_DOUBLE: g_value_set_double(pval, ygets_d(iarg)); break; case GI_TYPE_TAG_GTYPE: g_value_set_gtype(pval, ygets_l(iarg)); break; case GI_TYPE_TAG_UTF8: case GI_TYPE_TAG_FILENAME: g_value_set_static_string (pval, ygets_q(iarg)); GY_DEBUG("GValue is string: \"%s\"\n", ygets_q(iarg)); break; /* interface types */ case GI_TYPE_TAG_INTERFACE: itrf = g_type_info_get_interface(info); switch(g_base_info_get_type (itrf)) { case GI_INFO_TYPE_ENUM: g_value_set_enum (pval, ygets_l(iarg)); break; case GI_INFO_TYPE_OBJECT: g_value_set_object(pval, yget_gy_Object(iarg)->object); break; default: y_errorn("Unimplemented GValue interface type %ld", g_base_info_get_type (itrf)); } g_base_info_unref(itrf); break; case GI_TYPE_TAG_VOID: default: y_error("Unimplement property GValue type"); } GY_DEBUG("out gy_iarg2gvalue\n"); }
void gy_value_init(GValue * val, GITypeInfo * info) { GY_DEBUG("in gy_value_init\n"); GITypeTag type = g_type_info_get_tag(info); GIBaseInfo * itrf; GY_DEBUG("Initializing GValue to %s\n", g_type_tag_to_string(type)); switch (type) { /* basic types */ case GI_TYPE_TAG_BOOLEAN: g_value_init(val, G_TYPE_BOOLEAN); break; case GI_TYPE_TAG_INT8: g_value_init(val, G_TYPE_CHAR); break; case GI_TYPE_TAG_UINT8: g_value_init(val, G_TYPE_UCHAR); break; case GI_TYPE_TAG_INT16: case GI_TYPE_TAG_INT32: g_value_init(val, G_TYPE_INT); break; case GI_TYPE_TAG_UINT16: case GI_TYPE_TAG_UINT32: g_value_init(val, G_TYPE_INT); break; case GI_TYPE_TAG_INT64: g_value_init(val, G_TYPE_INT64); break; case GI_TYPE_TAG_UINT64: g_value_init(val, G_TYPE_UINT64); break; case GI_TYPE_TAG_FLOAT: g_value_init(val, G_TYPE_FLOAT); break; case GI_TYPE_TAG_DOUBLE: g_value_init(val, G_TYPE_DOUBLE); break; case GI_TYPE_TAG_GTYPE: g_value_init(val, G_TYPE_GTYPE); break; case GI_TYPE_TAG_UTF8: case GI_TYPE_TAG_FILENAME: g_value_init(val, G_TYPE_STRING); GY_DEBUG("GValue is string\n"); break; /* interface types */ case GI_TYPE_TAG_INTERFACE: itrf = g_type_info_get_interface(info); switch(g_base_info_get_type (itrf)) { case GI_INFO_TYPE_OBJECT: g_value_init(val, G_TYPE_OBJECT); break; case GI_INFO_TYPE_ENUM: g_value_init(val, g_registered_type_info_get_g_type(itrf)); GY_DEBUG("GValue is enum\n"); break; default: y_errorn("Unimplemented GValue interface type %ld", g_base_info_get_type (itrf)); } g_base_info_unref(itrf); break; case GI_TYPE_TAG_VOID: default: y_error("Unimplement property GValue type"); } GY_DEBUG("out gy_value_init\n"); }
void gy_value_push(GValue * pval, GITypeInfo * info, gy_Object* o) { GITypeTag tag = g_type_info_get_tag(info); GY_DEBUG("Pushing %s from GValue\n", g_type_tag_to_string(tag)); switch (tag) { /* basic types */ case GI_TYPE_TAG_VOID:{ GITypeInfo * cellinfo = g_type_info_get_param_type(info, 0); if (cellinfo) { GITypeTag ctag = g_type_info_get_tag(cellinfo); GY_DEBUG("void contains %s\n", g_type_tag_to_string(ctag)); g_base_info_unref(cellinfo); } ypush_nil(); break;} case GI_TYPE_TAG_BOOLEAN: *ypush_c(NULL) = g_value_get_boolean(pval); break; case GI_TYPE_TAG_INT8: *ypush_gint8(NULL) = g_value_get_schar(pval); break; case GI_TYPE_TAG_UINT8: *ypush_guint8(NULL)= g_value_get_uchar(pval); break; case GI_TYPE_TAG_INT16: case GI_TYPE_TAG_INT32: *ypush_gint32(NULL) = g_value_get_int(pval); break; case GI_TYPE_TAG_UINT16: case GI_TYPE_TAG_UINT32: *ypush_guint32(NULL) = g_value_get_uint(pval); break; case GI_TYPE_TAG_INT64: ypush_long(g_value_get_int64(pval)); break; case GI_TYPE_TAG_UINT64: ypush_long(g_value_get_uint64(pval)); break; case GI_TYPE_TAG_FLOAT: *ypush_f(NULL)=g_value_get_float(pval); break; case GI_TYPE_TAG_DOUBLE: ypush_double(g_value_get_double(pval)); break; case GI_TYPE_TAG_GTYPE: ypush_long(g_value_get_gtype(pval)); break; case GI_TYPE_TAG_UTF8: case GI_TYPE_TAG_FILENAME: *ypush_q(NULL) = p_strcpy(g_value_get_string(pval)); break; /* array types */ case GI_TYPE_TAG_ARRAY: y_error("array"); break; /* interface types */ case GI_TYPE_TAG_INTERFACE: { GIBaseInfo * itrf = g_type_info_get_interface (info); switch(g_base_info_get_type (itrf)) { case GI_INFO_TYPE_ENUM: ypush_long(g_value_get_enum(pval)); g_base_info_unref(itrf); break; case GI_INFO_TYPE_OBJECT: { GObject * prop=g_value_get_object(pval); g_object_ref_sink(prop); if (!prop) { g_base_info_unref(itrf); y_error("get property failed"); } GY_DEBUG("pushing result... "); ypush_check(1); gy_Object * out = ypush_gy_Object(); out->info=itrf; out->object=prop; out->repo=o->repo; } break; default: g_base_info_unref(itrf); y_error ("fix me: only properties of type object supported yet"); } break; } default: y_error("Unimplemented"); } }
static JSValueRef ns_get_property(JSContextRef context, JSObjectRef obj, JSStringRef property_name, JSValueRef* exception) { Ns *priv = NULL; char *name = NULL; GIRepository *repo = NULL; GIBaseInfo *info; JSValueRef ret = NULL; gboolean defined; name = gwkjs_jsstring_to_cstring(property_name); /* let Object.prototype resolve these */ if (strcmp(name, "valueOf") == 0 || strcmp(name, "toString") == 0) { goto out; } priv = priv_from_js(obj); gwkjs_debug_jsprop(GWKJS_DEBUG_GNAMESPACE, "Resolve prop '%s' hook obj %p priv %p", name, (void *)obj, priv); if (priv == NULL) { goto out; } // If the module was already included, the default proto system // should return the property, not this method. if (g_hash_table_contains(priv->modules, name)) goto out; repo = g_irepository_get_default(); info = g_irepository_find_by_name(repo, priv->gi_namespace, name); if (info == NULL) { /* No property defined, but no error either, so return TRUE */ goto out; } gwkjs_debug(GWKJS_DEBUG_GNAMESPACE, "Found info type %s for '%s' in namespace '%s'", gwkjs_info_type_name(g_base_info_get_type(info)), g_base_info_get_name(info), g_base_info_get_namespace(info)); g_hash_table_replace(priv->modules, g_strdup(name), NULL); if ((ret = gwkjs_define_info(context, obj, info, &defined))) { g_base_info_unref(info); //XXX: Does it return THIS?! // if (defined) // objp.set(obj); /* we defined the property in this object */ } else { g_hash_table_remove(priv->modules, name); gwkjs_debug(GWKJS_DEBUG_GNAMESPACE, "Failed to define info '%s'", g_base_info_get_name(info)); g_base_info_unref(info); } out: g_free(name); return ret; }
gboolean pygi_g_struct_info_is_simple (GIStructInfo *struct_info) { gboolean is_simple; gsize n_field_infos; gsize i; is_simple = TRUE; n_field_infos = g_struct_info_get_n_fields (struct_info); for (i = 0; i < n_field_infos && is_simple; i++) { GIFieldInfo *field_info; GITypeInfo *field_type_info; GITypeTag field_type_tag; field_info = g_struct_info_get_field (struct_info, i); field_type_info = g_field_info_get_type (field_info); field_type_tag = g_type_info_get_tag (field_type_info); switch (field_type_tag) { case GI_TYPE_TAG_BOOLEAN: case GI_TYPE_TAG_INT8: case GI_TYPE_TAG_UINT8: case GI_TYPE_TAG_INT16: case GI_TYPE_TAG_UINT16: case GI_TYPE_TAG_INT32: case GI_TYPE_TAG_UINT32: case GI_TYPE_TAG_INT64: case GI_TYPE_TAG_UINT64: case GI_TYPE_TAG_FLOAT: case GI_TYPE_TAG_DOUBLE: case GI_TYPE_TAG_UNICHAR: if (g_type_info_is_pointer (field_type_info)) { is_simple = FALSE; } break; case GI_TYPE_TAG_VOID: case GI_TYPE_TAG_GTYPE: case GI_TYPE_TAG_ERROR: case GI_TYPE_TAG_UTF8: case GI_TYPE_TAG_FILENAME: case GI_TYPE_TAG_ARRAY: case GI_TYPE_TAG_GLIST: case GI_TYPE_TAG_GSLIST: case GI_TYPE_TAG_GHASH: is_simple = FALSE; break; case GI_TYPE_TAG_INTERFACE: { GIBaseInfo *info; GIInfoType info_type; info = g_type_info_get_interface (field_type_info); info_type = g_base_info_get_type (info); switch (info_type) { case GI_INFO_TYPE_STRUCT: if (g_type_info_is_pointer (field_type_info)) { is_simple = FALSE; } else { is_simple = pygi_g_struct_info_is_simple ( (GIStructInfo *) info); } break; case GI_INFO_TYPE_UNION: /* TODO */ is_simple = FALSE; break; case GI_INFO_TYPE_ENUM: case GI_INFO_TYPE_FLAGS: if (g_type_info_is_pointer (field_type_info)) { is_simple = FALSE; } break; case GI_INFO_TYPE_BOXED: case GI_INFO_TYPE_OBJECT: case GI_INFO_TYPE_CALLBACK: case GI_INFO_TYPE_INTERFACE: is_simple = FALSE; break; case GI_INFO_TYPE_VFUNC: case GI_INFO_TYPE_INVALID: case GI_INFO_TYPE_FUNCTION: case GI_INFO_TYPE_CONSTANT: case GI_INFO_TYPE_VALUE: case GI_INFO_TYPE_SIGNAL: case GI_INFO_TYPE_PROPERTY: case GI_INFO_TYPE_FIELD: case GI_INFO_TYPE_ARG: case GI_INFO_TYPE_TYPE: case GI_INFO_TYPE_UNRESOLVED: default: g_assert_not_reached(); break; } g_base_info_unref (info); break; } } g_base_info_unref ( (GIBaseInfo *) field_type_info); g_base_info_unref ( (GIBaseInfo *) field_info); } return is_simple; }
static void argument_from_raw_data_interface(GICallableInfo *callable_info, void *raw_arg, GIArgument *argument, GITypeInfo *type_info) { GIBaseInfo *interface_info; GIInfoType interface_type; interface_info = g_type_info_get_interface(type_info); interface_type = g_base_info_get_type(interface_info); switch (interface_type) { case GI_INFO_TYPE_INVALID: case GI_INFO_TYPE_FUNCTION: case GI_INFO_TYPE_CALLBACK: rb_raise(rb_eNotImpError, "TODO: %s::%s: raw data -> GIArgument(interface)[%s]: <%s>", g_base_info_get_namespace(callable_info), g_base_info_get_name(callable_info), g_info_type_to_string(interface_type), g_base_info_get_name(interface_info)); break; case GI_INFO_TYPE_STRUCT: argument->v_pointer = *((gpointer *)(raw_arg)); break; case GI_INFO_TYPE_BOXED: case GI_INFO_TYPE_ENUM: rb_raise(rb_eNotImpError, "TODO: %s::%s: raw data -> GIArgument(interface)[%s]: <%s>", g_base_info_get_namespace(callable_info), g_base_info_get_name(callable_info), g_info_type_to_string(interface_type), g_base_info_get_name(interface_info)); break; case GI_INFO_TYPE_FLAGS: argument->v_int32= *((gint32 *)(raw_arg)); break; case GI_INFO_TYPE_OBJECT: case GI_INFO_TYPE_INTERFACE: argument->v_pointer = *((gpointer *)(raw_arg)); break; case GI_INFO_TYPE_CONSTANT: rb_raise(rb_eNotImpError, "TODO: %s::%s: raw data -> GIArgument(interface)[%s]: <%s>", g_base_info_get_namespace(callable_info), g_base_info_get_name(callable_info), g_info_type_to_string(interface_type), g_base_info_get_name(interface_info)); break; case GI_INFO_TYPE_INVALID_0: g_assert_not_reached(); break; case GI_INFO_TYPE_UNION: case GI_INFO_TYPE_VALUE: case GI_INFO_TYPE_SIGNAL: case GI_INFO_TYPE_VFUNC: case GI_INFO_TYPE_PROPERTY: case GI_INFO_TYPE_FIELD: case GI_INFO_TYPE_ARG: case GI_INFO_TYPE_TYPE: case GI_INFO_TYPE_UNRESOLVED: default: rb_raise(rb_eNotImpError, "TODO: %s::%s: raw data -> GIArgument(interface)[%s]: <%s>", g_base_info_get_namespace(callable_info), g_base_info_get_name(callable_info), g_info_type_to_string(interface_type), g_base_info_get_name(interface_info)); break; } g_base_info_unref(interface_info); }
static void out_argument_to_raw_data_interface(GICallableInfo *callable_info, GIArgument *argument, gpointer result, GITypeInfo *type_info, G_GNUC_UNUSED GITransfer transfer /* TODO */, gboolean is_return_value) { GIBaseInfo *interface_info; GIInfoType interface_type; GIFFIReturnValue *ffi_return_value = result; interface_info = g_type_info_get_interface(type_info); interface_type = g_base_info_get_type(interface_info); switch (interface_type) { case GI_INFO_TYPE_INVALID: case GI_INFO_TYPE_FUNCTION: case GI_INFO_TYPE_CALLBACK: case GI_INFO_TYPE_STRUCT: case GI_INFO_TYPE_BOXED: rb_raise(rb_eNotImpError, "TODO: %s::%s: out raw data(interface)[%s]: <%s>", g_base_info_get_namespace(callable_info), g_base_info_get_name(callable_info), g_info_type_to_string(interface_type), g_base_info_get_name(interface_info)); break; case GI_INFO_TYPE_ENUM: if (is_return_value) { ffi_return_value->v_ulong = argument->v_int; } else { *((gint *)result) = argument->v_int; } break; case GI_INFO_TYPE_FLAGS: case GI_INFO_TYPE_OBJECT: case GI_INFO_TYPE_INTERFACE: case GI_INFO_TYPE_CONSTANT: rb_raise(rb_eNotImpError, "TODO: %s::%s: out raw data(interface)[%s]: <%s>", g_base_info_get_namespace(callable_info), g_base_info_get_name(callable_info), g_info_type_to_string(interface_type), g_base_info_get_name(interface_info)); break; case GI_INFO_TYPE_INVALID_0: g_assert_not_reached(); break; case GI_INFO_TYPE_UNION: case GI_INFO_TYPE_VALUE: case GI_INFO_TYPE_SIGNAL: case GI_INFO_TYPE_VFUNC: case GI_INFO_TYPE_PROPERTY: case GI_INFO_TYPE_FIELD: case GI_INFO_TYPE_ARG: case GI_INFO_TYPE_TYPE: case GI_INFO_TYPE_UNRESOLVED: default: rb_raise(rb_eNotImpError, "TODO: %s::%s: out raw data(interface)[%s]: <%s>", g_base_info_get_namespace(callable_info), g_base_info_get_name(callable_info), g_info_type_to_string(interface_type), g_base_info_get_name(interface_info)); break; } g_base_info_unref(interface_info); }
gsize _pygi_g_type_info_size (GITypeInfo *type_info) { gsize size = 0; GITypeTag type_tag; type_tag = g_type_info_get_tag (type_info); switch (type_tag) { case GI_TYPE_TAG_BOOLEAN: case GI_TYPE_TAG_INT8: case GI_TYPE_TAG_UINT8: case GI_TYPE_TAG_INT16: case GI_TYPE_TAG_UINT16: case GI_TYPE_TAG_INT32: case GI_TYPE_TAG_UINT32: case GI_TYPE_TAG_INT64: case GI_TYPE_TAG_UINT64: case GI_TYPE_TAG_FLOAT: case GI_TYPE_TAG_DOUBLE: case GI_TYPE_TAG_GTYPE: case GI_TYPE_TAG_UNICHAR: size = _pygi_g_type_tag_size (type_tag); g_assert (size > 0); break; case GI_TYPE_TAG_INTERFACE: { GIBaseInfo *info; GIInfoType info_type; info = g_type_info_get_interface (type_info); info_type = g_base_info_get_type (info); switch (info_type) { case GI_INFO_TYPE_STRUCT: if (g_type_info_is_pointer (type_info)) { size = sizeof (gpointer); } else { size = g_struct_info_get_size ( (GIStructInfo *) info); } break; case GI_INFO_TYPE_UNION: if (g_type_info_is_pointer (type_info)) { size = sizeof (gpointer); } else { size = g_union_info_get_size ( (GIUnionInfo *) info); } break; case GI_INFO_TYPE_ENUM: case GI_INFO_TYPE_FLAGS: if (g_type_info_is_pointer (type_info)) { size = sizeof (gpointer); } else { GITypeTag type_tag; type_tag = g_enum_info_get_storage_type ( (GIEnumInfo *) info); size = _pygi_g_type_tag_size (type_tag); } break; case GI_INFO_TYPE_BOXED: case GI_INFO_TYPE_OBJECT: case GI_INFO_TYPE_INTERFACE: case GI_INFO_TYPE_CALLBACK: size = sizeof (gpointer); break; case GI_INFO_TYPE_VFUNC: case GI_INFO_TYPE_INVALID: case GI_INFO_TYPE_FUNCTION: case GI_INFO_TYPE_CONSTANT: case GI_INFO_TYPE_VALUE: case GI_INFO_TYPE_SIGNAL: case GI_INFO_TYPE_PROPERTY: case GI_INFO_TYPE_FIELD: case GI_INFO_TYPE_ARG: case GI_INFO_TYPE_TYPE: case GI_INFO_TYPE_UNRESOLVED: default: g_assert_not_reached(); break; } g_base_info_unref (info); break; } case GI_TYPE_TAG_ARRAY: case GI_TYPE_TAG_VOID: case GI_TYPE_TAG_UTF8: case GI_TYPE_TAG_FILENAME: case GI_TYPE_TAG_GLIST: case GI_TYPE_TAG_GSLIST: case GI_TYPE_TAG_GHASH: case GI_TYPE_TAG_ERROR: size = sizeof (gpointer); break; } return size; }