Replace RGBImagePtr by RGBImageCleanup#3048
Conversation
831c5e3 to
2e74fb1
Compare
wantehchang
left a comment
There was a problem hiding this comment.
LGTM. Thanks. I suggest some changes.
|
Maryla: Since I edited this PR, could you please review it? Thanks. |
| // Automatically cleans the ressources of the avifRGBImage. | ||
| // To use when RGBImage actually owns the pixels. RGBImage can also be used as a view, in which case it does not own the pixels. | ||
| using RGBImagePtr = std::unique_ptr<avifRGBImage, UniquePtrDeleter>; | ||
| class RGBImageCleanup |
There was a problem hiding this comment.
Vignesh: Please review. This is modeled after absl::MakeCleanup. Thanks!
|
Since the new class is only to be used when the buffers are owned by the underlying pointer, can you please clarify a bit more in the commit message as to how the new class is different from the old unique_ptr wrapper? Could one not use the existing unique_ptr wrapper the same way? |
|
Vignesh: I added a commit message in #3048 (comment). The existing unique_ptr wrapper ( |
Although RGBImagePtr, defined using std::unique_ptr, is correct, it is
confusing because it does not free the avifRGBImage struct. Since the
avifRGBImage struct is intended to be allocated on the stack, we should
not address this by forcing the users of RGBImagePtr to allocate
avifRGBImage from the heap.
Replace RGBImagePtr by RGBImageCleanup, which is modeled after
absl::Cleanup and is a lightweight cleanup object whose destructor
calls avifRGBImageFreePixels() on the associated avifRGBImage struct.