<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div style="" class=""><span style="" class="">I noticed a parentheses was missing is this right</span></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""><span style="" class=""></span></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br style="" class=""><br style="" class=""> (defmethod translate-to-foreign ((lisp-value cv-matrix) (c-type cv-mat))<br style="" class="">    (values  (c-pointer lisp-value) lisp-value))</div><div class="" style="color:
 rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal"><br></div><div class="" style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;
 background-color: transparent; font-style: normal"><br></div><div style="display: block;" class="yahoo_quoted"> <div class="" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 10pt"> <div class="" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt"> <div style="" class="" dir="ltr"> <font style="" class="" face="Arial" size="2"> On Monday, April 28, 2014 10:20 PM, Willem Rein Oudshoorn <woudshoo@xs4all.nl> wrote:<br style="" class=""> </font> </div> <blockquote class="" style="">  <div style="" class="">Martin Simmons <<a style="" class="" ymailto="mailto:martin@lispworks.com" href="mailto:martin@lispworks.com">martin@lispworks.com</a>> writes:<br style="" class=""><br style="" class="">>>>>>> On Mon, 28 Apr 2014 07:26:07 +0200, Willem Rein Oudshoorn said:<br style="" class="">>> Cancel-Lock:
 sha1:zqpk08tO/PaCrz3PLTlI+ocAF9E=<br style="" class="">>> <br style="" class="">>> Joeish W <<a style="" class="" ymailto="mailto:joeish80829@yahoo.com" href="mailto:joeish80829@yahoo.com">joeish80829@yahoo.com</a>> writes:<br style="" class="">>> <br style="" class="">>> > How do I work with the metaobjects(is that what they are called)<br style="" class="">>> > output by the code you gave me...If you can show me how to mem-aref<br style="" class="">>> > one I would really appreciate it<br style="" class="">>> <br style="" class="">>> Sorry for the short answer, but at the moment I am extremely busy.<br style="" class="">>> If you followed the example<br style="" class="">>> <br style="" class="">>>  (mem-aref (c-pointer YOUR-POINT) ...)<br style="" class="">>> <br style="" class="">>> should work.<br style="" class="">><br style="" class="">> It
 might be interesting (or scary depending on your point of view) to consider<br style="" class="">> what happens if the variable YOUR-POINT is the last reference to the CLOS<br style="" class="">> object here...the finalizer might free the foreign object before mem-aref is<br style="" class="">> entered if the compiler no longer keeps a pointer to the variable.<br style="" class="">><br style="" class="">No this is not safe.  In general you should never do <br style="" class="">`(c-pointer ...)` outside the low level parts of the bindings, and use<br style="" class="">it very carefully.<br style="" class=""><br style="" class="">Personally I would try to never use the `c-pointer` method outside<br style="" class="">the `translate-to-foreign` code.   And I naively expected that this<br style="" class="">would be safe.   But as you point out:<br style="" class=""><br style="" class="">> Or more specifically, can this ever be
 safe?<br style="" class="">><br style="" class="">> (mem-aref (c-pointer (point0)) ...)<br style="" class=""><br style="" class="">This is never safe.<br style="" class=""><br style="" class="">I think the easiest fix is to change the <br style="" class=""><br style="" class="">  (defmethod translate-to-foreign ((lisp-value cv-matrix) (c-type cv-mat))<br style="" class="">    (c-pointer lisp-value))<br style="" class=""><br style="" class="">code to  [UNTESTED CODE]:<br style="" class=""><br style="" class=""><br style="" class="">  (defmethod translate-to-foreign ((lisp-value cv-matrix) (c-type cv-mat))<br style="" class="">    (values  (c-pointer lisp-value) lisp-value)<br style="" class=""><br style="" class=""><br style="" class="">This should keep the lisp-value around until we are done using the<br style="" class="">`(c-pointer ...)` value.   Provided of course you are not mucking around<br
 style="" class="">with the `c-pointer` method yourself.<br style="" class=""><br style="" class=""><br style="" class="">In general, I would advocate to hide all the nasty c-pointer business in<br style="" class="">the translate methods and never deal with it outside that limited scope.<br style="" class=""><br style="" class=""><br style="" class="">Thank you for bringing this to my attention.  I do think we need a paper<br style="" class="">or section in the manual on how to deal with combing GC in Lisp and<br style="" class="">manual memory management on the C side.  <br style="" class=""><br style="" class="">When my time frees up (hopefully in a month or two)  I might take a stab <br style="" class="">at a first draft.<br style="" class=""><br style="" class="">Kind regards,<br style="" class="">Wim Oudshoorn.<br style="" class=""><br style="" class=""><br style="" class="">_______________________________________________<br style=""
 class="">Cffi-devel mailing list<br style="" class=""><a style="" class="" ymailto="mailto:Cffi-devel@common-lisp.net" href="mailto:Cffi-devel@common-lisp.net">Cffi-devel@common-lisp.net</a><br style="" class=""><a style="" class="" href="http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel" target="_blank">http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel</a><br style="" class=""><br style="" class=""><br style="" class=""></div> </blockquote>  </div> </div>   </div> </div></body></html>