Page 1 of 1

struct function only with libffi compiled in?

PostPosted: Tue Apr 21, 2015 5:09 pm
by TedWalther
Lutz, I did some tests last week, and it appears (could be wrong) that struct is only supported when libffi support is compiled in. Is this true? If so, would it be hard to enable struct even without libffi support?

Also, is libffi a Unix only thing, or is there Windows support as well?

Re: struct function only with libffi compiled in?

PostPosted: Wed Apr 22, 2015 6:24 am
by Lutz
All the main newLISP distributions: OSX, Windows and UBUTU Linux support the extended import API based on libffi and the struct function. If libffi support is present, the signon message contains the word libffi. In code you also could use the expression (primitive? struct) which only evaluates to true on libffi enabled versions.

But you can handle structures as well with the simple import API present in all versions and compiled flavors of newLISP. See the subchapter "Importing data structures" of the CodePatterns document here:

http://www.newlisp.org/downloads/CodePa ... tml#toc-23

The simple function import API relies on a strict implementation of C-calling conventions with all function parameters passed on the stack and in fixed width memory words, either 32-bit words on 32-bit versions of newLISP and 64-bit words on 64-bit versions of newLISP. When using the simple API, the programmer must have knowledge about the bit size of the different C-types and how ther are alligned and padded with dummy bytes on 32/64 bit borders when occuring next to each other in a structure. Using the pack and unpack functions present in all versions of newLISP, this can be handled by the programmer.

Re: struct function only with libffi compiled in?

PostPosted: Wed Apr 22, 2015 4:23 pm
by TedWalther
Thank you for the explanation Lutz.

I find struct a very convenient function, but I see what you are saying about pack/unpack being sufficient. Would it be hard to enable struct without libffi, or is that a libffi function itself?

Alternately, could you add that to the documentation for struct, that it is only present when libffi is compiled in?

The reason I have a newLisp without libffi is I haven't had time to upgrade my OpenBSD box. After some gentle reminders over the past two years, the latest release (or two) of OpenBSD have a new enough libffi that it should work with newLisp, but the older version I have has the wrong release of libffi. Thanks to Jasper and friends for updating the libffi in OpenBSD.