[Vm-dev] [Pharo-users] UFFI C basic types passed-by-reference for output
Ben Coman
btc at openinworld.com
Thu Nov 16 12:51:06 UTC 2017
On 15 November 2017 at 20:47, Esteban Lorenzano <estebanlm at gmail.com> wrote:
> On 15 Nov 2017, at 09:36, Ben Coman <btc at openInWorld.com> wrote:
>
> On 15 November 2017 at 17:27, Esteban Lorenzano <estebanlm at gmail.com>
> wrote:
>
>>
>>
>> > On 15 Nov 2017, at 02:05, Ben Coman <btc at openInWorld.com> wrote:
>> >
>> > What is the recommended way for a C basic type to be
>> passed-by-reference to function wanting to use it for output.
>> > For example 'width' & 'height' here in this library unction...
>> >
>> > In Pharo...
>> >
>> > FFIOpaqueObject subclass: #FPDF_DOCUMENT
>> >
>> > FPDF_GetPageSizeByIndex__document: document
>> > page_index: page_index
>> > width: width
>> > height: height
>> > ^self ffiCall: #(int FPDF_GetPageSizeByIndex(
>> > FPDF_DOCUMENT *document,
>> > int page_index,
>> > FFIFloat64 * width,
>> > FFIFloat64 * height))
>>
>> what you need to do here is to pass a “buffer” to contain the width and
>> height:
>>
>> testGetPageSizeByIndex
>> | document page_index widthBuffer heightBuffer width height
>> result|
>> PDFium FPDF_InitLibrary.
>> document := PDFium FPDF_LoadDocument__file_path: helloPdf
>> password: ''.
>> widthBuffer := ByteArray new: (FFIFloat64 typeSize).
>> heightBuffer := ByteArray new: (FFIFloat64 typeSize).
>>
>
> Thanks Esteban. That worked. However I needed a minor tweak...
> widthBuffer := ByteArray new: (FFIFloat64 new typeSize).
> or...
> widthBuffer := ByteArray new: (FFIFloat64 externalTypeSize).
>
>
> Now it would be nice to do...
> widthBuffer := FFIFloat64 newBuffer.
>
>
> you know, I thought the same :)
> but since I’m officially on holiday I didn’t do it (yet).
>
> If you want to add an issue and send a PR, it would be perfect :)
>
https://pharo.fogbugz.com/f/cases/20699/
btw, how do we write tests for FFI? Do we (or can we) deliver as part of
standard opensmalltalk-vm
a small shared library "libFFITestFrame.so" to write ffi tests against? With
functions like...
void passByRefOutputs(int *p_int, double *p_double) {
*p_int = 42;
*p_double = 4.2;
}
cheers -ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20171116/af620a0b/attachment.html>
More information about the Vm-dev
mailing list