-
Notifications
You must be signed in to change notification settings - Fork 15
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
Reentrant allocator #16
Conversation
Free parser list when freeing grammar.
Fix a memory leak where the memory used for YAEP_NIL and YAEP_ERROR nodes would not be freed if they were not used in the parse tree.
C++ already has error detection by throwing std::bad_alloc in case of allocation failure.
Thank you for working on this. The first thing I noticed is that the unit tests still fail after I apply this pull request. I really think the tests should work before and after someone adds code to the main branch of the repository. I also noticed that I do not know how to use the new memory management code. If I do not change my code, then the compiler reports the following errors:
. I fixed the problem by replacing the memory management function with To end this on a positive note, AddressSanitizer does not report any memory leaks if the OS creates a |
On my machine, all the tests succeed. To debug what's going wrong with the Travis tests, we need more info (the generated Just a thought: which branch are you applying the pull request to? vnmakarov/main or some other branch? Your PR #15 is quite possibly incompatible with my PR #16 (see below).
In making the new allocator, I changed the API of OS, VLO, and hash_table. I didn't think much of it since these were private interfaces anyway (I actually even removed allocate.h, since yaep doesn't need to make that public). However, almost simultaneously, you created #15, making (at least) OS public. Hence, boom.
I'm not sure what you mean here. If you replace all calls of
I'd like to say
If you call So, how to go on from here?
|
Thank you for the quick, extensive and helpful reply.
Interesting, on my machine the test suite fails, just like it does on Travis.
Yep, just sign up with your GitHub account at http://travis-ci.com and enable testing for your version of the YAEP repository. For more information, please take a look here. Afterwards just change the file
I crated a branch based on this PR, uninstalled YAEP and then installed YAEP via
I assumed as much. Anyway, I did not apply your code on my pull request or vice versa. I just used the code of this PR to build and install YAEP. I also removed
The C++ method
Interesting, I did not know that such a feature exists.
That would be really great, especially if the C++ interface would provide the same feature.
As far as I can tell,
I use
I would prefer that YAEP does not require that I provide a memory allocation function at all. As a user of YAEP I (currently) do not care what code the library uses to allocate and deallocate memory. In my opinion an interface that makes memory management easier would be really great. For example, I think using |
Regarding
I'll also add this on top of this PR. Thank you for the pointers regarding Travis. I'll look into that and into your OS usage after I have fixed the above things. |
Added two commits, see #16 (comment) |
Wow, you are really fast 😊. I was able to fix the memory leaks using the latest code from your PR. Thank you very much. |
OK, I've also got travis to run and see this: https://travis-ci.org/TheCount/yaep/jobs/438340845 What happens here is essentially that The API description does not mention this behaviour, so I'll just remove it. |
When yaep_read_grammar() fails, it must not free the grammar; this needs to be done by the caller of yaep_create_grammar(). See vnmakarov#16 (comment)
When yaep_read_grammar() fails, it must not free the grammar; this needs to be done by the caller of yaep_create_grammar(). See vnmakarov#16 (comment)
Thank you for the patches. It is a big work. I'll try to review the patches on the next week and, if they are ok, I'll merge them into the repository. YAEP was originally implemented on C. For some reasons, I decided to add C++ interface. But basically it was a wrap up around C. YAEP was a part of COCOM toolset and as many other tools it used a lot of common data-structures (os, vlo, hashtab etc). I don't work on COCOM anymore (some tool designs are too outdated) but on the base of it programming language DINO implemented http://dino-lang.github.io/ (it is my language to do a research on dynamic programming languages implementations). Earley parser is part of dino standard library. So YAEP code is very old and probably need some modernization. |
Alexander, thank you again for the patches. I've merged the pull request. YAEP code uses GNU standard style. So I've changed the format of your changes after the merge. |
This is an early preparation for a fix to #12.
It basically does two things:
allocate.h
from the yaep install/interface: it's not actually needed for using the yaep library.allocate.h
interface internally so the allocator becomes reentrant. Incidentally, this should remove the remaining memory leak.Note that the new
allocate.h
internal interface is not compatible to the old one, and the fact that the allocator is now reentrant makes it necessary to carry analloc
handle around, which had ramifications throughout the code.Bonus feature: yaep now has a convenience function to free a returned parse tree.