Remove 'friend SkRefCnt' from SkData.

https://codereview.chromium.org/13925021/

If a non-POD class does not provide a default destructor, one is
provided by teh compiler. GCC will do so, but only at the point where the
vtable is output; since BlockRef has no implementation its destructor is
never output, so there is no complaint. VC++, however, provides the
destructor implementation as soon as it sees the type. If the destructor
of BlockRef is ever defined an error will be reported (since the
destructor of SkData is private).

Declaring (but does not defining) a destructor for BlockRef fixes two
issues. First, it prevents a default destructor from being provided,
removing the VC++ error. Second, BlockRef now blocks access to the
destructor through '->'.


git-svn-id: http://skia.googlecode.com/svn/trunk@8697 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bungeman@google.com 2013-04-16 15:24:31 +00:00
parent c4f2ecaa47
commit 6f4cf2a195
2 changed files with 5 additions and 35 deletions

View File

@ -122,41 +122,10 @@ private:
SkData(const void* ptr, size_t size, ReleaseProc, void* context);
virtual ~SkData();
// This is here because SkAutoTUnref creates an internal helper class
// that derives from SkData (i.e., BlockRef) to prevent refs\unrefs.
// This helper class generates a compiler warning on Windows since the
// SkData's destructor is private. This friending gives the helper class
// access to the destructor.
friend class SkAutoTUnref<SkData>::BlockRef<SkData>;
typedef SkFlattenable INHERITED;
};
/**
* Specialized version of SkAutoTUnref<SkData> for automatically unref-ing a
* SkData.
*/
class SkAutoDataUnref : SkNoncopyable {
public:
SkAutoDataUnref(SkData* data) : fRef(data) {}
~SkAutoDataUnref() {
SkSafeUnref(fRef);
}
SkData* get() const { return fRef; }
void release() {
if (fRef) {
fRef->unref();
fRef = NULL;
}
}
SkData *operator->() const { return fRef; }
operator SkData*() { return fRef; }
private:
SkData* fRef;
};
/** Typedef of SkAutoTUnref<SkData> for automatically unref-ing a SkData. */
typedef SkAutoTUnref<SkData> SkAutoDataUnref;
#endif

View File

@ -189,12 +189,13 @@ public:
}
/**
* BlockRef<B> is a type which inherits from B, cannot be created,
* and makes ref and unref private.
* BlockRef<B> is a type which inherits from B, cannot be created,
* cannot be deleted, and makes ref and unref private.
*/
template<typename B> class BlockRef : public B {
private:
BlockRef();
~BlockRef();
void ref() const;
void unref() const;
};