How to hack my cfwrapper to generate Fortran interfaces for C prototypes

I have written a How-to for people wanting to try to use (to hack) the gtk-fortran Python cfwrapper with other C libraries:

As it was polished for 12 years, you may obtain very good results with “clean” C header files. The problems you may encounter are also detailed.

No warranty, it’s a hack! :hammer_and_wrench:

10 Likes

“Fortranaute” :grin:

1 Like

And sorry, there is no “e” at the end of “astronaut” in English…
So Fortranauts we are :rocket:, in cyberspace and beyond…

1 Like

I have added to the cfwrapper -l (--library) and -m (--module) options to respectively add the directories containing the header files and the corresponding Fortran modules names:

$ ./cfwrapper.py -l /usr/include/libsoup-3.0 /usr/include/json-glib-1.0 -m libsoup json
 Pass 1: looking for enumerators, funptr and derived types...
 Pass 2: looking for C functions... 
/usr/include/libsoup-3.0         =>  libsoup-auto.f90        125042 bytes
/usr/include/json-glib-1.0       =>  json-auto.f90            66359 bytes

Extracting GDK events for gtk-0-fortran
Failed to open /usr/include/gtk-0.0/gdk/gdktypes.h:No such file or directory

=== Statistics (ready to paste in the Status wiki page) ===

## gtk-fortran 0.0.0, GTK not_GTK, GLib 2.74.3, Ubuntu 22.10 x86_64, Python 3.10.7
vmagnin, Sun, 09 Apr 2023 09:50:07 +0000
* nb_files scanned =            55
* nb_generated_interfaces =    590
* nb_deprecated_functions =      5
* nb_type_errors =              50
* nb_errors (others) =          38
* nb_lines treated =          1884
* nb_variadic functions =        6
* nb_enumerators =              27
* nb_win32_utf8 =                0
* Number of types =             65
* Number of funptr types =      13
* Computing time: 0.34 s
* SHA1:  60dfe48b11ea511bb3b85197181994117f71d5e0
 >>>>>> SHA 1 HAS BEEN MODIFIED ! It was  10067b0d918677d31b4c9bc9c70a7a3ca27bc29a  <<<<<< 


 Used types: ['c_ptr', 'c_int', 'c_char', 'c_funptr', '?', 'c_size_t', 'c_long', 'c_int64_t', 'c_double']

You can also use the new -s (--suffix) option to add a suffix to the functions names.

The tutorial has been updated accordingly.

I am thinking about the license that could apply to a module with interfaces automatically generated by the cfwrapper (except the GLib/GTK libraries, gtk-fortran being under GPL3).

The modules generated for other libraries could be automatically put under the MIT license:

It implies acknowledgements, warranty disclaimer, and no limitations on use.

What’s your opinions?

I have just created that repository:

For the moment, we have only two libraries:

  • src/libsoup3/ (HTTP client/server library): generated from libsoup3-devel 3.4.2 in Fedora 38. See the Soup 3.0 documentation.

  • src/libadwaita/ (Building blocks for modern GNOME applications): generated from libadwaita-devel 1.3.3 in Fedora 38. See the Adwaita documentation.

More explanations are in the README.md file for people who would like to experiment and play with them.

1 Like