<html><head></head><body>This sounds like a bug. Could you open a ticket, ideally with a fairly standalone reproducer? <br><br>Cheer,<br><br>- Ben<br><br><div class="gmail_quote">On March 25, 2023 6:49:09 PM EDT, Dominick Samperi <djsamperi@gmail.com> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div dir="ltr">Hello,<div>FFI code that used to work now fails under Windows (still seems to work</div><div>under Ubuntu), and I wonder if anybody has seen anything like this and</div><div>can provide some pointers...</div><div><br></div><div>The code uses FFI to fetch information from the R side like R_NilValue,</div><div>using something like this;</div><div><br></div><div>-- Fetch R's R_NilValue...<br>foreign import ccall unsafe "&R_NilValue" r_NilValue_ptr :: Ptr R_EXP<br>r_NilValue :: IO R_EXP<br>r_NilValue = peek r_NilValue_ptr<br>rNilValue1 :: IO REXP<br>rNilValue1 = do</div><div> x <- r_NilValue</div><div> traceShow("addr=",x) extREXP x</div><div><br></div><div>Under Windows the address displayed is obviously bad, and this causes</div><div>the app to crash. This does not happen under Linux (Ubuntu).</div><div><br></div><div>Now, replace the line containing peek with</div><div><br></div><div>r_NilValue = trace "PEEK" peek r_NilValue_ptr</div><div><br></div><div>The address is now valid! It seems that adding the trace "PEEK" adds</div><div>some delay and somehow resolves the problem.</div><div><br></div><div>This problem is intermittent, so it is hard to come up with a</div><div>simple example that fails every time.</div><div><br></div><div>A little background: R_NilValue is a pointer to a SEXP that is not</div><div>initialized until an embedded instance of R is initialized, and the</div><div>code above is not triggered until this happens. Perhaps there is</div><div>a race condition between the time R initializes itself and Haskell</div><div>performs the peek? I don't think R_NilValue is garbage collected</div><div>once initialized.</div><div><br></div><div>Any tips would be appreciated.</div><div>Dominick</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>
</blockquote></div></body></html>