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

"it seems like jq_start frees input" mystery explanation #74

Open
diafour opened this issue Nov 23, 2019 · 1 comment
Open

"it seems like jq_start frees input" mystery explanation #74

diafour opened this issue Nov 23, 2019 · 1 comment

Comments

@diafour
Copy link

diafour commented Nov 23, 2019

Hi! Great work! Learn a lot about cgo and jq internals from this project.

I start my own project to use jq programs in Go projects with ability to cache compiled jq state. So here are some findings of jq_start behavior:

jq_start does two important things:

  • it calls jq_reset that free everything on the stack
  • it pushes input jv pointer to the stack

That stack is freed by a jq_teardown call that will call the same jq_reset. But input jv is already freed by the deferred call ;) That is why you need to use jv_copy here: https://github.com/jzelinskie/faq/blob/master/pkg/jq/exec.go#L237

@jzelinskie
Copy link
Owner

That's a great explanation! Thank you so much! Do you want to open a PR that updates the comment? That way the codebase can reflect your contribution of knowledge 😄

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

2 participants