chetant / LibClang

Haskell FFI to libclang
Other
58 stars 10 forks source link

is Alloc needed for visitChildren? #19

Closed ghorn closed 11 years ago

ghorn commented 11 years ago

I'm using a wrapper to avoid the Alloc requirement for visitChildren:

import qualified Control.Concurrent as CC

visitChildren' :: Cursor -> ChildVisitor a -> Maybe a -> IO (Maybe a, Bool)
visitChildren' cursor0 userVisitor userData0 = do
  m <- CC.newMVar userData0
  let cheaterVisitor cursor parent _ = do
        currentUserData <- CC.takeMVar m
        (newUserData,newUserRetCode) <- userVisitor cursor parent currentUserData
        CC.putMVar m newUserData
        return (Nothing :: Maybe Int, newUserRetCode)
  (_,finalRetCode) <- C.visitChildren cursor0 cheaterVisitor Nothing
  finalData <- CC.takeMVar m
  return (finalData, finalRetCode)

Is this a reasonable thing to do? I don't see a reason to pass the data pointer through the c library when it can be done in haskell.

chetant commented 11 years ago

You're absolutely right, there's no need for passing userdata through visitChildren. You could also use IORefs. I'll try and remove the Alloc req. when I get a chance. Thanks for find this issue!

ghorn commented 11 years ago

You are very welcome. Thanks for the bindings!

sethfowler commented 11 years ago

@chetant, I've already removed the Alloc requirement (and the user data parameter) in my branch. Sorry I haven't pushed it into this repo yet; as I mentioned in another bug I'm hoping to get it in sometime this week.

chetant commented 11 years ago

That's great! On May 5, 2013 11:51 PM, "sfowler" notifications@github.com wrote:

@chetant https://github.com/chetant, I've already removed the Alloc requirement (and the user data parameter) in my branch. Sorry I haven't pushed it into this repo yet; as I mentioned in another bug I'm hoping to get it in sometime this week.

— Reply to this email directly or view it on GitHubhttps://github.com/chetant/LibClang/issues/19#issuecomment-17465405 .

sethfowler commented 11 years ago

@ghorn, please see the llvm3.3 branch. Alloc has been removed.