Rob Shearman : rpcrt4: Fix NdrConformantArrayUnmarshall to use buffer memory if applicable and to reuse memory for embedded pointers .

Alexandre Julliard julliard at winehq.org
Sat Dec 8 13:43:42 CST 2007


Module: wine
Branch: master
Commit: abbceb137a36e99a388d080ec29f4d16f4e8efb1
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=abbceb137a36e99a388d080ec29f4d16f4e8efb1

Author: Rob Shearman <rob at codeweavers.com>
Date:   Sat Dec  8 17:14:10 2007 +0000

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

---

 dlls/rpcrt4/ndr_marshall.c       |   21 +++++++++++++++------
 dlls/rpcrt4/tests/ndr_marshall.c |    2 --
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/dlls/rpcrt4/ndr_marshall.c b/dlls/rpcrt4/ndr_marshall.c
index be18de8..f7c6104 100644
--- a/dlls/rpcrt4/ndr_marshall.c
+++ b/dlls/rpcrt4/ndr_marshall.c
@@ -2585,6 +2585,7 @@ unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
 {
   DWORD size, esize = *(const WORD*)(pFormat+2);
   unsigned char alignment = pFormat[1] + 1;
+  unsigned char *saved_buffer;
 
   TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
   if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
@@ -2592,16 +2593,24 @@ unsigned char * WINAPI NdrConformantArrayUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
   pFormat = ReadConformance(pStubMsg, pFormat+4);
 
   size = safe_multiply(esize, pStubMsg->MaxCount);
+  ALIGN_POINTER(pStubMsg->Buffer, alignment);
 
-  if (fMustAlloc || !*ppMemory)
+  if (fMustAlloc)
     *ppMemory = NdrAllocate(pStubMsg, size);
+  else
+  {
+    if (!pStubMsg->IsClient && !*ppMemory)
+      /* for servers, we just point straight into the RPC buffer */
+      *ppMemory = pStubMsg->Buffer;
+  }
 
-  ALIGN_POINTER(pStubMsg->Buffer, alignment);
-
-  pStubMsg->BufferMark = pStubMsg->Buffer;
-  safe_copy_from_buffer(pStubMsg, *ppMemory, size);
+  saved_buffer = pStubMsg->BufferMark = pStubMsg->Buffer;
+  safe_buffer_increment(pStubMsg, size);
+  EmbeddedPointerUnmarshall(pStubMsg, saved_buffer, *ppMemory, pFormat, fMustAlloc);
 
-  EmbeddedPointerUnmarshall(pStubMsg, *ppMemory, *ppMemory, pFormat, TRUE /* FIXME */);
+  TRACE("copying %p to %p\n", saved_buffer, *ppMemory);
+  if (*ppMemory != saved_buffer)
+      memcpy(*ppMemory, saved_buffer, size);
 
   return NULL;
 }
diff --git a/dlls/rpcrt4/tests/ndr_marshall.c b/dlls/rpcrt4/tests/ndr_marshall.c
index d72d76f..51aecd5 100644
--- a/dlls/rpcrt4/tests/ndr_marshall.c
+++ b/dlls/rpcrt4/tests/ndr_marshall.c
@@ -1072,10 +1072,8 @@ static void test_conformant_array(void)
     mem = NULL;
     StubMsg.Buffer = StubMsg.BufferStart;
     NdrConformantArrayUnmarshall( &StubMsg, &mem, fmtstr_conf_array, 0);
-todo_wine {
     ok(mem == StubMsg.BufferStart + 4, "mem not pointing at buffer\n");
     ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
-}
     my_alloc_called = 0;
     mem = NULL;
     StubMsg.Buffer = StubMsg.BufferStart;




More information about the wine-cvs mailing list