<div dir="ltr"><br><br><div class="gmail_quote">On Mon, Sep 22, 2008 at 6:19 AM, Igor Stasenko <span dir="ltr"><<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="Wj3C7c">2008/9/22 Gerardo Richarte <<a href="mailto:gera@corest.com">gera@corest.com</a>>:<br>
> Igor Stasenko wrote:<br>
>> 2008/9/22 Gerardo Richarte <<a href="mailto:gera@corest.com">gera@corest.com</a>>:<br>
>><br>
>>> There's a native function I need to call (I called it 'aPrintf' in<br>
>>> the code below) with a specific calling convention:<br>
>>><br>
>> I wondering , why you prefer using string formatting in C, while in<br>
>> smalltalk you have own? You can easily format strings in smalltalk,<br>
>> and print only the resulting string w/o need in inventing safe schemes<br>
>> or conversion.<br>
>><br>
> Hi Igor, nice to see you again!<br>
><br>
> I knew this was going to happen :)<br>
><br>
> It was just an example, I'm not using string formatting. The actual<br>
> function I'm calling is the callout interface for OpenFirmware, through<br>
> which OpenFirmware provides services to the booted operating<br>
> system. Pretty much like BIOS' INT mechanism, but much more<br>
> powerful.<br>
><br>
<br>
</div></div>Okay. Then i don't see any problems with this primitive, except maybe one thing:<br>
<br>
a primitive should never change the contents of any argument(s). As in<br>
general smalltalk methods, a primitive should be allowed to change the<br>
contents only of receiver object, otherwise its breaking a smalltalk<br>
encapsulation rules.<br>
I would advice you to allocate separate byte array and fill it with<br>
values, then pass to C routine. Since its a byte array you don't need<br>
to care about it contents, and don't need a cleanup (GC will collect<br>
it as garbage eventually).</blockquote><div><br></div><div>No need to use a Smalltalk object to hold the copy. Just use alloca (stack allocating version of malloc).</div><div><br></div><div>But this is the kind of thing an FFI does during marshalling anyway. Gerardo, why can't you use the FFI?</div>
</div></div>