<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 15 November 2017 at 20:47, Esteban Lorenzano <span dir="ltr"><<a href="mailto:estebanlm@gmail.com" target="_blank">estebanlm@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div><div class="gmail-h5"><blockquote type="cite"><div>On 15 Nov 2017, at 09:36, Ben Coman <<a href="mailto:btc@openInWorld.com" target="_blank">btc@openInWorld.com</a>> wrote:</div><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div class="gmail_extra" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_quote">On 15 November 2017 at 17:27, Esteban Lorenzano<span class="gmail-m_6233470791552793093Apple-converted-space"> </span><span dir="ltr"><<a href="mailto:estebanlm@gmail.com" target="_blank">estebanlm@gmail.com</a><wbr>></span><span class="gmail-m_6233470791552793093Apple-converted-space"> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-m_6233470791552793093gmail-HOEnZb"><div class="gmail-m_6233470791552793093gmail-h5"><br><br>> On 15 Nov 2017, at 02:05, Ben Coman <<a href="mailto:btc@openInWorld.com" target="_blank">btc@openInWorld.com</a>> wrote:<br>><br>> What is the recommended way for a C basic type to be passed-by-reference to function wanting to use it for output.<br>> For example 'width' & 'height' here in this library unction...<br>><br>> In Pharo...<br>><br>>   FFIOpaqueObject subclass: #FPDF_DOCUMENT<br>><br>>   FPDF_GetPageSizeByIndex__docu<wbr>ment: document<br>>                           page_index: page_index<br>>                           width: width<br>>                           height: height<br>>     ^self ffiCall: #(int FPDF_GetPageSizeByIndex(<br>>                                               FPDF_DOCUMENT *document,<br>>                                               int page_index,<br>>                                               FFIFloat64 * width,<br>>                                               FFIFloat64 * height))<br><br></div></div>what you need to do here is to pass a “buffer” to contain the width and height:<br><br>testGetPageSizeByIndex<br>       <span class="gmail-m_6233470791552793093Apple-converted-space"> </span>| document page_index widthBuffer heightBuffer width height result|<br><span class="gmail-m_6233470791552793093gmail-">       <span class="gmail-m_6233470791552793093Apple-converted-space"> </span>PDFium FPDF_InitLibrary.<br>       <span class="gmail-m_6233470791552793093Apple-converted-space"> </span>document := PDFium FPDF_LoadDocument__file_path:  helloPdf  password: ''.<br></span>       <span class="gmail-m_6233470791552793093Apple-converted-space"> </span>widthBuffer := ByteArray new: (FFIFloat64 typeSize).<br>       <span class="gmail-m_6233470791552793093Apple-converted-space"> </span>heightBuffer := ByteArray new: (FFIFloat64 typeSize).<br></blockquote><div><br></div>Thanks Esteban. That worked. However I needed a minor tweak...<div>   widthBuffer := ByteArray new: (FFIFloat64 new typeSize).</div><div>or...</div><div>   widthBuffer := ByteArray new: (FFIFloat64 externalTypeSize).</div><div><br></div><div><br></div><div>Now it would be nice to do...</div><div>   widthBuffer := FFIFloat64 newBuffer.</div></div></div></div></blockquote><div><br></div></div></div><div>you know, I thought the same :)</div><div>but since I’m officially on holiday I didn’t do it (yet). </div><div><br></div><div>If you want to add an issue and send a PR, it would be perfect :)</div></div></div></blockquote><div><br></div><div><a href="https://pharo.fogbugz.com/f/cases/20699/">https://pharo.fogbugz.com/f/cases/20699/</a></div><div><br></div><div><br></div><div>btw, how do we write tests for FFI?    Do we (or can we) deliver as part of standard opensmalltalk-vm </div><div>a small shared library "libFFITestFrame.so" <span style="font-size:14px;color:rgb(68,68,68);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif">to write ffi tests against? </span>With functions like...</div><div><br></div><div><span style="color:rgb(68,68,68);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px">  void passByRefOutputs(int *p_int, double *p_double) {</span><br style="box-sizing:border-box;color:rgb(68,68,68);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px"><span style="color:rgb(68,68,68);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px">      *p_int = 42;</span><br style="box-sizing:border-box;color:rgb(68,68,68);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px"><span style="color:rgb(68,68,68);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px">      *p_double = 4.2;</span><br style="box-sizing:border-box;color:rgb(68,68,68);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px"><span style="color:rgb(68,68,68);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px">    }</span><br></div><div><span style="color:rgb(68,68,68);font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px"><br></span></div><div><br></div><div><font color="#444444" face="Helvetica Neue, Helvetica, Arial, sans-serif"><span style="font-size:14px">cheers -ben</span></font></div></div></div></div>