<div dir="auto"><div>Hi,<div dir="auto"><br></div><div dir="auto">I'm missing some details here here as I'm having trouble following the flow. </div><div dir="auto"><br></div><div dir="auto">What provides the symbol for that import? As in where does R_NilValue come from? As in, how is it defined. Are you linking against a library or C sources?</div><div dir="auto"><br></div><div dir="auto">When you say you replace the trace statement, do you keep the x <- r_NilValue?</div><div dir="auto"><br></div><div dir="auto">The address to R_NilValue should never change during initialization so I'm more suspicious of how it's declared. Unless you're linking to a symbol in a shared library, in which case that could be possible due to ASLR. </div><div dir="auto"><br></div><div dir="auto">Kind regards, </div><div dir="auto">Tamar </div><div dir="auto"><br><div data-smartmail="gmail_signature" dir="auto">Sent from my Mobile</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 26, 2023, 14:15 Dominick Samperi <<a href="mailto:djsamperi@gmail.com">djsamperi@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks Ben, I'll see what I can do to reliably reproduce and open a ticket.<div><br></div><div>One theory I'm investigating is that this might have something to do</div><div>with my anti-virus software (AVG), since it sometimes interacts with</div><div>Windows in strange ways (for example, an extra instance of a terminal app pops up, then disappears after a few seconds). But disabling this software does not seem to solve the problem.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 25, 2023 at 11:18 PM Ben Gamari <<a href="mailto:ben@smart-cactus.org" target="_blank" rel="noreferrer">ben@smart-cactus.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>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 <<a href="mailto:djsamperi@gmail.com" target="_blank" rel="noreferrer">djsamperi@gmail.com</a>> 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></div></blockquote></div>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank" rel="noreferrer">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div></div></div>