Support for returning external structures in NativeBoost

classic Classic list List threaded Threaded
3 messages Options
melkyades melkyades
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Support for returning external structures in NativeBoost

I have this wrapper:

chooseVisual: display screen: aScreenNumber attributes: attribList
<primitive: #primitiveNativeCall module: #NativeBoostPlugin>

^ self call: #( NBXLibVisualInfo* glXChooseVisual ( NBXLibDisplay display , int aScreenNumber, int *attribList ) )

but when generating native code it ends in:

ExternalStructureType>>coerceReturn: gen

" ... should we support handling return of external structures? "
self error: 'returning pointer to structure?'


Changing "NBXLibVisualInfo*" to "NBXLibVisualInfo" didn't help. Is there any workaround??



--
Lic. Javier Pimás
Ciudad de Buenos Aires
Igor Stasenko Igor Stasenko
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Support for returning external structures in NativeBoost

On 10 February 2012 13:14, Javier Pimás <[hidden email]> wrote:

> I have this wrapper:
>
> chooseVisual: display screen: aScreenNumber attributes: attribList
> <primitive: #primitiveNativeCall module: #NativeBoostPlugin>
>
> ^ self call: #( NBXLibVisualInfo* glXChooseVisual ( NBXLibDisplay display ,
> int aScreenNumber, int *attribList ) )
>
> but when generating native code it ends in:
>
> ExternalStructureType>>coerceReturn: gen
>
> " ... should we support handling return of external structures? "
> self error: 'returning pointer to structure?'
>
>
> Changing "NBXLibVisualInfo*" to "NBXLibVisualInfo" didn't help. Is there any
> workaround??
>

Yes. Change the return type to void* :)
And then do as i showed before: load the struct fields from that
pointer in your code.

info := NBXLibVisualInfo fromPointer: (self chooseVisual: display
screen: aScreenNumber attributes: attribList)

Because how you would implement it? It maybe a pointer to single
structure or pointer to an array of structures..
Because in C a pointer can be a pointer to a single value, or pointer
to multiple values and you cannot make a difference.

--
Best regards,
Igor Stasenko.

Igor Stasenko Igor Stasenko
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Support for returning external structures in NativeBoost

On 10 February 2012 15:55, Igor Stasenko <[hidden email]> wrote:

> On 10 February 2012 13:14, Javier Pimás <[hidden email]> wrote:
>> I have this wrapper:
>>
>> chooseVisual: display screen: aScreenNumber attributes: attribList
>> <primitive: #primitiveNativeCall module: #NativeBoostPlugin>
>>
>> ^ self call: #( NBXLibVisualInfo* glXChooseVisual ( NBXLibDisplay display ,
>> int aScreenNumber, int *attribList ) )
>>
>> but when generating native code it ends in:
>>
>> ExternalStructureType>>coerceReturn: gen
>>
>> " ... should we support handling return of external structures? "
>> self error: 'returning pointer to structure?'
>>
>>
>> Changing "NBXLibVisualInfo*" to "NBXLibVisualInfo" didn't help. Is there any
>> workaround??
>>
>
> Yes. Change the return type to void* :)
> And then do as i showed before: load the struct fields from that
> pointer in your code.
>
> info := NBXLibVisualInfo fromPointer: (self chooseVisual: display
> screen: aScreenNumber attributes: attribList)
>
> Because how you would implement it? It maybe a pointer to single
> structure or pointer to an array of structures..
> Because in C a pointer can be a pointer to a single value, or pointer
> to multiple values and you cannot make a difference.
>

and of course it is a good excuse for not implementing structs which
accessing data indirectly (via pointer to some memory),
instead of holding fields data in bytearray  :)

Though, it is easy to implement. So if you really can't live without
it, i can add it.

--
Best regards,
Igor Stasenko.

Loading...