Christian Costa : d3dxof: Use offsets to reference data instead of pointers so data buffer can be resized .

Alexandre Julliard julliard at winehq.org
Thu Mar 12 09:54:25 CDT 2009


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

Author: Christian Costa <titan.costa at wanadoo.fr>
Date:   Thu Mar 12 09:06:16 2009 +0100

d3dxof: Use offsets to reference data instead of pointers so data buffer can be resized.

---

 dlls/d3dxof/d3dxof.c         |    5 +++--
 dlls/d3dxof/d3dxof_private.h |    6 ++++--
 dlls/d3dxof/parsing.c        |   31 ++++++++++++++++---------------
 3 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/dlls/d3dxof/d3dxof.c b/dlls/d3dxof/d3dxof.c
index 6a27cd5..f46a82c 100644
--- a/dlls/d3dxof/d3dxof.c
+++ b/dlls/d3dxof/d3dxof.c
@@ -686,7 +686,7 @@ static HRESULT WINAPI IDirectXFileDataImpl_GetData(IDirectXFileData* iface, LPCS
   }
 
   *pcbSize = This->pobj->size;
-  *ppvData = This->pobj->pdata;
+  *ppvData = This->pobj->root->pdata + This->pobj->pos_data;
 
   return DXFILE_OK;
 }
@@ -1063,7 +1063,8 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
     hr = DXFILEERR_BADALLOC;
     goto error;
   }
-  This->buf.cur_pdata = This->buf.pdata = object->pdata = pdata;
+  This->buf.pxo->pdata = This->buf.pdata = object->pdata = pdata;
+  This->buf.cur_pos_data = 0;
 
   pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER);
   if (!pstrings)
diff --git a/dlls/d3dxof/d3dxof_private.h b/dlls/d3dxof/d3dxof_private.h
index 67883ae..9cbd0e2 100644
--- a/dlls/d3dxof/d3dxof_private.h
+++ b/dlls/d3dxof/d3dxof_private.h
@@ -66,7 +66,7 @@ typedef struct {
 
 typedef struct {
     char* name;
-    LPBYTE start;
+    ULONG start;
     ULONG size;
 } xobject_member;
 
@@ -77,12 +77,14 @@ struct _xobject {
    GUID class_id;
    GUID type;
    LPBYTE pdata;
+   ULONG pos_data;
    DWORD size;
    ULONG nb_members;
    xobject_member members[MAX_MEMBERS];
    ULONG nb_childs;
    ULONG nb_subobjects;
    struct _xobject * childs[MAX_CHILDS];
+   struct _xobject * root;
 };
 
 typedef struct _xobject xobject;
@@ -130,7 +132,7 @@ typedef struct {
   BOOL token_present;
   BOOL txt;
   ULONG cur_subobject;
-  LPBYTE cur_pdata;
+  ULONG cur_pos_data;
   LPBYTE cur_pstrings;
   BYTE value[100];
   xobject** pxo_globals;
diff --git a/dlls/d3dxof/parsing.c b/dlls/d3dxof/parsing.c
index c849e5a..85c66cb 100644
--- a/dlls/d3dxof/parsing.c
+++ b/dlls/d3dxof/parsing.c
@@ -1009,14 +1009,14 @@ static BOOL parse_object_members_list(parse_buffer * buf)
     int nb_elems = 1;
 
     buf->pxo->members[i].name = pt->members[i].name;
-    buf->pxo->members[i].start = buf->cur_pdata;
+    buf->pxo->members[i].start = buf->cur_pos_data;
 
     for (k = 0; k < pt->members[i].nb_dims; k++)
     {
       if (pt->members[i].dim_fixed[k])
         nb_elems *= pt->members[i].dim_value[k];
       else
-        nb_elems *= *(DWORD*)buf->pxo->members[pt->members[i].dim_value[k]].start;
+        nb_elems *= *(DWORD*)(buf->pxo->root->pdata + buf->pxo->members[pt->members[i].dim_value[k]].start);
     }
 
     TRACE("Elements to consider: %d\n", nb_elems);
@@ -1076,20 +1076,20 @@ static BOOL parse_object_members_list(parse_buffer * buf)
           last_dword = *(DWORD*)buf->value;
           TRACE("%s = %d\n", pt->members[i].name, *(DWORD*)buf->value);
           /* Assume larger size */
-          if ((buf->cur_pdata - buf->pdata + 4) > MAX_DATA_SIZE)
+          if ((buf->cur_pos_data + 4) > MAX_DATA_SIZE)
           {
             FIXME("Buffer too small\n");
             return FALSE;
           }
           if (pt->members[i].type == TOKEN_WORD)
           {
-            *(((WORD*)(buf->cur_pdata))) = (WORD)(*(DWORD*)buf->value);
-            buf->cur_pdata += 2;
+            *(((WORD*)(buf->cur_pos_data + buf->pdata))) = (WORD)(*(DWORD*)buf->value);
+            buf->cur_pos_data += 2;
           }
           else if (pt->members[i].type == TOKEN_DWORD)
           {
-            *(((DWORD*)(buf->cur_pdata))) = (DWORD)(*(DWORD*)buf->value);
-            buf->cur_pdata += 4;
+            *(((DWORD*)(buf->cur_pos_data + buf->pdata))) = (DWORD)(*(DWORD*)buf->value);
+            buf->cur_pos_data += 4;
           }
           else
           {
@@ -1102,15 +1102,15 @@ static BOOL parse_object_members_list(parse_buffer * buf)
           get_TOKEN(buf);
           TRACE("%s = %f\n", pt->members[i].name, *(float*)buf->value);
           /* Assume larger size */
-          if ((buf->cur_pdata - buf->pdata + 4) > MAX_DATA_SIZE)
+          if ((buf->cur_pos_data + 4) > MAX_DATA_SIZE)
           {
             FIXME("Buffer too small\n");
             return FALSE;
           }
           if (pt->members[i].type == TOKEN_FLOAT)
           {
-            *(((float*)(buf->cur_pdata))) = (float)(*(float*)buf->value);
-            buf->cur_pdata += 4;
+            *(((float*)(buf->cur_pos_data + buf->pdata))) = (float)(*(float*)buf->value);
+            buf->cur_pos_data += 4;
           }
           else
           {
@@ -1123,7 +1123,7 @@ static BOOL parse_object_members_list(parse_buffer * buf)
           get_TOKEN(buf);
           TRACE("%s = %s\n", pt->members[i].name, (char*)buf->value);
           /* Assume larger size */
-          if ((buf->cur_pdata - buf->pdata + 4) > MAX_DATA_SIZE)
+          if ((buf->cur_pos_data + 4) > MAX_DATA_SIZE)
           {
             FIXME("Buffer too small\n");
             return FALSE;
@@ -1137,9 +1137,9 @@ static BOOL parse_object_members_list(parse_buffer * buf)
               return FALSE;
             }
             strcpy((char*)buf->cur_pstrings, (char*)buf->value);
-            *(((LPCSTR*)(buf->cur_pdata))) = (char*)buf->cur_pstrings;
+            *(((LPCSTR*)(buf->cur_pos_data + buf->pdata))) = (char*)buf->cur_pstrings;
             buf->cur_pstrings += len;
-            buf->cur_pdata += 4;
+            buf->cur_pos_data += 4;
           }
           else
           {
@@ -1173,7 +1173,7 @@ static BOOL parse_object_parts(parse_buffer * buf, BOOL allow_optional)
 
   if (allow_optional)
   {
-    buf->pxo->size = buf->cur_pdata - buf->pxo->pdata;
+    buf->pxo->size = buf->cur_pos_data - buf->pxo->pos_data;
 
     /* Skip trailing semicolon */
     while (check_TOKEN(buf) == TOKEN_SEMICOLON)
@@ -1242,8 +1242,9 @@ BOOL parse_object(parse_buffer * buf)
 {
   int i;
 
-  buf->pxo->pdata = buf->cur_pdata;
+  buf->pxo->pos_data = buf->cur_pos_data;
   buf->pxo->ptarget = NULL;
+  buf->pxo->root = buf->pxo_tab;
 
   if (get_TOKEN(buf) != TOKEN_NAME)
     return FALSE;




More information about the wine-cvs mailing list