Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is Alloc needed for visitChildren? #19

Closed
ghorn opened this issue May 5, 2013 · 5 comments
Closed

is Alloc needed for visitChildren? #19

ghorn opened this issue May 5, 2013 · 5 comments

Comments

@ghorn
Copy link
Contributor

ghorn commented May 5, 2013

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
Copy link
Owner

chetant commented May 5, 2013

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
Copy link
Contributor Author

ghorn commented May 5, 2013

You are very welcome. Thanks for the bindings!

@sethfowler
Copy link
Collaborator

@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
Copy link
Owner

chetant commented May 6, 2013

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//issues/19#issuecomment-17465405
.

@sethfowler
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants