How to resolve these 'TODO' GTK bindings

Linux specific questions.
Post Reply
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

How to resolve these 'TODO' GTK bindings

Post by Munair »

As I am just learning how to translate c headers to include files, I wonder how the following C code should be translated:

Code: Select all

GTK_SOURCE_AVAILABLE_IN_ALL
GType		 gtk_source_view_get_type		(void) G_GNUC_CONST;

GTK_SOURCE_AVAILABLE_IN_ALL
GtkWidget	*gtk_source_view_new			(void);

GTK_SOURCE_AVAILABLE_IN_ALL
GtkWidget 	*gtk_source_view_new_with_buffer	(GtkSourceBuffer *buffer);

GTK_SOURCE_AVAILABLE_IN_ALL
void		 gtk_source_view_set_show_line_numbers 	(GtkSourceView   *view,
							 gboolean         show);

GTK_SOURCE_AVAILABLE_IN_ALL
gboolean 	 gtk_source_view_get_show_line_numbers 	(GtkSourceView   *view);
I cannot find it in the FBWiki and I already tried available translator software, but these lines are not recognized and translated as 'TODO":

Code: Select all

'' TODO: GTK_SOURCE_AVAILABLE_IN_ALL GType gtk_source_view_get_type (void) G_GNUC_CONST;
'' TODO: GTK_SOURCE_AVAILABLE_IN_ALL GtkWidget *gtk_source_view_new (void);
The translation is for up-to-date GtkSourceView bindings (version 3.22.2) which are not in the standard gtk.bi.

Help would be very much appreciated.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: How to resolve these 'TODO' GTK bindings

Post by Munair »

In the meantime I figured out a few things and resolved most TODO'S. The one left is:

'' TODO: GType gtk_source_view_get_type (void) G_GNUC_CONST;

I may figure it out through trial and error, but if anyone knows... It may have to do with recognizing G_GNUC_CONST or lack thereof.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: How to resolve these 'TODO' GTK bindings

Post by Munair »

I was able to find this (for anyone interested) regarding the G_GNUC_CONST attribute
Your _get_type() function is not G_GNUC_CONST

It’s not uncommon in GNOME to annotate the _get_type() function declaration of a GObject with G_GNUC_CONST. Like so:
GType ephy_download_get_type (void) G_GNUC_CONST;

What does this do? It expands to __attribute__((__const__)) if the compiler is GCC (or a compiler that pretends to be GCC, like Clang); otherwise, it expands to nothing. What does that attribute do? I could point you at the GCC documentation, but GLib’s documentation is simpler: “Declaring a function as const enables better optimization of calls to the function. A const function doesn’t examine any values except its parameters, and has no effects except its return value.” That’s really all there is to it. What’s important to keep in mind is that if your function doesn’t meet the preconditions for the attribute, the compiler is free to make optimizations that break your code.
Should FBFROG be updated or simply ignore this attribute? It currently marks the line as TODO.
Last edited by Munair on Nov 12, 2017 16:06, edited 1 time in total.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: How to resolve these 'TODO' GTK bindings

Post by caseih »

That's a simple function declaration. gtk_source_view_get_type() takes no parameters and returns a value of type GType. The G_GNUC_CONST is a gcc-specific macro that tells the compiler the function has no side effects and refers to no global variables so the compiler can optimize it in certain ways. From FB's point of view I think you can probably just ignore that flag entirely. See https://developer.gnome.org/glib/stable ... CONST:CAPS

The FB declaration would be something along the lines of:

declare function gtk_source_view_get_type cdecl alias "gtk_source_view_get_type" () as GType

I'm guessing FBFrog could be updated to ignore this attribute entirely.
Last edited by caseih on Nov 12, 2017 16:11, edited 1 time in total.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: How to resolve these 'TODO' GTK bindings

Post by Munair »

Thanks caseih for your explanation.

The translation FBFROG seems to make of these declarations:

GtkWidget *gtk_source_view_new (void);
declare function gtk_source_view_new() as GtkWidget ptr

There's no cdecl alias so I take it that's not necessary. Other than that I got the same translation:

''TODO: GType gtk_source_view_get_type (void) G_GNUC_CONST;
declare function gtk_source_view_get_type() as GType
Last edited by Munair on Nov 12, 2017 16:14, edited 1 time in total.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: How to resolve these 'TODO' GTK bindings

Post by caseih »

I'm guessing the declarations are probably surrounded by an extern C block, which makes the cdecl stuff redundant.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: How to resolve these 'TODO' GTK bindings

Post by Munair »

caseih wrote:I'm guessing the declarations are probably surrounded by an extern C block, which makes the cdecl stuff redundant.
CORRECT
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: How to resolve these 'TODO' GTK bindings

Post by dkl »

Normally G_GNUC_CONST should be #defined somewhere (looks like it's from glib headers), but fbfrog didn't see it. If you provide the glib headers too, then it should be solved out automatically.

For example:
fbfrog \
-incdir gtk+-x.xx.x \
-incdir glib-x.xx.x \
-incdir glib-x.xx.x/glib \
-incdir glib-x.xx.x/gmodule \
-incdir ... \
-include gtk/gtk.h
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: How to resolve these 'TODO' GTK bindings

Post by Munair »

OK, I'll have a look.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: How to resolve these 'TODO' GTK bindings

Post by Munair »

I have another TODO. Is this a macro. Not sure how to translate it:

'' TODO: #define GTK_SOURCE_DEPRECATED_IN_3_0_FOR(f) G_DEPRECATED_FOR(f) _GTK_SOURCE_EXTERN

In fact, from this piece of code, only one line is translated:

C:

Code: Select all

#ifndef __GTK_DOC_IGNORE__
	#if GTK_SOURCE_VERSION_MIN_REQUIRED >= GTK_SOURCE_VERSION_3_0
		#define GTK_SOURCE_DEPRECATED_IN_3_0 G_DEPRECATED _GTK_SOURCE_EXTERN
		#define GTK_SOURCE_DEPRECATED_IN_3_0_FOR(f) G_DEPRECATED_FOR(f) _GTK_SOURCE_EXTERN
	#else
		#define GTK_SOURCE_DEPRECATED_IN_3_0 _GTK_SOURCE_EXTERN
		#define GTK_SOURCE_DEPRECATED_IN_3_0_FOR(f) _GTK_SOURCE_EXTERN
	#endif
#endif
FB:

Code: Select all

#define GTK_SOURCE_DEPRECATED_IN_3_0 G_DEPRECATED _GTK_SOURCE_EXTERN
Another problem seems to be this construction:

Code: Select all

#ifndef GTK_SOURCE_VERSION_MAX_ALLOWED
#if GTK_SOURCE_VERSION_MIN_REQUIRED > GTK_SOURCE_VERSION_PREV_STABLE
#define GTK_SOURCE_VERSION_MAX_ALLOWED  GTK_SOURCE_VERSION_MIN_REQUIRED
#else
#define GTK_SOURCE_VERSION_MAX_ALLOWED GTK_SOURCE_VERSION_CUR_STABLE
#endif
#endif
FBFROG simply translates:

Code: Select all

#define GTK_SOURCE_VERSION_MAX_ALLOWED GTK_SOURCE_VERSION_CUR_STABLE
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: How to resolve these 'TODO' GTK bindings

Post by dkl »

It looks like they are internal macros that aren't needed in the FB binding, so they can probably be dropped/ignored. For fbfrog: -removedefine GTK_SOURCE_DEPRECATED_*

Producing #ifs with fbfrog is possible but difficult, see also the example for freeglut's FREEGLUT_STATIC or the readme.
Post Reply