{"action":"created","issue":{"url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/4391","repository_url":"https://api.github.com/repos/idris-lang/Idris-dev","labels_url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/4391/labels{/name}","comments_url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/4391/comments","events_url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/4391/events","html_url":"https://github.com/idris-lang/Idris-dev/issues/4391","id":307686782,"number":4391,"title":"modifyIORef causes segmentation fault in FFI callback","user":{"login":"thalerjonathan","id":6533104,"avatar_url":"https://avatars2.githubusercontent.com/u/6533104?v=4","gravatar_id":"","url":"https://api.github.com/users/thalerjonathan","html_url":"https://github.com/thalerjonathan","followers_url":"https://api.github.com/users/thalerjonathan/followers","following_url":"https://api.github.com/users/thalerjonathan/following{/other_user}","gists_url":"https://api.github.com/users/thalerjonathan/gists{/gist_id}","starred_url":"https://api.github.com/users/thalerjonathan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thalerjonathan/subscriptions","organizations_url":"https://api.github.com/users/thalerjonathan/orgs","repos_url":"https://api.github.com/users/thalerjonathan/repos","events_url":"https://api.github.com/users/thalerjonathan/events{/privacy}","received_events_url":"https://api.github.com/users/thalerjonathan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-03-22T15:13:07Z","updated_at":"2018-03-27T14:16:40Z","closed_at":null,"author_association":"NONE","body":"# Steps to Reproduce\r\n```Idris\r\nimport Data.IORef\r\n\r\n%include C \"idris_clbks_test.h\"\r\n%link C \"idris_clbks_test.o\"\r\n\r\nTestCallback : Type\r\nTestCallback = Int -> ()\r\n\r\ntestCallbackPure : IORef Integer -> Int -> ()\r\ntestCallbackPure ref x = unsafePerformIO $ do \r\n  putStrLn \"before modifyIORef\"\r\n  modifyIORef ref (+1) -- segmentation fault occurs here\r\n  putStrLn \"after modifyIORef\"\r\n\r\ntestCallbackPurePtr : IORef Integer -> IO Ptr\r\ntestCallbackPurePtr ref\r\n  = foreign FFI_C \"%wrapper\" (CFnPtr TestCallback -> IO Ptr) (MkCFnPtr $ testCallbackPure ref)\r\n\r\nsetTestCallbackWithPtr : IORef Integer -> IO ()\r\nsetTestCallbackWithPtr ref = do\r\n  ptr <- testCallbackPurePtr ref\r\n  foreign FFI_C \"registerCallback\" (Ptr -> IO ()) ptr\r\n\r\nrunCallback : IO ()\r\nrunCallback = foreign FFI_C \"runCallback\" (IO ())\r\n\r\nexport\r\nrun : IO ()\r\nrun = do\r\n  ref <- newIORef 42\r\n  setTestCallbackWithPtr ref\r\n  runCallback\r\n  ret <- readIORef ref\r\n  putStrLn $ \"IORef = \" ++ show ret\r\n```\r\nNote that is is not possible to reproduce this problem with just this code, one needs the c files as well and compile the whole thing into an executable. For this purpose I created a repository which is available here https://github.com/thalerjonathan/idris-callbacks-tests. The relevant file for this problem is https://github.com/thalerjonathan/idris-callbacks-tests/blob/master/TestModifyIORef.idr\r\nTo compile this example run 'make' in the cloned folder. Make sure that in the Main.idr the TestModifyIORef.run function is called.\r\n\r\n# Expected Behavior\r\nProgram should not crash.\r\n\r\n# Observed Behavior\r\nProgram crashes with segmentation fault when modifyIORef is called.\r\n"},"comment":{"url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/comments/376541621","html_url":"https://github.com/idris-lang/Idris-dev/issues/4391#issuecomment-376541621","issue_url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/4391","id":376541621,"user":{"login":"thalerjonathan","id":6533104,"avatar_url":"https://avatars2.githubusercontent.com/u/6533104?v=4","gravatar_id":"","url":"https://api.github.com/users/thalerjonathan","html_url":"https://github.com/thalerjonathan","followers_url":"https://api.github.com/users/thalerjonathan/followers","following_url":"https://api.github.com/users/thalerjonathan/following{/other_user}","gists_url":"https://api.github.com/users/thalerjonathan/gists{/gist_id}","starred_url":"https://api.github.com/users/thalerjonathan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thalerjonathan/subscriptions","organizations_url":"https://api.github.com/users/thalerjonathan/orgs","repos_url":"https://api.github.com/users/thalerjonathan/repos","events_url":"https://api.github.com/users/thalerjonathan/events{/privacy}","received_events_url":"https://api.github.com/users/thalerjonathan/received_events","type":"User","site_admin":false},"created_at":"2018-03-27T14:16:40Z","updated_at":"2018-03-27T14:16:40Z","author_association":"NONE","body":"The crash occurs in idris_readRef (). I uploaded the crashing binary https://github.com/thalerjonathan/idris-callbacks-tests/blob/master/idrisclbktest and the coredump https://github.com/thalerjonathan/idris-callbacks-tests/blob/master/core.6975 for further inspection."}}
{"actor":{"display_login":"thalerjonathan"}}