<div dir="ltr"><br><br><div class="gmail_quote">On Mon, Sep 22, 2008 at 6:19 AM, Igor Stasenko <span dir="ltr">&lt;<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>&gt;</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 &lt;<a href="mailto:gera@corest.com">gera@corest.com</a>&gt;:<br>
&gt; Igor Stasenko wrote:<br>
&gt;&gt; 2008/9/22 Gerardo Richarte &lt;<a href="mailto:gera@corest.com">gera@corest.com</a>&gt;:<br>
&gt;&gt;<br>
&gt;&gt;&gt; &nbsp; &nbsp;There&#39;s a native function I need to call (I called it &#39;aPrintf&#39; in<br>
&gt;&gt;&gt; the code below) with a specific calling convention:<br>
&gt;&gt;&gt;<br>
&gt;&gt; I wondering , why you prefer using string formatting in C, while in<br>
&gt;&gt; smalltalk you have own? You can easily format strings in smalltalk,<br>
&gt;&gt; and print only the resulting string w/o need in inventing safe schemes<br>
&gt;&gt; or conversion.<br>
&gt;&gt;<br>
&gt; Hi Igor, nice to see you again!<br>
&gt;<br>
&gt; I knew this was going to happen :)<br>
&gt;<br>
&gt; It was just an example, I&#39;m not using string formatting. The actual<br>
&gt; function I&#39;m calling is the callout interface for OpenFirmware, through<br>
&gt; which OpenFirmware provides services to the booted operating<br>
&gt; system. Pretty much like BIOS&#39; INT mechanism, but much more<br>
&gt; powerful.<br>
&gt;<br>
<br>
</div></div>Okay. Then i don&#39;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&#39;t need<br>
to care about it contents, and don&#39;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. &nbsp;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. &nbsp;Gerardo, why can&#39;t you use the FFI?</div>
</div></div>