FFI | How to declare pointer to external structure in #fields?

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

FFI | How to declare pointer to external structure in #fields?

marcel.taeumel
Hi, there!

In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?

First, non-pointer works as expected:
^ #( (other MyStruct) )

Second, this just treats it as a void*, which returns a generic ExternalData:
^ #( (other 'MyStruct*') )

Third, this gives me a debugger:
^ #( (other MyStruct *) )

:-)

Best,
Marcel


Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Vanessa Freudenberg
On Mon, May 18, 2020 at 7:05 AM Marcel Taeumel <[hidden email]> wrote:
Hi, there!

In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?

First, non-pointer works as expected:
^ #( (other MyStruct) )

Second, this just treats it as a void*, which returns a generic ExternalData:
^ #( (other 'MyStruct*') )

Third, this gives me a debugger:
^ #( (other MyStruct *) )


I don't have the code in front of me but there is the parser you could check ;)

It might be *MyStruct.

 - Vanessa - 


Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

marcel.taeumel
Hi Vanessa,

I don't have the code in front of me but there is the parser you could check ;)

I tried. I suspect that the generator cannot do it but I have to wrap it manually. But I am not sure. Reverse engineering UnifiedFFI did not help yet either. Have to put more time into it. :-)

Best,
Marcel

Am 18.05.2020 20:00:16 schrieb Vanessa Freudenberg <[hidden email]>:

On Mon, May 18, 2020 at 7:05 AM Marcel Taeumel <[hidden email]> wrote:
Hi, there!

In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?

First, non-pointer works as expected:
^ #( (other MyStruct) )

Second, this just treats it as a void*, which returns a generic ExternalData:
^ #( (other 'MyStruct*') )

Third, this gives me a debugger:
^ #( (other MyStruct *) )


I don't have the code in front of me but there is the parser you could check ;)

It might be *MyStruct.

 - Vanessa - 


Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Jakob Reschke-2
Do we even have UFFI in Squeak? This was the thing I meant is missing to reuse Pharo's libgit2 bindings, in the vm-dev thread. 

Marcel Taeumel <[hidden email]> schrieb am Mo., 18. Mai 2020, 20:07:
Hi Vanessa,

I don't have the code in front of me but there is the parser you could check ;)

I tried. I suspect that the generator cannot do it but I have to wrap it manually. But I am not sure. Reverse engineering UnifiedFFI did not help yet either. Have to put more time into it. :-)

Best,
Marcel

Am 18.05.2020 20:00:16 schrieb Vanessa Freudenberg <[hidden email]>:

On Mon, May 18, 2020 at 7:05 AM Marcel Taeumel <[hidden email]> wrote:
Hi, there!

In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?

First, non-pointer works as expected:
^ #( (other MyStruct) )

Second, this just treats it as a void*, which returns a generic ExternalData:
^ #( (other 'MyStruct*') )

Third, this gives me a debugger:
^ #( (other MyStruct *) )


I don't have the code in front of me but there is the parser you could check ;)

It might be *MyStruct.

 - Vanessa - 



Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Eliot Miranda-2
In reply to this post by marcel.taeumel
Hi Marcel,

On Mon, May 18, 2020 at 7:05 AM Marcel Taeumel <[hidden email]> wrote:
Hi, there!

In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?

First, non-pointer works as expected:
^ #( (other MyStruct) )

Second, this just treats it as a void*, which returns a generic ExternalData:
^ #( (other 'MyStruct*') )

Third, this gives me a debugger:
^ #( (other MyStruct *) )

:-)

ExternalStructure class>>#compileFields:withAccessors: implies it is some variation on (filedName 'StructType *). See

fieldName := spec first.
fieldType := spec second.
isPointerField := fieldType last = $*.
fieldType := (fieldType findTokens: '*') first withBlanksTrimmed.
externalType := ExternalType atomicTypeNamed: fieldType.
selfRefering := isPointerField and: [externalType isNil and: [fieldType = self asString]].
selfRefering ifTrue: [
externalType := ExternalType void asPointerType
] ifFalse:[
externalType == nil ifTrue: ["non-atomic"
Symbol
hasInterned: fieldType
ifTrue: [:sym | externalType := ExternalType structTypeNamed: sym].
].
externalType == nil ifTrue:[
Transcript show: '(' , fieldType , ' is void)'.
externalType := ExternalType void.
].

So ...isPointerField should be true.
ExternalType atomicTypeNamed: 'MyStruct*' should answer nil.
ExternalType structTypeNamed: sym should receive MyStruct.
If MyStruct doesn't answer anything (externalType is nil) then an error should appear in the transcript.

HTH
_,,,^..^,,,_
best, Eliot


Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Eliot Miranda-2


On Mon, May 18, 2020 at 12:26 PM Eliot Miranda <[hidden email]> wrote:
Hi Marcel,

On Mon, May 18, 2020 at 7:05 AM Marcel Taeumel <[hidden email]> wrote:
Hi, there!

In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?

First, non-pointer works as expected:
^ #( (other MyStruct) )

Second, this just treats it as a void*, which returns a generic ExternalData:
^ #( (other 'MyStruct*') )

Third, this gives me a debugger:
^ #( (other MyStruct *) )

:-)

ExternalStructure class>>#compileFields:withAccessors: implies it is some variation on (filedName 'StructType *).

I mean  #(fieldName 'StructType*')
 
See

fieldName := spec first.
fieldType := spec second.
isPointerField := fieldType last = $*.
fieldType := (fieldType findTokens: '*') first withBlanksTrimmed.
externalType := ExternalType atomicTypeNamed: fieldType.
selfRefering := isPointerField and: [externalType isNil and: [fieldType = self asString]].
selfRefering ifTrue: [
externalType := ExternalType void asPointerType
] ifFalse:[
externalType == nil ifTrue: ["non-atomic"
Symbol
hasInterned: fieldType
ifTrue: [:sym | externalType := ExternalType structTypeNamed: sym].
].
externalType == nil ifTrue:[
Transcript show: '(' , fieldType , ' is void)'.
externalType := ExternalType void.
].

So ...isPointerField should be true.
ExternalType atomicTypeNamed: 'MyStruct*' should answer nil.
ExternalType structTypeNamed: sym should receive MyStruct.
If MyStruct doesn't answer anything (externalType is nil) then an error should appear in the transcript.

HTH
_,,,^..^,,,_
best, Eliot


--
_,,,^..^,,,_
best, Eliot


Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Levente Uzonyi
In reply to this post by marcel.taeumel
Hi Marcel,

On Mon, 18 May 2020, Marcel Taeumel wrote:

> Hi, there!
>
> In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?
>
> First, non-pointer works as expected:
> ^ #( (other MyStruct) )
>
> Second, this just treats it as a void*, which returns a generic ExternalData:
> ^ #( (other 'MyStruct*') )

This is how it should be written. Does MyStruct exist when you're writing
this method? If yes, is there a refence to that class in ExternalType's
StructTypes class variable?

Levente

>
> Third, this gives me a debugger:
> ^ #( (other MyStruct *) )
>
> :-)
>
> Best,
> Marcel
>
>

Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

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


ExternalStructure compileFields: #((other 'FFITestPoint2*')) a WordArray(65544 131080)

ExternalStructure compileFields: #((other 'FFITestPoint2 *')) a WordArray(65544 131080)

On Mon, May 18, 2020 at 12:27 PM Eliot Miranda <[hidden email]> wrote:


On Mon, May 18, 2020 at 12:26 PM Eliot Miranda <[hidden email]> wrote:
Hi Marcel,

On Mon, May 18, 2020 at 7:05 AM Marcel Taeumel <[hidden email]> wrote:
Hi, there!

In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?

First, non-pointer works as expected:
^ #( (other MyStruct) )

Second, this just treats it as a void*, which returns a generic ExternalData:
^ #( (other 'MyStruct*') )

Third, this gives me a debugger:
^ #( (other MyStruct *) )

:-)

ExternalStructure class>>#compileFields:withAccessors: implies it is some variation on (filedName 'StructType *).

I mean  #(fieldName 'StructType*')
 
See

fieldName := spec first.
fieldType := spec second.
isPointerField := fieldType last = $*.
fieldType := (fieldType findTokens: '*') first withBlanksTrimmed.
externalType := ExternalType atomicTypeNamed: fieldType.
selfRefering := isPointerField and: [externalType isNil and: [fieldType = self asString]].
selfRefering ifTrue: [
externalType := ExternalType void asPointerType
] ifFalse:[
externalType == nil ifTrue: ["non-atomic"
Symbol
hasInterned: fieldType
ifTrue: [:sym | externalType := ExternalType structTypeNamed: sym].
].
externalType == nil ifTrue:[
Transcript show: '(' , fieldType , ' is void)'.
externalType := ExternalType void.
].

So ...isPointerField should be true.
ExternalType atomicTypeNamed: 'MyStruct*' should answer nil.
ExternalType structTypeNamed: sym should receive MyStruct.
If MyStruct doesn't answer anything (externalType is nil) then an error should appear in the transcript.

HTH
_,,,^..^,,,_
best, Eliot


--
_,,,^..^,,,_
best, Eliot


--
_,,,^..^,,,_
best, Eliot


Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Levente Uzonyi
In reply to this post by Jakob Reschke-2
How does UFFI come here? AFAIK it's nothing but a different image-side
code using the VM's FFI implementation along with the signature notion
Igor used in NativeBoost (which is great btw because it's "as you would
write it in C" and doesn't require language changes).


Levente

On Mon, 18 May 2020, Jakob Reschke wrote:

> Do we even have UFFI in Squeak? This was the thing I meant is missing to reuse Pharo's libgit2 bindings, in the vm-dev thread. 
>
> Marcel Taeumel <[hidden email]> schrieb am Mo., 18. Mai 2020, 20:07:
>       Hi Vanessa,
> > I don't have the code in front of me but there is the parser you could check ;)
>
> I tried. I suspect that the generator cannot do it but I have to wrap it manually. But I am not sure. Reverse engineering UnifiedFFI did not help yet either. Have to put more time into it. :-)
>
> Best,
> Marcel
>
>       Am 18.05.2020 20:00:16 schrieb Vanessa Freudenberg <[hidden email]>:
>
>       On Mon, May 18, 2020 at 7:05 AM Marcel Taeumel <[hidden email]> wrote:
>       Hi, there!
>
> In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?
>
> First, non-pointer works as expected:
> ^ #( (other MyStruct) )
>
> Second, this just treats it as a void*, which returns a generic ExternalData:
> ^ #( (other 'MyStruct*') )
>
> Third, this gives me a debugger:
> ^ #( (other MyStruct *) )
>
>
> I don't have the code in front of me but there is the parser you could check ;)
>
> It might be *MyStruct.
>
>  - Vanessa - 
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Nicolas Cellier
Hi all,
I started to write a documentation of FFI implementation two or three months ago, I don't remember exactly, it's an eternity. The lock down did not give me an opportunity to continue. I want to publish with some liberal CC license, but I don't have chosen a support format yet. On one side, I wanted to focus on contents more than on the format. But on the other side, I want some graphical illustrations accurate enough. I wrote in Word because it was easy for me to include tables and graphics, but it's kinda stupid, especially because Word make you focus on format more than contents ! LaTeX is not general enough, it would rather be a backend nowadays. I contemplated using pandoc which has good support, or the much more limited Pilar, which at least is Smalltalk based...
The structure is not well established and the work is very preliminary, but since there is some demand, I give a pdf copy here as is, I hope it's not too big for the list. This probably should better be continued as a collaborative work anyway.

Le lun. 18 mai 2020 à 21:33, Levente Uzonyi <[hidden email]> a écrit :
How does UFFI come here? AFAIK it's nothing but a different image-side
code using the VM's FFI implementation along with the signature notion
Igor used in NativeBoost (which is great btw because it's "as you would
write it in C" and doesn't require language changes).


Levente

On Mon, 18 May 2020, Jakob Reschke wrote:

> Do we even have UFFI in Squeak? This was the thing I meant is missing to reuse Pharo's libgit2 bindings, in the vm-dev thread. 
>
> Marcel Taeumel <[hidden email]> schrieb am Mo., 18. Mai 2020, 20:07:
>       Hi Vanessa,
> > I don't have the code in front of me but there is the parser you could check ;)
>
> I tried. I suspect that the generator cannot do it but I have to wrap it manually. But I am not sure. Reverse engineering UnifiedFFI did not help yet either. Have to put more time into it. :-)
>
> Best,
> Marcel
>
>       Am 18.05.2020 20:00:16 schrieb Vanessa Freudenberg <[hidden email]>:
>
>       On Mon, May 18, 2020 at 7:05 AM Marcel Taeumel <[hidden email]> wrote:
>       Hi, there!
>
> In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?
>
> First, non-pointer works as expected:
> ^ #( (other MyStruct) )
>
> Second, this just treats it as a void*, which returns a generic ExternalData:
> ^ #( (other 'MyStruct*') )
>
> Third, this gives me a debugger:
> ^ #( (other MyStruct *) )
>
>
> I don't have the code in front of me but there is the parser you could check ;)
>
> It might be *MyStruct.
>
>  - Vanessa - 
>
>
>
>



The Squeak Foreign Function Interface and its implementation demystified.pdf (615K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Vanessa Freudenberg
In reply to this post by Levente Uzonyi
On Mon, May 18, 2020 at 12:28 PM Levente Uzonyi <[hidden email]> wrote:
Hi Marcel,

On Mon, 18 May 2020, Marcel Taeumel wrote:

> Hi, there!
>
> In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?
>
> First, non-pointer works as expected:
> ^ #( (other MyStruct) )
>
> Second, this just treats it as a void*, which returns a generic ExternalData:
> ^ #( (other 'MyStruct*') )

This is how it should be written. Does MyStruct exist when you're writing
this method? If yes, is there a refence to that class in ExternalType's
StructTypes class variable?

Levente


This is the correct answer. I missed the 'treats it as a void*' part.

The current FFI is very low-level. It tries to do as little magic as possible, meaning it may be necessary to still manually write a lot of the necessary accessors.

Also, we do not have a good story for 32/64 bits yet, I think. The same FFI code is unlikely to work on both.

- Vanessa - 


Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Vanessa Freudenberg
In reply to this post by Nicolas Cellier
On Mon, May 18, 2020 at 12:56 PM Nicolas Cellier <[hidden email]> wrote:
Hi all,
I started to write a documentation of FFI implementation two or three months ago, I don't remember exactly, it's an eternity. The lock down did not give me an opportunity to continue. I want to publish with some liberal CC license, but I don't have chosen a support format yet. On one side, I wanted to focus on contents more than on the format. But on the other side, I want some graphical illustrations accurate enough. I wrote in Word because it was easy for me to include tables and graphics, but it's kinda stupid, especially because Word make you focus on format more than contents ! LaTeX is not general enough, it would rather be a backend nowadays. I contemplated using pandoc which has good support, or the much more limited Pilar, which at least is Smalltalk based...
The structure is not well established and the work is very preliminary, but since there is some demand, I give a pdf copy here as is, I hope it's not too big for the list. This probably should better be continued as a collaborative work anyway.

Awesome!

- Vanessa - 


Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

marcel.taeumel
How does UFFI come here?

I just wanted to backtrack those struct pointers lead to the accessor in Pharo. But it gave me no easy clue that I could apply to plain FFI in Squeak. :-)

I started to write a documentation of FFI implementation two or three months ago ...

Yeah! I will have a look at it. GitHub Markdown + embedded graphics also hosted on GitHub could work. And support pull requests. :-) Maybe put it into the osvm repository.

Best,
Marcel

Am 18.05.2020 23:47:38 schrieb Vanessa Freudenberg <[hidden email]>:

On Mon, May 18, 2020 at 12:56 PM Nicolas Cellier <[hidden email]> wrote:
Hi all,
I started to write a documentation of FFI implementation two or three months ago, I don't remember exactly, it's an eternity. The lock down did not give me an opportunity to continue. I want to publish with some liberal CC license, but I don't have chosen a support format yet. On one side, I wanted to focus on contents more than on the format. But on the other side, I want some graphical illustrations accurate enough. I wrote in Word because it was easy for me to include tables and graphics, but it's kinda stupid, especially because Word make you focus on format more than contents ! LaTeX is not general enough, it would rather be a backend nowadays. I contemplated using pandoc which has good support, or the much more limited Pilar, which at least is Smalltalk based...
The structure is not well established and the work is very preliminary, but since there is some demand, I give a pdf copy here as is, I hope it's not too big for the list. This probably should better be continued as a collaborative work anyway.

Awesome!

- Vanessa - 


Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

marcel.taeumel
In reply to this post by Levente Uzonyi
Hi Levente.

 Does MyStruct exist when you're writing this method?

Yes.

> If yes, is there a refence to that class in ExternalType's StructTypes class variable?

Yes.

**

The issue was that I wanted to make a pointer to the struct I am currently (re-)defining:

struct MyStruct {
   MyStruct *foobar;
};

Works fine when pointing to other structs. Should code generation work for this case? :-)

Best,
Marcel

Am 18.05.2020 21:28:49 schrieb Levente Uzonyi <[hidden email]>:

Hi Marcel,

On Mon, 18 May 2020, Marcel Taeumel wrote:

> Hi, there!
>
> In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?
>
> First, non-pointer works as expected:
> ^ #( (other MyStruct) )
>
> Second, this just treats it as a void*, which returns a generic ExternalData:
> ^ #( (other 'MyStruct*') )

This is how it should be written. Does MyStruct exist when you're writing
this method? If yes, is there a refence to that class in ExternalType's
StructTypes class variable?

Levente

>
> Third, this gives me a debugger:
> ^ #( (other MyStruct *) )
>
> :-)
>
> Best,
> Marcel
>
>



Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Nicolas Cellier
In reply to this post by marcel.taeumel


Le mar. 19 mai 2020 à 08:15, Marcel Taeumel <[hidden email]> a écrit :
How does UFFI come here?

I just wanted to backtrack those struct pointers lead to the accessor in Pharo. But it gave me no easy clue that I could apply to plain FFI in Squeak. :-)

I started to write a documentation of FFI implementation two or three months ago ...

Yeah! I will have a look at it. GitHub Markdown + embedded graphics also hosted on GitHub could work. And support pull requests. :-) Maybe put it into the osvm repository.

Hi Marcel,
this was my exact intention, but I wanted some more powerful Markdown, so considering either pandoc or pilar...

Best,
Marcel

Am 18.05.2020 23:47:38 schrieb Vanessa Freudenberg <[hidden email]>:

On Mon, May 18, 2020 at 12:56 PM Nicolas Cellier <[hidden email]> wrote:
Hi all,
I started to write a documentation of FFI implementation two or three months ago, I don't remember exactly, it's an eternity. The lock down did not give me an opportunity to continue. I want to publish with some liberal CC license, but I don't have chosen a support format yet. On one side, I wanted to focus on contents more than on the format. But on the other side, I want some graphical illustrations accurate enough. I wrote in Word because it was easy for me to include tables and graphics, but it's kinda stupid, especially because Word make you focus on format more than contents ! LaTeX is not general enough, it would rather be a backend nowadays. I contemplated using pandoc which has good support, or the much more limited Pilar, which at least is Smalltalk based...
The structure is not well established and the work is very preliminary, but since there is some demand, I give a pdf copy here as is, I hope it's not too big for the list. This probably should better be continued as a collaborative work anyway.

Awesome!

- Vanessa - 



Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

marcel.taeumel
Hi Nicolas.

I wanted some more powerful Markdown

Which features do you have in mind? Maybe start with GitHub Markdown and migrate later if necessary?

Best,
Marcel

Am 19.05.2020 09:30:23 schrieb Nicolas Cellier <[hidden email]>:



Le mar. 19 mai 2020 à 08:15, Marcel Taeumel <[hidden email]> a écrit :
How does UFFI come here?

I just wanted to backtrack those struct pointers lead to the accessor in Pharo. But it gave me no easy clue that I could apply to plain FFI in Squeak. :-)

I started to write a documentation of FFI implementation two or three months ago ...

Yeah! I will have a look at it. GitHub Markdown + embedded graphics also hosted on GitHub could work. And support pull requests. :-) Maybe put it into the osvm repository.

Hi Marcel,
this was my exact intention, but I wanted some more powerful Markdown, so considering either pandoc or pilar...

Best,
Marcel

Am 18.05.2020 23:47:38 schrieb Vanessa Freudenberg <[hidden email]>:

On Mon, May 18, 2020 at 12:56 PM Nicolas Cellier <[hidden email]> wrote:
Hi all,
I started to write a documentation of FFI implementation two or three months ago, I don't remember exactly, it's an eternity. The lock down did not give me an opportunity to continue. I want to publish with some liberal CC license, but I don't have chosen a support format yet. On one side, I wanted to focus on contents more than on the format. But on the other side, I want some graphical illustrations accurate enough. I wrote in Word because it was easy for me to include tables and graphics, but it's kinda stupid, especially because Word make you focus on format more than contents ! LaTeX is not general enough, it would rather be a backend nowadays. I contemplated using pandoc which has good support, or the much more limited Pilar, which at least is Smalltalk based...
The structure is not well established and the work is very preliminary, but since there is some demand, I give a pdf copy here as is, I hope it's not too big for the list. This probably should better be continued as a collaborative work anyway.

Awesome!

- Vanessa - 



Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Tobias Pape
In reply to this post by marcel.taeumel

> On 19.05.2020, at 08:46, Marcel Taeumel <[hidden email]> wrote:
>
> Hi Levente.
>
> >  Does MyStruct exist when you're writing this method?
>
> Yes.
>
> > If yes, is there a refence to that class in ExternalType's StructTypes class variable?
>
> Yes.
>
> **
>
> The issue was that I wanted to make a pointer to the struct I am currently (re-)defining:
>

> struct MyStruct {
>    MyStruct *foobar;
> };

If you have control over the source, try this:

typedef struct s_MyStruct MyStruct;
typedef MyStruct* pMyStruct;
struct s_MyStruct {
        pMyStruct *foobar;
};

-t


>
> Works fine when pointing to other structs. Should code generation work for this case? :-)
>
> Best,
> Marcel
>> Am 18.05.2020 21:28:49 schrieb Levente Uzonyi <[hidden email]>:
>>
>> Hi Marcel,
>>
>> On Mon, 18 May 2020, Marcel Taeumel wrote:
>>
>> > Hi, there!
>> >
>> > In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?
>> >
>> > First, non-pointer works as expected:
>> > ^ #( (other MyStruct) )
>> >
>> > Second, this just treats it as a void*, which returns a generic ExternalData:
>> > ^ #( (other 'MyStruct*') )
>>
>> This is how it should be written. Does MyStruct exist when you're writing
>> this method? If yes, is there a refence to that class in ExternalType's
>> StructTypes class variable?
>>
>> Levente
>>
>> >
>> > Third, this gives me a debugger:
>> > ^ #( (other MyStruct *) )
>> >
>> > :-)
>> >
>> > Best,
>> > Marcel
>> >
>> >
>>
>



Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

marcel.taeumel
If you have control over the source, try this:

Well, that recursive definition through pointers still valid in C, right? So it should be supported in Squeak's FFI. :-)

Best,
Marcel

Am 19.05.2020 09:52:57 schrieb Tobias Pape <[hidden email]>:


> On 19.05.2020, at 08:46, Marcel Taeumel wrote:
>
> Hi Levente.
>
> > Does MyStruct exist when you're writing this method?
>
> Yes.
>
> > If yes, is there a refence to that class in ExternalType's StructTypes class variable?
>
> Yes.
>
> **
>
> The issue was that I wanted to make a pointer to the struct I am currently (re-)defining:
>

> struct MyStruct {
> MyStruct *foobar;
> };

If you have control over the source, try this:

typedef struct s_MyStruct MyStruct;
typedef MyStruct* pMyStruct;
struct s_MyStruct {
pMyStruct *foobar;
};

-t


>
> Works fine when pointing to other structs. Should code generation work for this case? :-)
>
> Best,
> Marcel
>> Am 18.05.2020 21:28:49 schrieb Levente Uzonyi :
>>
>> Hi Marcel,
>>
>> On Mon, 18 May 2020, Marcel Taeumel wrote:
>>
>> > Hi, there!
>> >
>> > In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?
>> >
>> > First, non-pointer works as expected:
>> > ^ #( (other MyStruct) )
>> >
>> > Second, this just treats it as a void*, which returns a generic ExternalData:
>> > ^ #( (other 'MyStruct*') )
>>
>> This is how it should be written. Does MyStruct exist when you're writing
>> this method? If yes, is there a refence to that class in ExternalType's
>> StructTypes class variable?
>>
>> Levente
>>
>> >
>> > Third, this gives me a debugger:
>> > ^ #( (other MyStruct *) )
>> >
>> > :-)
>> >
>> > Best,
>> > Marcel
>> >
>> >
>>
>





Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Tobias Pape

> On 19.05.2020, at 10:24, Marcel Taeumel <[hidden email]> wrote:
>
> > If you have control over the source, try this:
>
> Well, that recursive definition through pointers still valid in C, right? So it should be supported in Squeak's FFI. :-)

only if you name it struct tho…

% c99 -o ms.o -c ms.c
ms.c:2:2: error: must use 'struct' tag to refer to type 'MyStruct'
 MyStruct *foobar;
 ^
 struct

;P


But actually, yes, you're right.
But are you sure about the thing 'mystruct' is? I assume   #( (other 'struct MyStruct*') ) is nothing FFI is fond of, is it?

Best regards
        -Tobias

>
> Best,
> Marcel
>> Am 19.05.2020 09:52:57 schrieb Tobias Pape <[hidden email]>:
>>
>>
>> > On 19.05.2020, at 08:46, Marcel Taeumel wrote:
>> >
>> > Hi Levente.
>> >
>> > > Does MyStruct exist when you're writing this method?
>> >
>> > Yes.
>> >
>> > > If yes, is there a refence to that class in ExternalType's StructTypes class variable?
>> >
>> > Yes.
>> >
>> > **
>> >
>> > The issue was that I wanted to make a pointer to the struct I am currently (re-)defining:
>> >
>>
>> > struct MyStruct {
>> > MyStruct *foobar;
>> > };
>>
>> If you have control over the source, try this:
>>
>> typedef struct s_MyStruct MyStruct;
>> typedef MyStruct* pMyStruct;
>> struct s_MyStruct {
>> pMyStruct *foobar;
>> };
>>
>> -t
>>
>>
>> >
>> > Works fine when pointing to other structs. Should code generation work for this case? :-)
>> >
>> > Best,
>> > Marcel
>> >> Am 18.05.2020 21:28:49 schrieb Levente Uzonyi :
>> >>
>> >> Hi Marcel,
>> >>
>> >> On Mon, 18 May 2020, Marcel Taeumel wrote:
>> >>
>> >> > Hi, there!
>> >> >
>> >> > In the #fields method of a new ExternalStructure, how can I express a pointer to another external structure?
>> >> >
>> >> > First, non-pointer works as expected:
>> >> > ^ #( (other MyStruct) )
>> >> >
>> >> > Second, this just treats it as a void*, which returns a generic ExternalData:
>> >> > ^ #( (other 'MyStruct*') )
>> >>
>> >> This is how it should be written. Does MyStruct exist when you're writing
>> >> this method? If yes, is there a refence to that class in ExternalType's
>> >> StructTypes class variable?
>> >>
>> >> Levente
>> >>
>> >> >
>> >> > Third, this gives me a debugger:
>> >> > ^ #( (other MyStruct *) )
>> >> >
>> >> > :-)
>> >> >
>> >> > Best,
>> >> > Marcel
>> >> >
>> >> >
>> >>
>> >
>>
>>
>>
>



Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to declare pointer to external structure in #fields?

Ben Coman
In reply to this post by Levente Uzonyi
On Tue, 19 May 2020 at 03:33, Levente Uzonyi <[hidden email]> wrote:
How does UFFI come here? AFAIK it's nothing but a different image-side
code using the VM's FFI implementation along with the signature notion
Igor used in NativeBoost (which is great btw because it's "as you would
write it in C" and doesn't require language changes).

Think of UFFI as a front-end for original-FFI.  IIUC although Igor's NativeBoost was a super fast alternative FFI, 
it wasn't portable and wasn't compatible with Spur, so Pharo had to throw NativeBoost away.  
But they kept the nice signature style as a layer over FFI.

Ronie wrote a paper on the reasons for UFFI in Pharo...

Here is a shorter presentation...


I never used FFI before UFFI, but I find UFFI very friendly to use.

I believe Ronie's Lowcode was designed to be another backend for UFFI, but I don't know the status of state.

cheers -ben


12