-
Notifications
You must be signed in to change notification settings - Fork 11
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
Possible early free of input in generated C++ Parser #377
Comments
The issue here is that the generated parsers "own" their arguments, in particular they own the input. So when calling If you do want to use In general, this fine grained control over when things are copied/deallocated is very convenient for generating code, but is quite error prone for using manually from C++. To make it a bit more convenient, we have a wrapper class called It is defined here: To use it in this particular example, one would change the first line to: DDL::Owend<DDL::Input> i = DDL::Input("test", R"x("1")x"); Then when passing it to the parser, you need to use In short |
We should write some documentation about this in the reference manual. Also, the |
Agree that documentation should be improved on this matter. It is not the generally expected behavior in C/C++ that function will take ownership of an argument in this manner (normally if the caller created the memory then the caller free's the memory). One suggestion is to not take ownership and instead, have the parserMain immediately call copy on |
The reason the top-level parsers take their arguments as owned is so they can be de-allocated as soon as the parser is done with them, rather than having to hold on to them until parsing is complete. For normal inputs this doesn't matter hugely as you can't deallocate the input in parts, however, this is quite important for the streaming parsers, where chunks of input arrive while parsing. In that case it is nice that the parser can let go of earlier chunks of input that it knows it does not need anymore, and is essential if you want to support "infinite" or long running streams. I do agree that the behavior is quite surprising though, so at the very least it should be documented. Note that, at present, the same sort of memory management scheme is used everywhere in Daedalus, and you need the same sort of things with the results of the parser too. I haven't thought about it very deeply, but perhaps a better plan would be to simply use |
I'm getting a memory corruption of the name data for the Input instance in the following test:
If i.getName() is called before parseMain, then the above test will pass.
After some digging around in the debugger, one of the places the input is freed is:
The text was updated successfully, but these errors were encountered: