FFI to UFFI

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

FFI to UFFI

eftomi
I started to play with ODBC package upgrade from Pharo 4.0 to 7.0 (http://smalltalkhub.com/mc/PharoExtras/ODBC), more or less as an exercise. As a smalltalk novice I stubmled to the challenge of, as it seems, an old FFI syntax. When I try to load the package into Pharo 7.02 on Windows, I get this error:


I have two questions:
- Is there any elegant way to successfuly load the package into Pharo 7 to get started with the code adaptation?
- And, of course, I'd be grateful if someone could point me into the right direction of how to tackle with the above cdecl syntax with the new UFFI. 

Best wishes
Tomaz
Reply | Threaded
Open this post in threaded view
|

Re: FFI to UFFI

Pierce Ng-3
On Sat, Mar 23, 2019 at 05:22:32PM +0000, Tomaž Turk wrote:
> - Is there any elegant way to successfuly load the package into Pharo 7 to
> get started with the code adaptation?

Elegantly, dunno.

Manually, open Monticello browser, right click on the repo (if you have
loaded the ConfigOf then the repo will be listed), click "open
repository". Click the mcz file in the right pane of the repo browser,
click "browse". You'll see the (not loaded) code in the resulting code
browser and can attempt to adapt the FFI calls.

> - And, of course, I'd be grateful if someone could point me into the right
> direction of how to tackle with the above cdecl syntax with the new UFFI.

https://files.pharo.org/books-pdfs/booklet-uFFI/UFFIDRAFT.pdf

Also see my very simple demo:

https://github.com/PierceNg/libffidemo

HTH.

Pierce

Reply | Threaded
Open this post in threaded view
|

Re: FFI to UFFI

EstebanLM
In reply to this post by eftomi
Hi,

One way: 

1) load the old compiler from here: https://github.com/pharo-project/OldCompiler
2) Activate it: 

SmalltalkImage compilerClass: Compiler.

3) load ODBC

4) restore OpalCompiler

SmalltalkImage compilerClass: OpalCompiler.

This *should* work.


Esteban

On 23 Mar 2019, at 18:22, Tomaž Turk <[hidden email]> wrote:

I started to play with ODBC package upgrade from Pharo 4.0 to 7.0 (http://smalltalkhub.com/mc/PharoExtras/ODBC), more or less as an exercise. As a smalltalk novice I stubmled to the challenge of, as it seems, an old FFI syntax. When I try to load the package into Pharo 7.02 on Windows, I get this error:

<br0g15dj.png>

I have two questions:
- Is there any elegant way to successfuly load the package into Pharo 7 to get started with the code adaptation?
- And, of course, I'd be grateful if someone could point me into the right direction of how to tackle with the above cdecl syntax with the new UFFI. 

Best wishes
Tomaz

Reply | Threaded
Open this post in threaded view
|

Re: FFI to UFFI

EstebanLM
In reply to this post by eftomi
Now, about translation to UFFI, is not so simple, but not so complex (it just needs some work).

1) you need to declare the types like SQLRETURN, usually in a shared pool, something like: 

SQLRETURN := #uint.

That you later will include in your ODBC classes.

2) you need to translate structures (this is the hardest part).
In UFFI, you declare structures extending FFIExternalStructure and declaring fields with something like this:

fieldsDesc 
"self rebuildFieldAccessors"
^ #(
double ascent;
double descent;
double height;
double max_x_advance;
double max_y_advance;
)

Finally, you need to translate the function calls. The function you are putting as an example would be translated like that: 

sqAllocEnv: environmentHandle

^ self ffiCall: #(SQLRETURN SQAllocEnv(SQLHENV environmentHandle) )

Which, if you see, is a direct translation of the function call :)

Esteban

PS: I have in my infinite TODO list to do this… but I do not had the time yet :(
Also, the real problem is that once you are working with UFFI, the design possibilities of a library change a lot, and you can do something a lot more close to real OOP. That’s what happened to me when I fist took a look to the package to translate it… I said “Oh boy, I would do this very differently" :P



On 23 Mar 2019, at 18:22, Tomaž Turk <[hidden email]> wrote:

I started to play with ODBC package upgrade from Pharo 4.0 to 7.0 (http://smalltalkhub.com/mc/PharoExtras/ODBC), more or less as an exercise. As a smalltalk novice I stubmled to the challenge of, as it seems, an old FFI syntax. When I try to load the package into Pharo 7.02 on Windows, I get this error:

<br0g15dj.png>

I have two questions:
- Is there any elegant way to successfuly load the package into Pharo 7 to get started with the code adaptation?
- And, of course, I'd be grateful if someone could point me into the right direction of how to tackle with the above cdecl syntax with the new UFFI. 

Best wishes
Tomaz

Reply | Threaded
Open this post in threaded view
|

Re: FFI to UFFI

EstebanLM
In reply to this post by eftomi
One final consideration: 

Truth is, once you load it in P7, the package should work (at least in 32 bits, I do not think is made thinking on 64bits platforms). Both notations ends calling same primitives.

This means, if your intentions are just to play a bit and see how things work: you should not need to do the translation :)

Esteban

Ps: I just tried in P8 the approach to load I proposed. It throws an error but loads.



On 23 Mar 2019, at 18:22, Tomaž Turk <[hidden email]> wrote:

I started to play with ODBC package upgrade from Pharo 4.0 to 7.0 (http://smalltalkhub.com/mc/PharoExtras/ODBC), more or less as an exercise. As a smalltalk novice I stubmled to the challenge of, as it seems, an old FFI syntax. When I try to load the package into Pharo 7.02 on Windows, I get this error:

<br0g15dj.png>

I have two questions:
- Is there any elegant way to successfuly load the package into Pharo 7 to get started with the code adaptation?
- And, of course, I'd be grateful if someone could point me into the right direction of how to tackle with the above cdecl syntax with the new UFFI. 

Best wishes
Tomaz

Reply | Threaded
Open this post in threaded view
|

FFI to UFFI

eftomi
Pierce, Esteban, many thanks for your most valuable directions. Live and learn :-)

Tomaz 



------ Original Message ------
From: "Esteban Lorenzano" <[hidden email]>
To: "Tomaž Turk" <[hidden email]>; "Any question about pharo is welcome" <[hidden email]>
Sent: 24.3.2019 8:10:32
Subject: Re: [Pharo-users] FFI to UFFI

One final consideration: 

Truth is, once you load it in P7, the package should work (at least in 32 bits, I do not think is made thinking on 64bits platforms). Both notations ends calling same primitives.

This means, if your intentions are just to play a bit and see how things work: you should not need to do the translation :)

Esteban

Ps: I just tried in P8 the approach to load I proposed. It throws an error but loads.



On 23 Mar 2019, at 18:22, Tomaž Turk <[hidden email]> wrote:

I started to play with ODBC package upgrade from Pharo 4.0 to 7.0 (http://smalltalkhub.com/mc/PharoExtras/ODBC), more or less as an exercise. As a smalltalk novice I stubmled to the challenge of, as it seems, an old FFI syntax. When I try to load the package into Pharo 7.02 on Windows, I get this error:

<br0g15dj.png>

I have two questions:
- Is there any elegant way to successfuly load the package into Pharo 7 to get started with the code adaptation?
- And, of course, I'd be grateful if someone could point me into the right direction of how to tackle with the above cdecl syntax with the new UFFI. 

Best wishes
Tomaz