<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Jun 15, 2013 at 1:55 PM, Roman Klochkov <span dir="ltr"><<a href="mailto:kalimehtar@mail.ru" target="_blank">kalimehtar@mail.ru</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>What aboutš<br><br>(define-lib foo (fun _string -> _void))<br><br>(foo "Test")<br><br>?<br><br>Will be the pointer from string "Test" freed?</div></blockquote><div><br></div><div>I *think* Racket will garbage collect the "Test" value when it is not used anymore on the Racket side, but it won't know what happens on the ffi C side (hence the "ffi/unsafe").<br>
</div><div>So I think the lib may point to a freed value if you're not cautious.<br></div><div>š</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>And how to make it retain, if I need to save it on the foreign side?<br></div></blockquote><div><br></div><div>You can probably at least simply store it in a global variable. There may be a better way to do it though.<br>
</div><div>For example (not tested) :<br>#lang racket<br>(define dontfreethem '())<br>(define (dontfreeme x)<br>š (set! dontfreethem (cons x dontfreethem))<br>š x)<br><br>(foo (dontfreeme "Test"))<br><br></div>
<div>Laurent<br></div><br></div></div></div>