ole32: COM cleanup of storage IStream implementation.

oldstable
Nikolay Sivov 2012-07-13 09:45:37 +04:00 committed by Alexandre Julliard
parent 91049f5e75
commit ea196ef0eb
3 changed files with 42 additions and 56 deletions

View File

@ -74,9 +74,6 @@ static void StgStreamImpl_Destroy(StgStreamImpl* This)
This->parentStorage = 0;
/*
* Finally, free the memory used-up by the class.
*/
HeapFree(GetProcessHeap(), 0, This);
}
@ -89,41 +86,24 @@ static HRESULT WINAPI StgStreamImpl_QueryInterface(
REFIID riid, /* [in] */
void** ppvObject) /* [iid_is][out] */
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
/*
* Perform a sanity check on the parameters.
*/
if (ppvObject==0)
return E_INVALIDARG;
/*
* Initialize the return parameter.
*/
*ppvObject = 0;
/*
* Compare the riid with the interface IDs implemented by this object.
*/
if (IsEqualIID(&IID_IUnknown, riid) ||
IsEqualIID(&IID_IPersist, riid) ||
IsEqualIID(&IID_IPersistStream, riid) ||
IsEqualIID(&IID_ISequentialStream, riid) ||
IsEqualIID(&IID_IStream, riid))
{
*ppvObject = This;
*ppvObject = &This->IStream_iface;
}
/*
* Check that we obtained an interface.
*/
if ((*ppvObject)==0)
else
return E_NOINTERFACE;
/*
* Query Interface always increases the reference count by one when it is
* successful
*/
IStream_AddRef(iface);
return S_OK;
@ -136,7 +116,7 @@ static HRESULT WINAPI StgStreamImpl_QueryInterface(
static ULONG WINAPI StgStreamImpl_AddRef(
IStream* iface)
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
return InterlockedIncrement(&This->ref);
}
@ -147,7 +127,7 @@ static ULONG WINAPI StgStreamImpl_AddRef(
static ULONG WINAPI StgStreamImpl_Release(
IStream* iface)
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
ULONG ref;
@ -179,7 +159,7 @@ static HRESULT WINAPI StgStreamImpl_Read(
ULONG cb, /* [in] */
ULONG* pcbRead) /* [out] */
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
ULONG bytesReadBuffer;
HRESULT res;
@ -235,7 +215,7 @@ static HRESULT WINAPI StgStreamImpl_Write(
ULONG cb, /* [in] */
ULONG* pcbWritten) /* [out] */
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
ULONG bytesWritten = 0;
HRESULT res;
@ -316,7 +296,7 @@ static HRESULT WINAPI StgStreamImpl_Seek(
DWORD dwOrigin, /* [in] */
ULARGE_INTEGER* plibNewPosition) /* [out] */
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
ULARGE_INTEGER newPosition;
DirEntry currentEntry;
@ -389,7 +369,7 @@ static HRESULT WINAPI StgStreamImpl_SetSize(
IStream* iface,
ULARGE_INTEGER libNewSize) /* [in] */
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
HRESULT hr;
@ -441,7 +421,7 @@ static HRESULT WINAPI StgStreamImpl_CopyTo(
ULARGE_INTEGER* pcbRead, /* [out] */
ULARGE_INTEGER* pcbWritten) /* [out] */
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
HRESULT hr = S_OK;
BYTE tmpBuffer[128];
ULONG bytesRead, bytesWritten, copySize;
@ -516,7 +496,7 @@ static HRESULT WINAPI StgStreamImpl_Commit(
IStream* iface,
DWORD grfCommitFlags) /* [in] */
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
if (!This->parentStorage)
{
@ -547,7 +527,7 @@ static HRESULT WINAPI StgStreamImpl_LockRegion(
ULARGE_INTEGER cb, /* [in] */
DWORD dwLockType) /* [in] */
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
if (!This->parentStorage)
{
@ -565,7 +545,7 @@ static HRESULT WINAPI StgStreamImpl_UnlockRegion(
ULARGE_INTEGER cb, /* [in] */
DWORD dwLockType) /* [in] */
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
if (!This->parentStorage)
{
@ -590,7 +570,7 @@ static HRESULT WINAPI StgStreamImpl_Stat(
STATSTG* pstatstg, /* [out] */
DWORD grfStatFlag) /* [in] */
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
DirEntry currentEntry;
HRESULT hr;
@ -650,7 +630,7 @@ static HRESULT WINAPI StgStreamImpl_Clone(
IStream* iface,
IStream** ppstm) /* [out] */
{
StgStreamImpl* const This=(StgStreamImpl*)iface;
StgStreamImpl* This = impl_from_IStream(iface);
HRESULT hres;
StgStreamImpl* new_stream;
LARGE_INTEGER seek_pos;
@ -672,7 +652,7 @@ static HRESULT WINAPI StgStreamImpl_Clone(
if (!new_stream)
return STG_E_INSUFFICIENTMEMORY; /* Currently the only reason for new_stream=0 */
*ppstm = (IStream*) new_stream;
*ppstm = &new_stream->IStream_iface;
IStream_AddRef(*ppstm);
seek_pos.QuadPart = This->currentPosition.QuadPart;
@ -687,7 +667,7 @@ static HRESULT WINAPI StgStreamImpl_Clone(
/*
* Virtual function table for the StgStreamImpl class.
*/
static const IStreamVtbl StgStreamImpl_Vtbl =
static const IStreamVtbl StgStreamVtbl =
{
StgStreamImpl_QueryInterface,
StgStreamImpl_AddRef,
@ -725,12 +705,12 @@ StgStreamImpl* StgStreamImpl_Construct(
newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(StgStreamImpl));
if (newStream!=0)
if (newStream)
{
/*
* Set-up the virtual function table and reference count.
*/
newStream->lpVtbl = &StgStreamImpl_Vtbl;
newStream->IStream_iface.lpVtbl = &StgStreamVtbl;
newStream->ref = 0;
newStream->parentStorage = parentStorage;

View File

@ -524,10 +524,10 @@ static HRESULT WINAPI StorageBaseImpl_OpenStream(
newStream = StgStreamImpl_Construct(This, grfMode, streamEntryRef);
if (newStream!=0)
if (newStream)
{
newStream->grfMode = grfMode;
*ppstm = (IStream*)newStream;
*ppstm = &newStream->IStream_iface;
IStream_AddRef(*ppstm);
@ -1007,10 +1007,9 @@ static HRESULT WINAPI StorageBaseImpl_CreateStream(
*/
newStream = StgStreamImpl_Construct(This, grfMode, newStreamEntryRef);
if (newStream != 0)
if (newStream)
{
*ppstm = (IStream*)newStream;
*ppstm = &newStream->IStream_iface;
IStream_AddRef(*ppstm);
}
else
@ -1684,11 +1683,19 @@ static HRESULT StorageBaseImpl_CopyChildEntryTo(StorageBaseImpl *This,
*/
if (hr == S_OK)
{
pstrChild = (IStream*)StgStreamImpl_Construct(This, STGM_READ|STGM_SHARE_EXCLUSIVE, srcEntry);
if (pstrChild)
IStream_AddRef(pstrChild);
StgStreamImpl *streamimpl = StgStreamImpl_Construct(This, STGM_READ|STGM_SHARE_EXCLUSIVE, srcEntry);
if (streamimpl)
{
pstrChild = &streamimpl->IStream_iface;
if (pstrChild)
IStream_AddRef(pstrChild);
}
else
{
pstrChild = NULL;
hr = E_OUTOFMEMORY;
}
}
if (hr == S_OK)

View File

@ -418,25 +418,19 @@ SmallBlockChainStream* Storage32Impl_BigBlocksToSmallBlocks(
/****************************************************************************
* StgStreamImpl definitions.
*
* This class implements the IStream32 interface and represents a stream
* This class implements the IStream interface and represents a stream
* located inside a storage object.
*/
struct StgStreamImpl
{
const IStreamVtbl *lpVtbl; /* Needs to be the first item in the struct
* since we want to cast this to an IStream pointer */
IStream IStream_iface;
LONG ref;
/*
* We are an entry in the storage object's stream handler list
*/
struct list StrmListEntry;
/*
* Reference count
*/
LONG ref;
/*
* Storage that is the parent(owner) of the stream
*/
@ -458,6 +452,11 @@ struct StgStreamImpl
ULARGE_INTEGER currentPosition;
};
static inline StgStreamImpl *impl_from_IStream( IStream *iface )
{
return CONTAINING_RECORD(iface, StgStreamImpl, IStream_iface);
}
/*
* Method definition for the StgStreamImpl class.
*/