Skip to content

Conversation

pks-t
Copy link
Member

@pks-t pks-t commented Dec 8, 2017

The function git_packfile_stream_free frees all state of the packfile
stream without freeing the structure itself. Thus, the function is
misnamed, as we usually call such a function a "clear" function. Rename
it to make clear that in fact it does not free the structure.

@ethomson
Copy link
Member

ethomson commented Dec 8, 2017

Not sure I agree here, what about git_buf_free, git_zstream_free... clear suggests that it doesn't necessarily free underlying memory (eg, git_buf_clear).

I don't really mind that these are _free if they don't free the structure itself. But I think I did give it a raised eyebrow when I saw it. But I don't think _clear is correct, so maybe we should come up with something else. And if we're going to do it then we need to be consistent.

@pks-t
Copy link
Member Author

pks-t commented Dec 8, 2017

Huh, you're correct about those. I don't mind to find a better term than clear, but I do want those two cases of freeing or not freeing to be distinct. You just cannot see whether the implementation will try to free the pointer itself or not if both types are being called free, and this becomes confusing really fast. I've tripped about this in reviewing another PR, where I first thought the change was incorrect as a stack-allocated pointer was being passed to a free function. And free to me means just that: free the structure and everything else that is associated with it, just like free(3).

I don't really have good alternatives. Some things that came to my mind:

  • release
  • purge
  • wipe

I think I like wipe the best. It shows that it is being cleaned up somehow, but with wiping you don't remove the structure itself. Opinions?

I also definitly agree about being consistent. I didn't think of those other occurrences.

@ethomson
Copy link
Member

ethomson commented Dec 8, 2017

Hm. I know where you're coming from but this has never bothered me in that way, I don't think. Curious about @carlosmn's opinions.

Note also that git_buf_free is public API which complicates things.

If we do make a change, what about dispose?

@pks-t
Copy link
Member Author

pks-t commented Dec 8, 2017

Dispose would be fine with me, sure.

And yeah, the git_buf thing is rather unfortunate. I'm definitly not in favor of changing the API, so I'd treat this as an exception to the rule.

@ethomson
Copy link
Member

ethomson commented Feb 2, 2018

OK. I'm leaning towards thinking that this makes sense. I think that I prefer dispose.

I'm also okay with adding git_buf_dispose as a public API and adding a deprecation notice to git_buf_free and zapping it eventually. Thoughts?

@pks-t
Copy link
Member Author

pks-t commented Feb 8, 2018

As I'm the one pushing towards that direction, I'm definitly in favor of your proposal.

I don't know about removing the git_buf_free function, though. it's really no burden to maintain at all, so if we decide to zap it for code hygiene we should be conservative and give at least two or three releases of time to do so. Probably together with a deprecation warning annotation the compiler, such that downstream notices we have deprecated it in favor of git_buf_dispose.

@pks-t pks-t force-pushed the pks/packfile-stream-free branch from 91717e0 to 853f3a7 Compare February 8, 2018 11:18
@pks-t
Copy link
Member Author

pks-t commented Feb 8, 2018

I've made your proposed change with regards to git_buf_free. Created a deprecation macro, implemented git_buf_dispose, deprecated git_buf_free and then afterwards made a tree-wide conversion of git_buf_free -> git_buf_dispose.

__attribute__((deprecated)) \
func
#elif defined(_MSC_VER)
# define GIT_EXTERN(func) __declspec(deprecated) func
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a copy/paste error.

Copy link
Member Author

Choose a reason for hiding this comment

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

cough Embarrassing.

#elif defined(_MSC_VER)
# define GIT_EXTERN(func) __declspec(deprecated) func
#else
# define GIT_EXTERN(func) func
Copy link
Member

Choose a reason for hiding this comment

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

Same.

@pks-t pks-t force-pushed the pks/packfile-stream-free branch from 853f3a7 to 80810cf Compare February 8, 2018 11:28
@pks-t pks-t force-pushed the pks/packfile-stream-free branch from 80810cf to 08f2ff4 Compare March 2, 2018 11:24
@ethomson
Copy link
Member

ethomson commented Jun 9, 2018

Ugh, sorry, I wish I had gotten around to this sooner before there were conflicts. If you could fix those up quickly I'll merge this. 👍

I'm really happy that we're deprecating this nicely and not breaking anything. 😀

pks-t added 4 commits June 10, 2018 19:30
The function `git_packfile_stream_free` frees all state of the packfile
stream without freeing the structure itself. This naming makes it hard
to spot whether it will try to free the pointer itself or not, causing
potential future errors. Due to this reason, we have decided to name a
function freeing state without freeing the actual struture a "dispose"
function.

Rename `git_packfile_stream_free` to `git_packfile_stream_dispose` as a
first example following this rule.
@pks-t pks-t force-pushed the pks/packfile-stream-free branch from 08f2ff4 to ecf4f33 Compare June 10, 2018 17:34
@pks-t
Copy link
Member Author

pks-t commented Jun 10, 2018 via email

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