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

Borrow C strings instead of copying them #335

Merged
merged 7 commits into from
Feb 4, 2014

Conversation

carlosmn
Copy link
Member

@carlosmn carlosmn commented Feb 4, 2014

Often, we don't need our own copy of a C string as we're simply going to pass it to libgit2 and then free it. In those cases, we can skip the strdup and use the underlying C string and use the refcount to make sure we have a valid pointer.

It also fixes a leak in the IndexEntry code.

We don't always need our own copy of a C string; sometimes we just need
to parse it. Create py_str_borrow_c_str() which returns a char pointer
to python's internal value string, with which we can avoid an extra copy.
We don't need our own copy of the string, so use the new borrowing
mechanism to use python's underlying string for the key to get/set.
@jdavid jdavid merged commit dcd5acc into libgit2:master Feb 4, 2014
@carlosmn carlosmn deleted the c-str-borrow branch February 4, 2014 17:46
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

Successfully merging this pull request may close these issues.

2 participants