Subject: Ffidl open questions: namespace, syntax, exceptions - DN [1]


Roger E Critchlow Jr <rec@elf.org> - 09 Nov 1999 - comp.lang.tcl

 Ffidl is an extension that allows constructing calls to C code in pure
 Tcl.  The initial release of Ffidl is described at

     http://elf.org/ffidl/

 Work on the next release of Ffidl is progressing nicely.  I have
 ported libffi-2.00-beta to Windows and exposed its implementation of
 callbacks in Ffidl.  Robin Becker has verified the Windows
 implementation, in binary form, with one of his ::dll:: examples.

 I've also been looking at incorporating another foreign function call
 library, the GPL'ed ffcall package from clisp, into Ffidl.  This has
 support for other architectures, including AIX and HP-UX, general
 support for callbacks, VisualC and Borland makefiles, and a vastly
 different organization than libffi.  At the moment it's looking quite
 reasonable, but it's a lot more work than I was planning to do for
 free right now, so it may have to wait unless someone wants to help
 clarify my priorties for me.

 Robin has made a few suggestions which I would like to hear some
 other opinions on.

 The current Ffidl interface looks like this:

   ffidl-proc name {?arg_type1 ...?} ret_type address ?protocol?
   ffidl-callback name {?arg_type1 ...?} ret_type ?protocol?

 ffidl-proc establishes a Tcl command "name" which accepts the
 specified "arg_types", converts them to C values, calls the
 function at "address" according to "protocol", and converts the return
 value into a Tcl object according to "ret_type".

 ffidl-callback establishes a C callable function pointer which accepts
 the specified "arg_types", converts them to Tcl objects, calls
 the Tcl proc "name", converts the Tcl result into a C value according
 to "ret_type", and returns according to "protocol".

 In either case, "protocol" specifies a calling convention where there
 is a choice, as on Windows where a call might use the caller pops
 "cdecl" convention or the callee pops "stdcall" convention.

 The first suggestion is to move Ffidl into a namespace.  I have no
 problem with this, except that ::ffidl::proc will need to change its
 name, probably to ::ffidl::callout.  So we'd have:

   ::ffidl::callout name {?arg_type1 ...?} ret_type address ?protocol?
   ::ffidl::callback name {?arg_type1 ...?} ret_type ?protocol?

 The second suggestion is to reorganize the syntax so that it looks
 more like a C/C++ declaration:

   ::ffidl::callout ret_type name {?arg_type1 ...?} address
   ::ffidl::callback ret_type name {?arg_type1 ...?}
   ::ffidl::callout-cdecl ret_type name {?arg_type1 ...?} address
   ::ffidl::callback-cdecl ret_type name {?arg_type1 ...?}
   ::ffidl::callout-stdcall ret_type name {?arg_type1 ...?} address
   ::ffidl::callback-stdcall ret_type name {?arg_type1 ...?}

 I modelled the original syntax on Tcl proc, but Robin sees it as
 Pascalish.

 The third issue is what to do with ::ffidl::callback's once they've
 been lit.  ::dll:: allows them to be freed to save space.  I tend to
 think of them as dynamically compiled code -- that an address once
 advertised as a function pointer should always remain valid, even if
 all it does is panic("call to invalid callback").

 So, opinions:

     Namespaces good?
     Better names than callout and callback?
     Better syntax for callout and callback?
     Reuse callback space or maintain the function pointer?

 -- rec --

Last modified
1999-11-17

(195.108.246.50)

Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated