chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] location and c-string*


From: Zbigniew
Subject: [Chicken-users] location and c-string*
Date: Sat, 11 Aug 2007 17:31:19 -0500

Hi, just want to make sure this code is legal.  I have a C function
which allocates a string and returns it via one of its arguments,
expecting the caller to free it.  The following code works as
expected, but I want to make sure it is valid.

(let-location ((out c-string*))
  (let ((rv (my-func "Lambda.OrG" #$out "Nameprep" 0)))
    (let ((out out))           ; free out once
      (if (eqv? rv 0)
          (print out)
          (error "profile error" rv)))))

The issue is that ##sys#peek-and-free-c-string will be called every
time "out" is referenced.    To guarantee "out" is freed exactly once,
I immediately rebind out to itself after the call.  Is this a valid
recipe?

Zb




reply via email to

[Prev in Thread] Current Thread [Next in Thread]