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

Split upb::Arena/upb::Allocator from upb::Environment. #58

Merged
merged 6 commits into from
Apr 19, 2016

Conversation

haberman
Copy link
Member

This will allow arenas and allocators to be used
independently of environments, which will be important
for an upcoming change (a message representation).
Overall this design feels cleaner that the previous
Environment/SeededAllocator design.

As part of this change, moved all allocations in upb
to use a global allocator instead of hard-coding
malloc/free. This will allow injecting OOM faults
for more robust testing.

One place that doesn't use the global allocator is
the tracked ref code. Instead of its previous approach
of CHECK_OOM() after every malloc() or table insert, it
simply uses an allocator that does this automatically.

I moved Allocator/Arena/Environment into upb.h.
This seems principled since these are the only types
in upb whose size is directly exposed to users, since
they form the basis of memory allocation strategy.

This will allow arenas and allocators to be used
independently of environments, which will be important
for an upcoming change (a message representation).
Overall this design feels cleaner that the previous
Environment/SeededAllocator design.

As part of this change, moved all allocations in upb
to use a global allocator instead of hard-coding
malloc/free.  This will allow injecting OOM faults
for more robust testing.

One place that doesn't use the global allocator is
the tracked ref code.  Instead of its previous approach
of CHECK_OOM() after every malloc() or table insert, it
simply uses an allocator that does this automatically.

I moved Allocator/Arena/Environment into upb.h.
This seems principled since these are the only types
in upb whose size is directly exposed to users, since
they form the basis of memory allocation strategy.
@haberman
Copy link
Member Author

Review to @scwhittle. I think you're going to like this!

@coveralls
Copy link

Coverage Status

Coverage increased (+7.9%) to 79.221% when pulling 6c6aa1b on haberman:arena into 89197b9 on google:master.

@haberman
Copy link
Member Author

Tests are green now.

free((void*)def->fullname);
def->fullname = upb_strdup(fullname);
if (!upb_isident(fullname, strlen(fullname), true, s)) {
return false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errmsg?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upb_isident() takes care of that.

@coveralls
Copy link

Coverage Status

Coverage increased (+7.8%) to 79.147% when pulling 215c956 on haberman:arena into 89197b9 on google:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+7.8%) to 79.147% when pulling 5b04ff6 on haberman:arena into 89197b9 on google:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+7.8%) to 79.147% when pulling 378e10e on haberman:arena into 89197b9 on google:master.

@haberman
Copy link
Member Author

Addressed comments, PTAL.

/* Need better logic here; at this point we've qualified some names but
* not others. */
return false;
}
upb_def_setfullname(def, name, NULL);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may fail with oom too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are probably lots of places like this, and we don't have a great recovery story here. I'm going to punt on being super thorough with this until we're actually testing for it anyway by injecting malloc failures.

@scwhittle
Copy link

LGTM

@haberman
Copy link
Member Author

Thanks! Merging.

@haberman haberman merged commit 68bc62a into protocolbuffers:master Apr 19, 2016
@haberman haberman deleted the arena branch April 13, 2019 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants