Forum > GTK

GTK2 ABI seems broken, at least on Windows

(1/4) > >>

Arioch:
First of all, there seems to be  no more GTK2 for Win32, only for Win64 - https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer

However, when you run the GTK2 hello-world the program fails with "there is no gtk_file_selection_get_selections entrypoint in DLL libgtk-win32-2.0-0.dll"

The introspection confirms it: https://gitlab.com/freepascal.org/lazarus/lazarus/uploads/264b57972ba6bbe1b241dd1ba01ff3ca/2022-09-08_13_42_50-Lister__fileinfo__-__C__Program_Files_GTK2-Runtime_Win64_bin_libgtk-win32-2.0-0..png

(from https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39887 )

https://developer-old.gnome.org/gtk2/stable/GtkFileSelection.html

This doc (official or no more?) has a lot of lines line

--- Code: C  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// gtk_file_selection_set_filename#define gtk_file_selection_set_filename gtk_file_selection_set_filename_utf8
I had a short Discord chat with MSYS2 devs


--- Quote ---Biswa96 — Сегодня, в 6:08
There are some aliasing between gtk_file_selection_get_selections and gtk_file_selection_get_selections_utf8. See gtkalias.h and gtkaliasdef.c files in gtk2 source code.

Arioch — Сегодня, в 6:09
Ooops, so i would need sources... Are them there in git? So i won't need the whole pack?
Also, there should be some documentation, why what tag done and what did it mean. ABI breaking should have meaning attached

Biswa96 — Сегодня, в 6:11
You do not need source code for normal use cases. There is no ABI breakage. The symbol is just aliased like that. Docs also says

#define gtk_file_selection_get_selections gtk_file_selection_get_selections_utf8
"gtk_file_selection_get_selections is deprecated and should not be used in newly-written code."

Arioch — Сегодня, в 6:13
Well, there was ABI exported symbol, then it ceased to be. It was breaking. Okay, that is the start... Those two source files are in the msys2 repo?..

Biswa96 — Сегодня, в 6:14
Please read the documentation carefully. The DLL exports gtk_file_selection_get_selections_utf8 then it gets aliased in preprocessor to gtk_file_selection_get_selections for backward compatibility.

Arioch — Сегодня, в 6:15
Ahem, i'd like to, but gtk.org only hosts docs for gtk 3 and 4

Biswa96 — Сегодня, в 6:15
I read the docs from your provided links in that GitHub issue.

Arioch — Сегодня, в 6:16
I think the app in question was compiled before that aliasing was made.
Maybe i even have some 10 years ago gimpwin distros to see.

Those were not official docs, or i did not identified them like that.
Okay, thanks, at least some pointers. I am not at the desktop anyway, so would remain for later.

Biswa96 — Сегодня, в 6:17
Then the app need a fix.

Arioch — Сегодня, в 6:18
Perhaps. But i needed to make sure with some specific reasoning, rather than jumping out saying "your app is at fault, i think so"
--- End quote ---

There seems to be no aliasing in LCL, example

both fpcsrc\packages\gtk1\src\gtk\gtkfilesel.pp and fpcsrc\packages\gtk2\src\gtk+\gtk\gtkfilesel.inc

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function  gtk_file_selection_get_filename (filesel:PGtkFileSelection):Pgchar;cdecl;external gtkdll name 'gtk_file_selection_get_filename'; 
It probably was added later than GTK 2.0.0 but it seems no one knows for sure when and why,

If such code still runs on Linux - then perhaps there is some added backward compatibility layer, that was nremoved form Windows. Or at least from MSYS2, who make compiled GTK2 runtime installers now.

AmatCoder:

--- Quote ---It probably was added later than GTK 2.0.0 but it seems no one knows for sure when and why
--- End quote ---

*_utf8 functions was added in GTK 2.6, reserving old names for DLL ABI backward compatibility.

But they were removed for 64-bit versions of Windows in GTK 2.14:

--- Code: C  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---/* Binary compatibility version. Not for newly compiled code. Also not needed for * 64-bit versions as there should be no old deployed binaries that would use * the old versions. */
Note that GTK 2.6 version is from the year 2005 and 2.14 version is from the year 2008.
Support for 64-bit Windows was not available from MinGW until 2011.

When GTK got support it even had a disclaimer:

--- Quote ---Download for Windows (64-bit)

Note that these 64-bit packages are experimental. Binary compatibility between versions is not guaranteed.
--- End quote ---

Arioch:
Great you found the specific point of time.

So, can we safely assume now that ALL of those funciton in GTK1/GTK2 LCL sources today should be moved to *_utf8 linknames and there would be no practically machines with GTK so old the *_utf8 functions are missed ?

Also i fail to grasp mere documentation about G Encoding". Can we safely assume GTK funcitons return UTF-8 encoded filenames? Or is it dependent upon some settings, like Current Thread Locale in windows, EXPORT LOCALE in Linux, etc? The rename suggests they decided to drop it and to make their API UTF8-only. But their docs still claim conversion of filenames to UTF when receiving from GTK and converting back from UTF8 when sending to GTK. It confuses me greately..

marcov:
Is GTK2 (let alone GTK1) still supported as LCL backend for Windows  ?

AmatCoder:

--- Quote ---So, can we safely assume now that ALL of those funciton in GTK1/GTK2 LCL sources today should be moved to *_utf8 linknames and there would be no practically machines with GTK so old the *_utf8 functions are missed ?

--- End quote ---

Yes. All Linux distributions has 2.24 version since ten years ago at least. And version 2.6 was introduced eighteen years ago.
Nobody uses such old distributions.

Even more: The minimum Gtk 2 version supported for Lazarus is Gtk 2.8: https://wiki.freepascal.org/GTK2_Interface#Introduction


--- Quote ---Can we safely assume GTK funcitons return UTF-8 encoded filenames?

--- End quote ---

On Windows, yes.
On Linux, no:

--- Quote ---Historically, Linux has not had a defined encoding for file names: a file name is valid as long as it does not have path separators in it (“/”). However, displaying file names may require conversion: from the character set in which they were created, to the character set in which the application operates.

--- End quote ---

Example:
An application creates a file named "Tést". The application which created it uses ISO-8859-1 for its encoding.
But GTK uses UTF-8 for its strings. On Linux, if you get a file name from the file system - for example with readdir() - and you want to display the file name to the user with GTK, you will need to convert it into UTF-8.

Navigation

[0] Message Index

[#] Next page

Go to full version