FFI syntax

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

FFI syntax

Annick
What is the syntax to describe an external structure with an array of int of size 6 ?

I know only the syntax

fields
^#(
(param1 ‘long’)
(param2 ‘long’)
(param3 ‘long’)
(param4 ‘long’)
(param5 ‘long’)
(param6 ‘long’)
)

Annick
Reply | Threaded
Open this post in threaded view
|

Re: FFI syntax

Eliot Miranda-2
Hi Annick,

On Wed, Oct 15, 2014 at 7:57 AM, Annick Fron <[hidden email]> wrote:
What is the syntax to describe an external structure with an array of int of size 6 ?

I know only the syntax

fields
^#(
(param1 ‘long’)
(param2 ‘long’)
(param3 ‘long’)
(param4 ‘long’)
(param5 ‘long’)
(param6 ‘long’)
)

Hmm.  Good question.  It seems you can write

fields
"IAXCallStateEvent defineFields"
^#(
(type 'long')
(callNo 'long')
(state 'long')
(format 'long')
(vformat 'long')
(remote 'char[256]')
(remoteName 'char[256]')
(local 'char[256]')
(localContext 'char[256]')
)

But as a community we really need to document the FFI more thoroughly :-/
 

Annick



--
best,
Eliot


Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Nicolai Hess
2014-10-15 19:18 GMT+02:00 Eliot Miranda <[hidden email]>:
Hi Annick,

On Wed, Oct 15, 2014 at 7:57 AM, Annick Fron <[hidden email]> wrote:
What is the syntax to describe an external structure with an array of int of size 6 ?

I know only the syntax

fields
^#(
(param1 ‘long’)
(param2 ‘long’)
(param3 ‘long’)
(param4 ‘long’)
(param5 ‘long’)
(param6 ‘long’)
)

Hmm.  Good question.  It seems you can write

fields
"IAXCallStateEvent defineFields"
^#(
(type 'long')
(callNo 'long')
(state 'long')
(format 'long')
(vformat 'long')
(remote 'char[256]')
(remoteName 'char[256]')
(local 'char[256]')
(localContext 'char[256]')
)


 

But as a community we really need to document the FFI more thoroughly :-/
 

+1
I can not even find up to date information on how to *install* current working FFI.
Aren't there any "alive" projects build on FFI (old or Alien-FFI).
It would help to see more real-life examples.


 

Annick



--
best,
Eliot



cbc
Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

cbc
So, I use the ODBC package from SqueakMap, which relies on FFI.  It works.  Although I have a fun time trying to remember how to do it each time, so I wrote notes the last time.  In essence:

<Load FFI From SqueakMap>
<Load ODBC For Squeak from SqueakMap>

<Load FFI-Win32 manually (constants need to go first, by hand) from source.squeak.org/FFI>
- this last one because it regularly fails for Win32 things, which I use.  Among other things, this part requires you to turn on _ as part of variable names, so that things like 
WS_EX_ACCEPTFILES := 16r10.
is valid.

Note this is all old FFI - not Alien.

-cbc

On Wed, Oct 15, 2014 at 1:59 PM, Nicolai Hess <[hidden email]> wrote:
2014-10-15 19:18 GMT+02:00 Eliot Miranda <[hidden email]>:
Hi Annick,

On Wed, Oct 15, 2014 at 7:57 AM, Annick Fron <[hidden email]> wrote:
What is the syntax to describe an external structure with an array of int of size 6 ?

I know only the syntax

fields
^#(
(param1 ‘long’)
(param2 ‘long’)
(param3 ‘long’)
(param4 ‘long’)
(param5 ‘long’)
(param6 ‘long’)
)

Hmm.  Good question.  It seems you can write

fields
"IAXCallStateEvent defineFields"
^#(
(type 'long')
(callNo 'long')
(state 'long')
(format 'long')
(vformat 'long')
(remote 'char[256]')
(remoteName 'char[256]')
(local 'char[256]')
(localContext 'char[256]')
)


 

But as a community we really need to document the FFI more thoroughly :-/
 

+1
I can not even find up to date information on how to *install* current working FFI.
Aren't there any "alive" projects build on FFI (old or Alien-FFI).
It would help to see more real-life examples.


 

Annick



--
best,
Eliot







Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Annick
In reply to this post by Eliot Miranda-2
Hi Eliot,

Thank you. Meanwhile I have tried to use only pointers to structs by writing some C code.

I confirm that in Pharo you can load FFI and OldAlien in the ConfigurationBrowser.
Yet it seems both FFI and Alien versions in the ConfigurationBrowser are behind the squeak repositories. 
I did not try if  the new versions worked.

I have posted some time ago an example for X11 windows on Linux, and I never got an answer why it was failing.

It was the following
testGetOurWindowLocation
  "self new testGetOurWindowLocation"

  | display ourWindow aParent anX anY aWidth aHeight aBorderWidth aDepth |
  display := X11Display XOpenDisplay: nil.
  ourWindow := display ourWindow.
  (Alien lookup: 'XGetGeometry' inLibrary: 'X11')
      primFFICallResult: nil
      withArguments:
          {display.
          ourWindow xid.
          (aParent := Alien new: 4).
          (anX := Alien new: 4).
          (anY := Alien new: 4).
          (aWidth := Alien new: 4).
          (aHeight := Alien new: 4).
          (aBorderWidth := Alien new: 4).
          (aDepth := Alien new: 4)}.
  (anX unsignedLongAt: 1) inspect.

Has anybody looked at Wayland (replacement of X11) on Linux ?

Annick

Le 15 oct. 2014 à 19:18, Eliot Miranda <[hidden email]> a écrit :

Hi Annick,

On Wed, Oct 15, 2014 at 7:57 AM, Annick Fron <[hidden email]> wrote:
What is the syntax to describe an external structure with an array of int of size 6 ?

I know only the syntax

fields
^#(
(param1 ‘long’)
(param2 ‘long’)
(param3 ‘long’)
(param4 ‘long’)
(param5 ‘long’)
(param6 ‘long’)
)

Hmm.  Good question.  It seems you can write

fields
"IAXCallStateEvent defineFields"
^#(
(type 'long')
(callNo 'long')
(state 'long')
(format 'long')
(vformat 'long')
(remote 'char[256]')
(remoteName 'char[256]')
(local 'char[256]')
(localContext 'char[256]')
)

But as a community we really need to document the FFI more thoroughly :-/
 

Annick



-- 
best,
Eliot
Le 15 oct. 2014 à 19:18, Eliot Miranda <[hidden email]> a écrit :

Hi Annick,

On Wed, Oct 15, 2014 at 7:57 AM, Annick Fron <[hidden email]> wrote:
What is the syntax to describe an external structure with an array of int of size 6 ?

I know only the syntax

fields
^#(
(param1 ‘long’)
(param2 ‘long’)
(param3 ‘long’)
(param4 ‘long’)
(param5 ‘long’)
(param6 ‘long’)
)

Hmm.  Good question.  It seems you can write

fields
"IAXCallStateEvent defineFields"
^#(
(type 'long')
(callNo 'long')
(state 'long')
(format 'long')
(vformat 'long')
(remote 'char[256]')
(remoteName 'char[256]')
(local 'char[256]')
(localContext 'char[256]')
)

But as a community we really need to document the FFI more thoroughly :-/
 

Annick



--
best,
Eliot



Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Nicolai Hess
2014-10-16 11:53 GMT+02:00 Annick Fron <[hidden email]>:
Hi Eliot,

Thank you. Meanwhile I have tried to use only pointers to structs by writing some C code.

I confirm that in Pharo you can load FFI and OldAlien in the ConfigurationBrowser.
Yet it seems both FFI and Alien versions in the ConfigurationBrowser are behind the squeak repositories. 
I did not try if  the new versions worked.

I have posted some time ago an example for X11 windows on Linux, and I never got an answer why it was failing.

and  you changed the argument "ourWindow" to "ourWindow xid" like I proposed. But yes,
actually this didn't help, I guess. You still get the error "bad argument" ?

My next bet would be:
Maybe we cannot mix Alien calls with (old) FFI structures (display is a externalstructure defined for FFI).


 

It was the following
testGetOurWindowLocation
  "self new testGetOurWindowLocation"

  | display ourWindow aParent anX anY aWidth aHeight aBorderWidth aDepth |
  display := X11Display XOpenDisplay: nil.
  ourWindow := display ourWindow.
  (Alien lookup: 'XGetGeometry' inLibrary: 'X11')
      primFFICallResult: nil
      withArguments:
          {display.
          ourWindow xid.
          (aParent := Alien new: 4).
          (anX := Alien new: 4).
          (anY := Alien new: 4).
          (aWidth := Alien new: 4).
          (aHeight := Alien new: 4).
          (aBorderWidth := Alien new: 4).
          (aDepth := Alien new: 4)}.
  (anX unsignedLongAt: 1) inspect.

Has anybody looked at Wayland (replacement of X11) on Linux ?

Annick

Le 15 oct. 2014 à 19:18, Eliot Miranda <[hidden email]> a écrit :

Hi Annick,

On Wed, Oct 15, 2014 at 7:57 AM, Annick Fron <[hidden email]> wrote:
What is the syntax to describe an external structure with an array of int of size 6 ?

I know only the syntax

fields
^#(
(param1 ‘long’)
(param2 ‘long’)
(param3 ‘long’)
(param4 ‘long’)
(param5 ‘long’)
(param6 ‘long’)
)

Hmm.  Good question.  It seems you can write

fields
"IAXCallStateEvent defineFields"
^#(
(type 'long')
(callNo 'long')
(state 'long')
(format 'long')
(vformat 'long')
(remote 'char[256]')
(remoteName 'char[256]')
(local 'char[256]')
(localContext 'char[256]')
)

But as a community we really need to document the FFI more thoroughly :-/
 

Annick



-- 
best,
Eliot
Le 15 oct. 2014 à 19:18, Eliot Miranda <[hidden email]> a écrit :

Hi Annick,

On Wed, Oct 15, 2014 at 7:57 AM, Annick Fron <[hidden email]> wrote:
What is the syntax to describe an external structure with an array of int of size 6 ?

I know only the syntax

fields
^#(
(param1 ‘long’)
(param2 ‘long’)
(param3 ‘long’)
(param4 ‘long’)
(param5 ‘long’)
(param6 ‘long’)
)

Hmm.  Good question.  It seems you can write

fields
"IAXCallStateEvent defineFields"
^#(
(type 'long')
(callNo 'long')
(state 'long')
(format 'long')
(vformat 'long')
(remote 'char[256]')
(remoteName 'char[256]')
(local 'char[256]')
(localContext 'char[256]')
)

But as a community we really need to document the FFI more thoroughly :-/
 

Annick



--
best,
Eliot




Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Chris Muller-3
In reply to this post by Nicolai Hess
> I can not even find up to date information on how to *install* current
> working FFI.

Look no further than the "head" version of "FFI" on SqueakMap.  You
can install it straight from the menu or select "Edit Release" to see
the script it uses to load it.

We've been so lulled into things being undocumented that, even when
they are, people don't find it because they don't think to look.

Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Frank Shearar-3
On 17 October 2014 21:54, Chris Muller <[hidden email]> wrote:
>> I can not even find up to date information on how to *install* current
>> working FFI.
>
> Look no further than the "head" version of "FFI" on SqueakMap.  You
> can install it straight from the menu or select "Edit Release" to see
> the script it uses to load it.
>
> We've been so lulled into things being undocumented that, even when
> they are, people don't find it because they don't think to look.

For instance: https://github.com/squeak-smalltalk/squeak-ci/blob/master/package-load-scripts/FFI.st
which says

Installer squeakmap
    update;
    install: 'FFI (head)'.

frank

Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Nicolai Hess
In reply to this post by Chris Muller-3
2014-10-17 22:54 GMT+02:00 Chris Muller <[hidden email]>:
> I can not even find up to date information on how to *install* current
> working FFI.

Look no further than the "head" version of "FFI" on SqueakMap.  You
can install it straight from the menu or select "Edit Release" to see
the script it uses to load it.

We've been so lulled into things being undocumented that, even when
they are, people don't find it because they don't think to look.

"people don't find it because they don't think to look."
?

This:
"I can not even find up to date information on how to *install* current working FFI."
was about a working version on linux. Working with tests and examples, something
a beginner can look into and see how it is used.

Sure maybe it is just as simple as select one entry from the squeak map list.
But how should a beginner know to look there ?
We have three package managers (in the current 4.5 release).
squeak map catalog
monticello
universe browser (<- is still here but not working)

searching squeak mailing shows links to source.squeak.org
ffi on wiki.squeak does not link to squeak map

And no,ffi examples are not in squeak map.
some ffi tests are failing.
loading ffi examples from squeak source:
FFI-Unix-Examples ->failing (can not coerce arguments)
FFI-Examples -> crash the image.

-> maybe I am just uncapable, but I thnk it is not obvious how to get FFI working, it just does not work with the
current squeak 4.5 release. You have to find a working cog version from eliots site.

nicolai







Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Nicolai Hess
2014-10-18 0:24 GMT+02:00 Nicolai Hess <[hidden email]>:
2014-10-17 22:54 GMT+02:00 Chris Muller <[hidden email]>:
> I can not even find up to date information on how to *install* current
> working FFI.

Look no further than the "head" version of "FFI" on SqueakMap.  You
can install it straight from the menu or select "Edit Release" to see
the script it uses to load it.

We've been so lulled into things being undocumented that, even when
they are, people don't find it because they don't think to look.

"people don't find it because they don't think to look."
?

This:
"I can not even find up to date information on how to *install* current working FFI."
was about a working version on linux. Working with tests and examples, something
a beginner can look into and see how it is used.

Sure maybe it is just as simple as select one entry from the squeak map list.
But how should a beginner know to look there ?
We have three package managers (in the current 4.5 release).
squeak map catalog
monticello
universe browser (<- is still here but not working)

searching squeak mailing shows links to source.squeak.org
ffi on wiki.squeak does not link to squeak map

And no,ffi examples are not in squeak map.
some ffi tests are failing.
loading ffi examples from squeak source:
FFI-Unix-Examples ->failing (can not coerce arguments)
FFI-Examples -> crash the image.


same results on windows:
some ffi tests are failing.
FFI-Examples -> crash the image.
FFI-Win32 can not be loaded


 
-> maybe I am just uncapable, but I thnk it is not obvious how to get FFI working, it just does not work with the
current squeak 4.5 release. You have to find a working cog version from eliots site.

nicolai








Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Chris Muller-4
In reply to this post by Nicolai Hess
> This:
> "I can not even find up to date information on how to *install* current
> working FFI."
> was about a working version on linux. Working with tests and examples,
> something
> a beginner can look into and see how it is used.
>
> Sure maybe it is just as simple as select one entry from the squeak map
> list.
> But how should a beginner know to look there ?

I always hoped the word "Catalog" on the menu entry would stand out
enough to encourage beginners to click and "see what's there".  If
not, there is lots of beginner documentation:  wiki, videos, etc.
which refer to SqueakMap.  I agree there's room for improvement
though..

> We have three package managers (in the current 4.5 release).
> squeak map catalog
> monticello
> universe browser (<- is still here but not working)

Universes brings up an empty list, SqueakMap does not.  Simply
following the path of least resistance gets you a working FFI in
Squeak 4.5.

> searching squeak mailing shows links to source.squeak.org
> ffi on wiki.squeak does not link to squeak map

The whole point of SqueakMap is to _avoid_ having to search mailing
lists.  It is the only single place that can document where any Squeak
software is, regardless what other SCM repository is being used to
host it.  That's why SqueakMap shoud always be checked first and, if
not there, only then have to dig thru mailing lists, etc.

> And no,ffi examples are not in squeak map.

Then why not make an entry for them there so the next person can find
them?  It is really very easy to do that (see [1]).

I made entries for a lot of projects that aren't mine, but the only
way to get out of this rut as a community is to embrace our catalog as
a community.

> some ffi tests are failing.

Not the ones from loaded from SqueakMap.  I just tried it in a stock
4.5 and trunk and got 32 out of 32 green tests, on Ubuntu Linux 12.04
LTS.

> loading ffi examples from squeak source:
> FFI-Unix-Examples ->failing (can not coerce arguments)
> FFI-Examples -> crash the image.
>
> -> maybe I am just uncapable, but I thnk it is not obvious how to get FFI
> working, it just does not work with the
> current squeak 4.5 release. You have to find a working cog version from
> eliots site.

SqueakMap documentation for FFI Core and Tests appears to be
up-to-date.  If you have found a working "FFI Examples" somewhere
(mirandabanda.org?) and you got it working in 4.5 or trunk, I hope
you'll add an entry to SqueakMap..  I'll help!

 - Chris

[1] -- "SqueakMap Publishing Guidelines"  http://wiki.squeak.org/squeak/6182

Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Nicolai Hess
2014-10-18 1:11 GMT+02:00 Chris Muller <[hidden email]>:

> And no,ffi examples are not in squeak map.

Then why not make an entry for them there so the next person can find
them?  It is really very easy to do that (see [1]).

I made entries for a lot of projects that aren't mine, but the only
way to get out of this rut as a community is to embrace our catalog as
a community.


I'll try it.


SqueakMap documentation for FFI Core and Tests appears to be
up-to-date.  If you have found a working "FFI Examples" somewhere
(mirandabanda.org?) and you got it working in 4.5 or trunk,

I tried to find the maintainer (http://forum.world.st/Maintainer-of-FFI-Package-td4781017.html) or whoever
made the latest changes,because, the latest comment for FFI-Unix: "made the XLib examples actually work (Window is an unsigned int handle, not a struct)"
sounds like they should work now, but as far as I understand the code, this can not work, I would like
to clearify this.

Did you use the 4.5 image *and* the vm from Squeak 4.5 all-in-one?
Because I can not get it to work not on linux (ok, ubuntu 10.04 32 Bit I'll try it on
a more recent version) and not on windows (Windows 7 32 Bit)

I hope
you'll add an entry to SqueakMap..  I'll help!

Thank you for your help.



Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Chris Muller-4
> Did you use the 4.5 image *and* the vm from Squeak 4.5 all-in-one?
> Because I can not get it to work not on linux (ok, ubuntu 10.04 32 Bit I'll
> try it on
> a more recent version) and not on windows (Windows 7 32 Bit)

I tried it with the Cog-Linux-HT-3095 VM.

Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Annick
I have tried a version of the examples mentioned in the list, and it works.


But I have still doubts with passing variables by reference (&var in C): this is common in C to allocate a variable, pass its pointer as argument to get the value back, instead of using function returns.


Annick

Le 18 oct. 2014 à 05:12, Chris Muller <[hidden email]> a écrit :

>> Did you use the 4.5 image *and* the vm from Squeak 4.5 all-in-one?
>> Because I can not get it to work not on linux (ok, ubuntu 10.04 32 Bit I'll
>> try it on
>> a more recent version) and not on windows (Windows 7 32 Bit)
>
> I tried it with the Cog-Linux-HT-3095 VM.
>


Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-users] [squeak-dev] FFI syntax

Bert Freudenberg
On 18.10.2014, at 09:52, Annick Fron <[hidden email]> wrote:

> But I have still doubts with passing variables by reference (&var in C): this is common in C to allocate a variable, pass its pointer as argument to get the value back, instead of using function returns.

Internally, C handles references as pointers.

- Bert -



smime.p7s (5K) Download Attachment