rpcrt4: Fix NdrConformantVaryingStructUnmarshall to use buffer memory if applicable and to reuse memory for embedded pointers.

This commit is contained in:
Rob Shearman 2008-06-23 12:56:49 +01:00 committed by Alexandre Julliard
parent 33e907bc9d
commit 0c095ee0d3
2 changed files with 19 additions and 13 deletions

View File

@ -1562,7 +1562,7 @@ static unsigned char * EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
* EmbeddedPointerUnmarshall
*/
static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
unsigned char *pDstMemoryPtrs,
unsigned char *pDstBuffer,
unsigned char *pSrcMemoryPtrs,
PFORMAT_STRING pFormat,
unsigned char fMustAlloc)
@ -1572,7 +1572,7 @@ static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
unsigned i;
unsigned char *saved_buffer = NULL;
TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, pDstMemoryPtrs, pSrcMemoryPtrs, pFormat, fMustAlloc);
TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, pDstBuffer, pSrcMemoryPtrs, pFormat, fMustAlloc);
if (*pFormat != RPC_FC_PP) return NULL;
pFormat += 2;
@ -1610,16 +1610,16 @@ static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
}
for (i = 0; i < rep; i++) {
PFORMAT_STRING info = pFormat;
unsigned char *memdstbase = pDstMemoryPtrs + (i * stride);
unsigned char *bufdstbase = pDstBuffer + (i * stride);
unsigned char *memsrcbase = pSrcMemoryPtrs + (i * stride);
unsigned char *bufbase = Mark + (i * stride);
unsigned u;
for (u=0; u<count; u++,info+=8) {
unsigned char **memdstptr = (unsigned char **)(memdstbase + *(const SHORT*)&info[0]);
unsigned char **bufdstptr = (unsigned char **)(bufdstbase + *(const SHORT*)&info[2]);
unsigned char **memsrcptr = (unsigned char **)(memsrcbase + *(const SHORT*)&info[0]);
unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
PointerUnmarshall(pStubMsg, bufptr, memdstptr, *memsrcptr, info+4, fMustAlloc);
PointerUnmarshall(pStubMsg, bufptr, bufdstptr, *memsrcptr, info+4, fMustAlloc);
}
}
pFormat += 8 * count;
@ -4186,6 +4186,7 @@ unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE
PFORMAT_STRING pCVArrayFormat;
ULONG esize, bufsize;
unsigned char cvarray_type;
unsigned char *saved_buffer, *saved_array_buffer;
TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
@ -4237,9 +4238,9 @@ unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE
*ppMemory = NdrAllocate(pStubMsg, size);
}
/* copy the constant data */
pStubMsg->BufferMark = pStubMsg->Buffer;
safe_copy_from_buffer(pStubMsg, *ppMemory, pCVStructFormat->memory_size);
/* mark the start of the constant data */
saved_buffer = pStubMsg->BufferMark = pStubMsg->Buffer;
safe_buffer_increment(pStubMsg, pCVStructFormat->memory_size);
pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat, pStubMsg->MaxCount);
@ -4249,16 +4250,23 @@ unsigned char * WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE
(cvarray_type == RPC_FC_C_WSTRING))
validate_string_data(pStubMsg, bufsize, esize);
/* mark the start of the array data */
saved_array_buffer = pStubMsg->Buffer;
safe_buffer_increment(pStubMsg, bufsize);
EmbeddedPointerUnmarshall(pStubMsg, saved_buffer, *ppMemory, pFormat, fMustAlloc);
/* copy the constant data */
memcpy(*ppMemory, saved_buffer, pCVStructFormat->memory_size);
/* copy the array data */
safe_copy_from_buffer(pStubMsg, *ppMemory + pCVStructFormat->memory_size, bufsize);
TRACE("copying %p to %p\n", saved_array_buffer, *ppMemory + pCVStructFormat->memory_size);
memcpy(*ppMemory + pCVStructFormat->memory_size, saved_array_buffer, bufsize);
if (cvarray_type == RPC_FC_C_CSTRING)
TRACE("string=%s\n", debugstr_a((char *)(*ppMemory + pCVStructFormat->memory_size)));
else if (cvarray_type == RPC_FC_C_WSTRING)
TRACE("string=%s\n", debugstr_w((WCHAR *)(*ppMemory + pCVStructFormat->memory_size)));
EmbeddedPointerUnmarshall(pStubMsg, *ppMemory, *ppMemory, pFormat, TRUE /* FIXME */);
return NULL;
}

View File

@ -1208,9 +1208,7 @@ array_tests(void)
ns->size = 5;
ns->numbers[0].pi = pi;
get_numbers_struct(&ns);
todo_wine {
ok(ns->numbers[0].pi == pi, "RPC conformant varying struct embedded pointer changed from %p to %p\n", pi, ns->numbers[0].pi);
}
ok(*ns->numbers[0].pi == 5, "pi unmarshalled incorrectly %d\n", *ns->numbers[0].pi);
HeapFree(GetProcessHeap(), 0, ns);