Re: GObject Introspection Enum details
Hi Aleksey, Perhaps a solution is to prefix the name returned by g_base_info_get_name with the namespace's C prefix returned by g_irepository_get_c_prefix I think this will reconstruct the C name because (somebody correct me if I'm wrong) the names in the GIR metadata are derived by stripping the prefix from the C names in the first place. (For functions, you can get the name with g_function_info_get_symbol.) On a different note, I was using the GIRepository library to generate binding code and found that it wasn't possible to generate one binding library for all platforms because information about platform-dependent C types, e.g. glong, was not available. Calling g_base_info_get_name on a TypeInfo gave ** ERROR:girepository/gibaseinfo.c:366:g_base_info_get_name: code should not be reached instead of the type name present in the GIR file, e.g. "glong". The information provided by the GITypeTag enum type has integer sizes resolved for the platform in use. So seeing e.g. INT64 on a 64 bit platform doesn't tell you whether that was gint64 or glong in C. That was an issue for me, so I thought I'd mention it. 17/11/13 17:42, Aleksey wrote: Thanks Jasper I've somehow overlooked that GIEnumInfo is inherited GIRegisteredTypeInfo, not directly from GIBaseInfo. Unfortunately, g_registered_type_info_get_type_name() returns NULL. I've also tried g_registered_type_info_get_g_type & g_type_name: GType type = g_registered_type_info_get_g_type(info); const gchar * name = g_type_name(type); but it returns "void". > mind asking why you want to know? I am trying to automate binding generation for Swi-Prolog (http://www.swi-prolog.org/). Currently I am working on datatype conversion, for example, following (generated) function takes Prolog data structure (term) and converts it to C enum-integer: BookmarkFileError convert_term_to_BookmarkFileError(term_t var) { const char * value = convert_term_to_cstring(var); if (strcmp(value, "invalid_uri") == 0) { return invalid_uri; } else if (strcmp(value, "invalid_value") == 0) { return invalid_value; } else if (strcmp(value, "app_not_registered") == 0) { return app_not_registered; } else if (strcmp(value, "uri_not_found") == 0) { return uri_not_found; } else if (strcmp(value, "read") == 0) { return read; } else if (strcmp(value, "unknown_encoding") == 0) { return unknown_encoding; } else if (strcmp(value, "write") == 0) { return write; } else if (strcmp(value, "file_not_found") == 0) { return file_not_found; } printf("Error in convert_term_to_BookmarkFileError while converting value\n"); return (BookmarkFileError)0; } But I need to get exact names for enum (and enum values, but this is another problem I hadn't investigated yet). On Sunday 17 November 2013 11:51:24 Jasper St. Pierre wrote: > You can try g_registered_type_info_get_type_name(), but mind asking why you > want to know? > ___ gtk-devel-list mailing list gtk-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-devel-list ___ gtk-devel-list mailing list gtk-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Re: GObject Introspection Enum details
Thanks Jasper I've somehow overlooked that GIEnumInfo is inherited GIRegisteredTypeInfo, not directly from GIBaseInfo. Unfortunately, g_registered_type_info_get_type_name() returns NULL. I've also tried g_registered_type_info_get_g_type & g_type_name: GType type = g_registered_type_info_get_g_type(info); const gchar * name = g_type_name(type); but it returns "void". > mind asking why you want to know? I am trying to automate binding generation for Swi-Prolog (http://www.swi-prolog.org/). Currently I am working on datatype conversion, for example, following (generated) function takes Prolog data structure (term) and converts it to C enum-integer: BookmarkFileError convert_term_to_BookmarkFileError(term_t var) { const char * value = convert_term_to_cstring(var); if (strcmp(value, "invalid_uri") == 0) { return invalid_uri; } else if (strcmp(value, "invalid_value") == 0) { return invalid_value; } else if (strcmp(value, "app_not_registered") == 0) { return app_not_registered; } else if (strcmp(value, "uri_not_found") == 0) { return uri_not_found; } else if (strcmp(value, "read") == 0) { return read; } else if (strcmp(value, "unknown_encoding") == 0) { return unknown_encoding; } else if (strcmp(value, "write") == 0) { return write; } else if (strcmp(value, "file_not_found") == 0) { return file_not_found; } printf("Error in convert_term_to_BookmarkFileError while converting value\n"); return (BookmarkFileError)0; } But I need to get exact names for enum (and enum values, but this is another problem I hadn't investigated yet). On Sunday 17 November 2013 11:51:24 Jasper St. Pierre wrote: > You can try g_registered_type_info_get_type_name(), but mind asking why you > want to know? > ___ gtk-devel-list mailing list gtk-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Re: GObject Introspection Enum details
You can try g_registered_type_info_get_type_name(), but mind asking why you want to know? On Sun, Nov 17, 2013 at 11:33 AM, Aleksey wrote: > Hi guys > > > > I am trying to use GIRepository (version 1.38) to retrieve Enumeration > details and I'm wondering how to retrieve C-name of Enum. For example, I > have GIEnumInfo instance for GBookmarkFileError ( > https://developer.gnome.org/glib/2.38/glib-Bookmark-file-parser.html#GBookmarkFileError > ). > > Calling g_base_info_get_name gives me BookmarkFileError, not > GBookmarkFileError. > > After looking at *.gir file contents for GLib, I've found that required > value is stored in c:type attribute: > > > > > c:type="GBookmarkFileError" > > glib:error-quark="g_bookmark_file_error_quark"> > > ... > > > > > > so I expected to be able to get the name using g_base_info_get_attribute, > however, checking available attributes with > g_base_info_iterate_attributesproduced no results. Code used to check > attributes (no attribute > names/values are printed): > > > > // print available attributes, taken from GIRepository manual page > > void print_attributes(GIBaseInfo *info) > > { > > GIAttributeIter iter = { 0, }; > > char * name; > > char * value; > > while (g_base_info_iterate_attributes (info, &iter, &name, &value)) { > > g_print ("attribute name: %s value: %s", name, value); > > } > > } > > > > int main(int argc, char ** argv) > > { > > GIRepository *repo = g_irepository_get_default(); > > g_irepository_require(repo, "GLib", NULL, 0, NULL); > > gint count = g_irepository_get_n_infos(repo, "GLib"); > > // find first enum > > int i; > > GIBaseInfo * info = NULL; > > for (i = 0; i < count; i++) { > > info = g_irepository_get_info(repo, "GLib", i); > > GIInfoType type = g_base_info_get_type(info); > > if (type == GI_INFO_TYPE_ENUM) break; > > } > > > > const gchar * name = g_base_info_get_name(info); > > printf("Enum: %s\n", name); > > print_attributes(info); > > > > return 0; > > } > > Could you please advise on how is it possible to get C-type name for enum > (e.g. GBookmarkFileError). > > ___ > gtk-devel-list mailing list > gtk-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-devel-list > > -- Jasper ___ gtk-devel-list mailing list gtk-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-devel-list
GObject Introspection Enum details
Hi guys I am trying to use GIRepository (version 1.38) to retrieve Enumeration details and I'm wondering how to retrieve C-name of Enum. For example, I have GIEnumInfo instance for GBookmarkFileError (https://developer.gnome.org/glib/2.38/glib-Bookmark-file-parser.html#GBookmarkFileError). Calling /g_base_info_get_name/ gives me BookmarkFileError, not GBookmarkFileError. After looking at *.gir file contents for GLib, I've found that required value is stored in c:type attribute: ... so I expected to be able to get the name using /g_base_info_get_attribute/, however, checking available attributes with /g_base_info_iterate_attributes/ produced no results. Code used to check attributes (no attribute names/values are printed): // print available attributes, taken from GIRepository manual page void print_attributes(GIBaseInfo *info) { GIAttributeIter iter = { 0, }; char * name; char * value; *while* (g_base_info_iterate_attributes (info, &iter, &name, &value)) { g_print ("attribute name: %s value: %s", name, value); } } int main(int argc, char ** argv) { GIRepository *repo = g_irepository_get_default(); g_irepository_require(repo, "GLib", NULL, 0, NULL); gint count = g_irepository_get_n_infos(repo, "GLib"); // find first enum int i; GIBaseInfo * info = NULL; *for* (i = 0; i < count; i++) { info = g_irepository_get_info(repo, "GLib", i); GIInfoType type = g_base_info_get_type(info); *if* (type == GI_INFO_TYPE_ENUM) *break*; } const gchar * name = g_base_info_get_name(info); printf("Enum: %s\n", name); print_attributes(info); *return* 0; } Could you please advise on how is it possible to get C-type name for enum (e.g. GBookmarkFileError). ___ gtk-devel-list mailing list gtk-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-devel-list