• ANNOUNCE: CFFI 1.0b5

    From apn@21:1/5 to All on Wed Apr 6 08:45:28 2022
    The cffi package permits calling C functions in shared libraries from
    within Tcl scripts via either the libffi or dyncall open source libraries.

    Documentation is at https://cffi.magicsplat.com. Some additional
    tutorial material is available at
    https://www.magicsplat.com/blog/tags/cffi/. The https://github.com/apnadkarni/tcl-cffi/tree/main/examples directory
    contains some sample bindings.

    Source distributions and binary packages Windows can be downloaded from https://sourceforge.net/projects/magicsplat/files/cffi.

    The source repository is at https://github.com/apnadkarni/tcl-cffi.


    ## Changes in 1.0b5

    - Added a *Cookbook* section to documentation to help in mapping C
    declarations to CFFI.

    - Added the `retval` annotation to return a output parameter as the
    command result.

    - Added `getnativefields` method to retrieve multiple field values from
    a native struct.

    - Added `new` method for struct instances to allocate and initialize a
    native struct in memory.

    - Added implicit and explicit casting for pointers.

    - The `enum value` and `enum name` commands now accept defaults.

    - **Incompatibility** The `get` and `set` methods for struct instances
    renamed to `getnative` and `setnative`.

    - **Incompatibility** The `callback` and `callback_free` commands are
    now part of a `callback` command ensemble.

    - **Incompatibility** The last element of a bitmask enumeration list
    returns original integer value.

    - Miscellaneous bug fixes.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ashok@21:1/5 to Arjen Markus on Thu Apr 7 12:33:15 2022
    On 4/7/2022 12:15 PM, Arjen Markus wrote:
    As I mentioned in the chat yesterday, this looks really interesting. If I understand it correctly, then the CFFI library allows callbacks from C to Tcl - this was mentioned as a limitation for the dyncall backend, but not described in the
    documentation ;).

    Regards,

    Arjen

    It's described at the bottom of the Concepts page - https://cffi.magicsplat.com/cffi-Concepts.html#::Concepts-Callbacks

    Note asynchronous callbacks are not supported, only synchronous ones.

    /Ashok

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Thu Apr 7 09:08:53 2022
    Am 07.04.22 um 08:45 schrieb Arjen Markus:
    On Wednesday, April 6, 2022 at 5:15:41 AM UTC+2, apn wrote:
    The cffi package permits calling C functions in shared libraries from
    within Tcl scripts via either the libffi or dyncall open source libraries. >>
    As I mentioned in the chat yesterday, this looks really interesting. If I understand it correctly, then the CFFI library allows callbacks from C to Tcl - this was mentioned as a limitation for the dyncall backend, but not described in the
    documentation ;).


    libffi is also used in the Python standard library - the module "ctypes"
    allows Python users to interface to any C library, including callbacks,
    which is heavily used to build extensions at the script level, without a
    C compiler. It is quite interesting to have the same thing for Tcl.

    Christian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arjen Markus@21:1/5 to apn on Wed Apr 6 23:45:31 2022
    On Wednesday, April 6, 2022 at 5:15:41 AM UTC+2, apn wrote:
    The cffi package permits calling C functions in shared libraries from
    within Tcl scripts via either the libffi or dyncall open source libraries.

    As I mentioned in the chat yesterday, this looks really interesting. If I understand it correctly, then the CFFI library allows callbacks from C to Tcl - this was mentioned as a limitation for the dyncall backend, but not described in the documentation ;
    ).

    Regards,

    Arjen

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ashok@21:1/5 to Christian Gollwitzer on Thu Apr 7 13:02:56 2022
    On 4/7/2022 12:38 PM, Christian Gollwitzer wrote:
    libffi is also used in the Python standard library - the module "ctypes" allows Python users to interface to any C library, including callbacks,
    which is heavily used to build extensions at the script level, without a
    C compiler. It is quite interesting to have the same thing for Tcl.

        Christian

    Not just python, even Tcl has had a libffi based FFI interface - ffidl -
    for a while now.

    cffi came about for two reasons - for a long while libffi did not
    support Win64 (I'm talking a decade or more ago) so twapi made use of
    dyncall. That eventually lead to cffi. Second, I felt scripting using a
    C API needed more safety as well as convenience features. Hence cffi.
    Adding libffi support in addition to dyncall was just the logical next step.

    Anyone wrapping C API's should look at both ffidl and cffi and decide
    for themselves. I'd obviously be biased no matter how much I claim
    otherwise :-)

    /Ashok

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arjen Markus@21:1/5 to Ashok on Fri Apr 8 03:07:15 2022
    On Thursday, April 7, 2022 at 9:33:02 AM UTC+2, Ashok wrote:


    cffi came about for two reasons - for a long while libffi did not
    support Win64 (I'm talking a decade or more ago) so twapi made use of dyncall. That eventually lead to cffi. Second, I felt scripting using a
    C API needed more safety as well as convenience features. Hence cffi.
    Adding libffi support in addition to dyncall was just the logical next step.

    Anyone wrapping C API's should look at both ffidl and cffi and decide
    for themselves. I'd obviously be biased no matter how much I claim
    otherwise :-)

    /Ashok

    Well, I will not attempt this, but my simple experiments so far show that with cffi it is really simple to call functions in external libraries. My experiments involved calling a few Fortran functions and a subroutine on Windows. The library was compiled
    with gfortran and with Intel Fortran and both versions worked rightaway. As cffi supports the transparent use of Tcl lists as C and Fortran arrays, this opens up quite some possibilities.

    Regards,

    Arjen

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)