<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le lun. 22 juin 2020 à 10:30, Marcel Taeumel <<a href="mailto:marcel.taeumel@hpi.de">marcel.taeumel@hpi.de</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id="gmail-m_819012628946558009__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)">
                                        
                                        
                                            
                                        
                                        
                                        Hi Nicolas,<div><br></div><div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">> I'd like to simply write (MyStruct new: 25) to get an array of 25 MyStruct.</div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">> I DO NOT want to see the ExternalData, it's an implementation detail blurring the intentions.</div></div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">Then you would just hide what I just proposed behind #new: in your struct. :-) I just argued to not put </div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">#allocate: in ExternalType.</div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">However, you want to treat MyStruct to be able to answer an array of itself. This is not okay. Well, it might be C-style, but not Smalltalk-style. We should try to find a connection between C-world and Smalltalk-world. Would you do that with "Morph new: 25"? Expect an array of 25 morphs?</div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">If you want to have an array, ExternalData is the closes we have at the moment. It can directly work like Collection.</div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">So, #new: (or similar) is a thing you want to implement in ExternalData, not MyStruct.</div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">Well ... if you insist on creating an array of MyStruct through MyStruct .... I would at least not use #new: but rather #newArray: ... </div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div></div></blockquote><div><br></div><div><div>In your mind, ExternalData <=> Array.</div><div>(Array of: MyStruct) new: 10 <=> (ExternalData type: MyStruct) new: 10.<div>That's what you tend toward: add some of Collection protocol to ExternalData.</div></div><div><br></div><div>If you have a look at Smallapack ExternalArray, that's somehow what I tried to achieve years ago...<br></div><div>have Collection protocol for arrays external objects.</div></div><div><br></div><div>My POV is different.</div><div>We're interfacing C.<div>In C, I can simply have MyStruct foo; or MyStruct foo[10];</div><div>So direct manipulation of MyStruct without any intermediary is much more appealing/convenient.<br></div><div><br></div>ExternalData? The name does not speak as Collection.</div><div>In fact it's a hurdle. It's verbiage. It's too low level, like all the external*</div><div>I do not see the ExternalFunction, can live without EternalAddress, etc...<br></div><div>I do not want to manipulate ExternalData by myself. I do not want to see it.<br></div><div>I do not want to have to tell an ExternalData to create an array of the type I need for myself.</div><div>I do want to handle my domain objects DIRECTLY, without intermediary (or at least have the illusion of).</div><div>See it?<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id="gmail-m_819012628946558009__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)"><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px"></div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">> I want to see/handle my domain specific "objects" DIRECTLY.</div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">Sure. But having an array of your domain specific objects is handled via ExternalData. ExternalData is like Collection (or Array).</div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">Best,</div><div style="font-family:Arial,Helvetica,sans-serif;font-size:13px">Marcel</div><div></div>
                                        
                                        <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-top:20px;margin-left:0px;padding-left:10px;min-width:500px">
                        <p style="color:rgb(170,170,170);margin-top:10px">Am 22.06.2020 10:21:23 schrieb Nicolas Cellier <<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmail.com</a>>:</p><div style="font-family:Arial,Helvetica,sans-serif">
<div dir="ltr"><div>Hi Marcel,</div><div>The idea is to manipulate the alias or structures types as if they were classes.</div><div><br></div><div>I already can write MyStruct new, and pass that to an external function call.</div><div>I'd like to simply write (MyStruct new: 25) to get an array of 25 MyStruct.</div><div>I DO NOT want to see the ExternalData, it's an implementation detail blurring the intentions.<br></div><div>I want to see/handle my domain specific "objects" DIRECTLY.</div><div>That's what I manipulate in function signatures, etc...</div><div><br></div><div>Since external types are not exactly classes, i prefer to have another vocabulary in place of new:.</div><div>In VW DLLCC, the selectors malloc malloc: calloc calloc: gcMalloc gcMalloc: are sent to the CType.</div><div><br></div><div>Unlike us, DLLCC does not allocate in objectMemory, always on the heap.</div><div>So having the C vocabulary is logical for them.<br></div><div>Allocating in ObjectMemory is one essential feature of Squeak FFI.</div><div><div>That's why I prefer not use C vocabulary.</div><div>#allocate: is something in between.</div><div>I know that it is already used on the low level for ExternalAddress, which is unfortunate.<br></div></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le lun. 22 juin 2020 à 09:31, Marcel Taeumel <<a href="mailto:marcel.taeumel@hpi.de" target="_blank">marcel.taeumel@hpi.de</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;min-width:500px"><div id="gmail-m_819012628946558009gmail-m_1179877851132068488__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)">
                                        
                                        
                                            
                                        
                                        
                                        Hi Nicolas.<div><br></div><div>I like the idea of having #allocate: ... but maybe not in ExternalType:</div><div><br></div><div>- The term "allocate:" is somewhat reserved for heap memory from the SqueakFFI perspective; See ExternalAddress class >> #allocate:.</div><div>- The counterpart #free is missing ... which means that, maybe, both #allocate: and #free should be implemented in ExternalData, not ExternalType<br><br></div><div>What about such a this programming interface:</div><div><br></div><div>data := ExternalData</div><div>   fromHandle: nil</div><div>   type: MyStruct externalType asPointerType.</div><div>data allocate.</div><div>myStruct := data asExternalStructure.</div><div><br></div><div>You could also copy it back to object memory:</div><div><br></div><div>myStruct := data getExternalStructure. "get/pull/fetch ...."</div><div>data free.</div><div><br></div><div>You are proposing a way to start off in object memory. Maybe like this:</div><div><br></div><div><div>data := ExternalData</div><div>   fromHandle: nil "maybe optional?"</div><div>   type: MyStruct externalType asPointerType.</div><div>data allocateLocal.</div><div>myStruct := data asExternalStructure.</div><div><br style="font-size:13.3333px"></div></div><div>Then we don't need to call #free. See how #allocate and #allocateLocal in ExternalData could mirror #new and #externalNew of ExternalStructure?</div><div><br></div><div>There is really an interesting releationship between ExternalStructure (incl. ExternalUnion/ExternalTypeAlias/ExternalPackedStructure) and ExternalData. Can you see it? ^__^</div><div><br></div><div>Arrays could be similar:</div><div><br></div><div>data := ExternalData type: Externaltype int32_t asPointerType.</div><div>data size: 20.</div><div>data allocate. "or #allocateLocal"</div><div><br></div><div>Now you would have an array of 20 integers. :-) Note that #allocate: with argument could inline that #size: call.</div><div><br></div><div>Best,</div><div>Marcel</div><div></div>
                                        
                                        <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-top:20px;margin-left:0px;padding-left:10px;min-width:500px">
                        <p style="color:rgb(170,170,170);margin-top:10px">Am 21.06.2020 13:20:44 schrieb <a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a> <<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>>:</p><div style="font-family:Arial,Helvetica,sans-serif">Nicolas Cellier uploaded a new version of FFI-Kernel to project FFI:<br><a href="http://source.squeak.org/FFI/FFI-Kernel-nice.118.mcz" target="_blank">http://source.squeak.org/FFI/FFI-Kernel-nice.118.mcz</a><br><br>==================== Summary ====================<br><br>Name: FFI-Kernel-nice.118<br>Author: nice<br>Time: 21 June 2020, 1:20:34.369348 pm<br>UUID: a8c48997-991d-4e32-9b67-6d93fc0dabe0<br>Ancestors: FFI-Kernel-mt.117<br><br>Add the ability to allocate: an ExternalType or an ExternalStructure/Alias.<br><br>It's equivalent to new: but we want a specific idiom, C types are not exactly classes.<br><br>Add the ability to compare aliases (at least for equality)<br><br>=============== Diff against FFI-Kernel-mt.117 ===============<br><br>Item was added:<br>+ ----- Method: ExternalStructure class>>allocate: (in category 'instance creation') -----<br>+ allocate: anInteger<br>+     "Create an ExternalData with enough room for storing an array of size anInteger of such structure"<br>+         ^self externalType allocate: anInteger!<br><br>Item was added:<br>+ ----- Method: ExternalType>>allocate: (in category 'external data') -----<br>+ allocate: anInteger<br>+         "Allocate space for containing an array of size anInteger of this dataType"<br>+        <br>+     | handle |<br>+   handle := ByteArray new: self byteSize * anInteger.<br>+  ^(ExternalData fromHandle: handle type: self) size: anInteger!<br><br>Item was added:<br>+ ----- Method: ExternalTypeAlias>>= (in category 'comparing') -----<br>+ = anExternalTypeAlias<br>+       ^self class = anExternalTypeAlias class and: [self value = anExternalTypeAlias value]!<br><br>Item was added:<br>+ ----- Method: ExternalTypeAlias>>hash (in category 'comparing') -----<br>+ hash<br>+     ^self class hash hashMultiply bitXor: self value hash!<br><br><br></div></blockquote></div><br>
</blockquote></div>
</div></blockquote></div><br>
</blockquote></div></div>