Bug 1005321 - Convert the xpt code to C++; r=bholley
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 05 May 2014 19:52:09 -0400
changeset 200903 72fbb3c9a2669a6f6d46980a1dd5dd0ebd17977d
parent 200838 997a2d66710e23265e9cf7a13c21f700a8b2ec36
child 200904 f5ac479e69d4b916a0396c7e4683a626e6a7508c
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1005321
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1005321 - Convert the xpt code to C++; r=bholley
CLOBBER
xpcom/typelib/xpt/src/moz.build
xpcom/typelib/xpt/src/xpt_arena.c
xpcom/typelib/xpt/src/xpt_arena.cpp
xpcom/typelib/xpt/src/xpt_struct.c
xpcom/typelib/xpt/src/xpt_struct.cpp
xpcom/typelib/xpt/src/xpt_xdr.c
xpcom/typelib/xpt/src/xpt_xdr.cpp
xpcom/typelib/xpt/tests/PrimitiveTest.c
xpcom/typelib/xpt/tests/PrimitiveTest.cpp
xpcom/typelib/xpt/tests/SimpleTypeLib.c
xpcom/typelib/xpt/tests/SimpleTypeLib.cpp
xpcom/typelib/xpt/tests/moz.build
--- a/CLOBBER
+++ b/CLOBBER
@@ -17,9 +17,9 @@
 #
 # Modifying this file will now automatically clobber the buildbot machines \o/
 #
 
 # Are you updating CLOBBER because you think it's needed for your WebIDL
 # changes to stick? As of bug 928195, this shouldn't be necessary! Please
 # don't change CLOBBER for WebIDL changes any more.
 
-Bug 1003702 - Relanding ICU changes with a clobber
+Bug 1005321 - Requires a clobber because of bug 1005486
--- a/xpcom/typelib/xpt/src/moz.build
+++ b/xpcom/typelib/xpt/src/moz.build
@@ -2,17 +2,17 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 LIBRARY_NAME = 'xpt'
 
 UNIFIED_SOURCES += [
-    'xpt_arena.c',
-    'xpt_struct.c',
-    'xpt_xdr.c',
+    'xpt_arena.cpp',
+    'xpt_struct.cpp',
+    'xpt_xdr.cpp',
 ]
 
 FINAL_LIBRARY = 'xpcom_core'
 
 GENERATED_INCLUDES += ['/xpcom/base']
 LOCAL_INCLUDES += ['/xpcom/base']
rename from xpcom/typelib/xpt/src/xpt_arena.c
rename to xpcom/typelib/xpt/src/xpt_arena.cpp
--- a/xpcom/typelib/xpt/src/xpt_arena.c
+++ b/xpcom/typelib/xpt/src/xpt_arena.cpp
@@ -100,17 +100,17 @@ struct XPTArena
     uint32_t LOG_RealMallocCallCount;
     uint32_t LOG_RealMallocTotalBytesRequested;
 #endif /* XPT_ARENA_LOGGING */
 };
 
 XPT_PUBLIC_API(XPTArena *)
 XPT_NewArena(uint32_t block_size, size_t alignment, const char* name)
 {
-    XPTArena *arena = calloc(1, sizeof(XPTArena));
+    XPTArena *arena = (XPTArena*)calloc(1, sizeof(XPTArena));
     if (arena) {
         XPT_ASSERT(alignment);
         if (alignment > sizeof(double))
             alignment = sizeof(double);
         arena->alignment = alignment;
 
         if (block_size < XPT_MIN_BLOCK_SIZE)
             block_size = XPT_MIN_BLOCK_SIZE;
@@ -239,17 +239,17 @@ XPT_ArenaStrDup(XPTArena *arena, const c
 {
     size_t len;
     char* cur;
 
     if (!s)
         return NULL;
 
     len = strlen(s)+1;
-    cur = XPT_ArenaMalloc(arena, len);
+    cur = (char*)XPT_ArenaMalloc(arena, len);
     memcpy(cur, s, len);
     return cur;
 }
 
 XPT_PUBLIC_API(void)
 XPT_NotifyDoneLoading(XPTArena *arena)
 {
 #ifdef XPT_ARENA_LOGGING
rename from xpcom/typelib/xpt/src/xpt_struct.c
rename to xpcom/typelib/xpt/src/xpt_struct.cpp
--- a/xpcom/typelib/xpt/src/xpt_struct.c
+++ b/xpcom/typelib/xpt/src/xpt_struct.cpp
@@ -93,18 +93,18 @@ XPT_NewHeader(XPTArena *arena, uint16_t 
     if (!header)
         return NULL;
     memcpy(header->magic, XPT_MAGIC, 16);
     header->major_version = major_version;
     header->minor_version = minor_version;
     header->num_interfaces = num_interfaces;
     if (num_interfaces) {
         header->interface_directory = 
-            XPT_CALLOC(arena, 
-                       num_interfaces * sizeof(XPTInterfaceDirectoryEntry));
+            (XPTInterfaceDirectoryEntry*)XPT_CALLOC(arena, 
+                                                    num_interfaces * sizeof(XPTInterfaceDirectoryEntry));
         if (!header->interface_directory) {
             XPT_DELETE(arena, header);
             return NULL;
         }
     }
     header->data_pool = 0;      /* XXX do we even need this struct any more? */
     
     return header;
@@ -202,17 +202,16 @@ XPT_DoHeaderPrologue(XPTArena *arena, XP
     return PR_TRUE;
     /* XXX need to free child data sometimes! */
     XPT_ERROR_HANDLE(arena, header);    
 }
 
 XPT_PUBLIC_API(PRBool)
 XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
 {
-    const int HEADER_SIZE = 24;
     XPTMode mode = cursor->state->mode;
     XPTHeader * header;
     uint32_t ide_offset;
     int i;
     XPTAnnotation *ann, *next, **annp;
 
     if (!XPT_DoHeaderPrologue(arena, cursor, headerp, &ide_offset))
         return PR_FALSE;
@@ -232,18 +231,18 @@ XPT_DoHeader(XPTArena *arena, XPTCursor 
         XPT_DataOffset(cursor->state, &header->data_pool);
     if (!XPT_Do32(cursor, &header->data_pool))
         goto error;
     if (mode == XPT_DECODE)
         XPT_DataOffset(cursor->state, &header->data_pool);
 
     if (mode == XPT_DECODE && header->num_interfaces) {
         header->interface_directory = 
-            XPT_CALLOC(arena, header->num_interfaces * 
-                       sizeof(XPTInterfaceDirectoryEntry));
+            (XPTInterfaceDirectoryEntry*)XPT_CALLOC(arena, header->num_interfaces * 
+                                                    sizeof(XPTInterfaceDirectoryEntry));
         if (!header->interface_directory)
             goto error;
     }
 
     /*
      * Iterate through the annotations rather than recurring, to avoid blowing
      * the stack on large xpt files.
      */
@@ -342,26 +341,26 @@ XPT_NewInterfaceDescriptor(XPTArena *are
                            uint16_t num_constants, uint8_t flags)
 {
 
     XPTInterfaceDescriptor *id = XPT_NEWZAP(arena, XPTInterfaceDescriptor);
     if (!id)
         return NULL;
 
     if (num_methods) {
-        id->method_descriptors = XPT_CALLOC(arena, num_methods *
-                                            sizeof(XPTMethodDescriptor));
+        id->method_descriptors = (XPTMethodDescriptor*)XPT_CALLOC(arena, num_methods *
+                                                                  sizeof(XPTMethodDescriptor));
         if (!id->method_descriptors)
             goto free_id;
         id->num_methods = num_methods;
     }
 
     if (num_constants) {
-        id->const_descriptors = XPT_CALLOC(arena, num_constants *
-                                           sizeof(XPTConstDescriptor));
+        id->const_descriptors = (XPTConstDescriptor*)XPT_CALLOC(arena, num_constants *
+                                                                sizeof(XPTConstDescriptor));
         if (!id->const_descriptors)
             goto free_meth;
         id->num_constants = num_constants;
     }
 
     if (parent_interface) {
         id->parent_interface = parent_interface;
     } else {
@@ -410,76 +409,76 @@ XPT_FreeInterfaceDescriptor(XPTArena *ar
     }
 }
 
 XPT_PUBLIC_API(PRBool)
 XPT_InterfaceDescriptorAddTypes(XPTArena *arena, XPTInterfaceDescriptor *id, 
                                 uint16_t num)
 {
     XPTTypeDescriptor *old = id->additional_types;
-    XPTTypeDescriptor *new;
+    XPTTypeDescriptor *new_;
     size_t old_size = id->num_additional_types * sizeof(XPTTypeDescriptor);
     size_t new_size = (num * sizeof(XPTTypeDescriptor)) + old_size;
 
     /* XXX should grow in chunks to minimize alloc overhead */
-    new = XPT_CALLOC(arena, new_size);
-    if (!new)
+    new_ = (XPTTypeDescriptor*)XPT_CALLOC(arena, new_size);
+    if (!new_)
         return PR_FALSE;
     if (old) {
         if (old_size)
-            memcpy(new, old, old_size);
+            memcpy(new_, old, old_size);
         XPT_FREE(arena, old);
     }
-    id->additional_types = new;
+    id->additional_types = new_;
     id->num_additional_types += num;
     return PR_TRUE;
 }
 
 XPT_PUBLIC_API(PRBool)
 XPT_InterfaceDescriptorAddMethods(XPTArena *arena, XPTInterfaceDescriptor *id, 
                                   uint16_t num)
 {
     XPTMethodDescriptor *old = id->method_descriptors;
-    XPTMethodDescriptor *new;
+    XPTMethodDescriptor *new_;
     size_t old_size = id->num_methods * sizeof(XPTMethodDescriptor);
     size_t new_size = (num * sizeof(XPTMethodDescriptor)) + old_size;
 
     /* XXX should grow in chunks to minimize alloc overhead */
-    new = XPT_CALLOC(arena, new_size);
-    if (!new)
+    new_ = (XPTMethodDescriptor*)XPT_CALLOC(arena, new_size);
+    if (!new_)
         return PR_FALSE;
     if (old) {
         if (old_size)
-            memcpy(new, old, old_size);
+            memcpy(new_, old, old_size);
         XPT_FREE(arena, old);
     }
-    id->method_descriptors = new;
+    id->method_descriptors = new_;
     id->num_methods += num;
     return PR_TRUE;
 }
 
 XPT_PUBLIC_API(PRBool)
 XPT_InterfaceDescriptorAddConsts(XPTArena *arena, XPTInterfaceDescriptor *id, 
                                  uint16_t num)
 {
     XPTConstDescriptor *old = id->const_descriptors;
-    XPTConstDescriptor *new;
+    XPTConstDescriptor *new_;
     size_t old_size = id->num_constants * sizeof(XPTConstDescriptor);
     size_t new_size = (num * sizeof(XPTConstDescriptor)) + old_size;
 
     /* XXX should grow in chunks to minimize alloc overhead */
-    new = XPT_CALLOC(arena, new_size);
-    if (!new)
+    new_ = (XPTConstDescriptor*)XPT_CALLOC(arena, new_size);
+    if (!new_)
         return PR_FALSE;
     if (old) {
         if (old_size)
-            memcpy(new, old, old_size);
+            memcpy(new_, old, old_size);
         XPT_FREE(arena, old);
     }
-    id->const_descriptors = new;
+    id->const_descriptors = new_;
     id->num_constants += num;
     return PR_TRUE;
 }
 
 uint32_t
 SizeOfTypeDescriptor(XPTTypeDescriptor *td, XPTInterfaceDescriptor *id)
 {
     uint32_t size = 1; /* prefix */
@@ -599,34 +598,34 @@ DoInterfaceDescriptor(XPTArena *arena, X
         return PR_TRUE;
     }
     if(!XPT_Do16(cursor, &id->parent_interface) ||
        !XPT_Do16(cursor, &id->num_methods)) {
         goto error;
     }
 
     if (mode == XPT_DECODE && id->num_methods) {
-        id->method_descriptors = XPT_CALLOC(arena, id->num_methods *
-                                            sizeof(XPTMethodDescriptor));
+        id->method_descriptors = (XPTMethodDescriptor*)XPT_CALLOC(arena, id->num_methods *
+                                                                  sizeof(XPTMethodDescriptor));
         if (!id->method_descriptors)
             goto error;
     }
     
     for (i = 0; i < id->num_methods; i++) {
         if (!DoMethodDescriptor(arena, cursor, &id->method_descriptors[i], id))
             goto error;   
     }
     
     if (!XPT_Do16(cursor, &id->num_constants)) {
         goto error;
     }
     
     if (mode == XPT_DECODE && id->num_constants) {
-        id->const_descriptors = XPT_CALLOC(arena, id->num_constants * 
-                                           sizeof(XPTConstDescriptor));
+        id->const_descriptors = (XPTConstDescriptor*)XPT_CALLOC(arena, id->num_constants * 
+                                                                sizeof(XPTConstDescriptor));
         if (!id->const_descriptors)
             goto error;
     }
     
     for (i = 0; i < id->num_constants; i++) {
         if (!DoConstDescriptor(arena, cursor, &id->const_descriptors[i], id)) {
             goto error;
         }
@@ -699,25 +698,24 @@ XPT_FillMethodDescriptor(XPTArena *arena
                          uint8_t flags, char *name, uint8_t num_args)
 {
     meth->flags = flags & XPT_MD_FLAGMASK;
     meth->name = XPT_STRDUP(arena, name);
     if (!meth->name)
         return PR_FALSE;
     meth->num_args = num_args;
     if (num_args) {
-        meth->params = XPT_CALLOC(arena, num_args * sizeof(XPTParamDescriptor));
+        meth->params = (XPTParamDescriptor*)XPT_CALLOC(arena, num_args * sizeof(XPTParamDescriptor));
         if (!meth->params)
             goto free_name;
     } else {
         meth->params = NULL;
     }
     return PR_TRUE;
 
- free_params:
     XPT_DELETE(arena, meth->params);
  free_name:
     XPT_DELETE(arena, meth->name);
     return PR_FALSE;
 }
 
 PRBool
 DoMethodDescriptor(XPTArena *arena, XPTCursor *cursor, XPTMethodDescriptor *md,
@@ -727,17 +725,17 @@ DoMethodDescriptor(XPTArena *arena, XPTC
     int i;
 
     if (!XPT_Do8(cursor, &md->flags) ||
         !XPT_DoCString(arena, cursor, &md->name) ||
         !XPT_Do8(cursor, &md->num_args))
         return PR_FALSE;
 
     if (mode == XPT_DECODE && md->num_args) {
-        md->params = XPT_CALLOC(arena, md->num_args * sizeof(XPTParamDescriptor));
+        md->params = (XPTParamDescriptor*)XPT_CALLOC(arena, md->num_args * sizeof(XPTParamDescriptor));
         if (!md->params)
             return PR_FALSE;
     }
 
     for(i = 0; i < md->num_args; i++) {
         if (!DoParamDescriptor(arena, cursor, &md->params[i], id))
             goto error;
     }
rename from xpcom/typelib/xpt/src/xpt_xdr.c
rename to xpcom/typelib/xpt/src/xpt_xdr.cpp
--- a/xpcom/typelib/xpt/src/xpt_xdr.c
+++ b/xpcom/typelib/xpt/src/xpt_xdr.cpp
@@ -162,17 +162,17 @@ XPT_NewXDRState(XPTMode mode, char *data
     state->pool->offset_map = XPT_NewHashTable(arena);
 
     if (!state->pool->offset_map)
         goto err_free_pool;
     if (mode == XPT_DECODE) {
         state->pool->data = data;
         state->pool->allocated = len;
     } else {
-        state->pool->data = XPT_MALLOC(arena, XPT_GROW_CHUNK);
+        state->pool->data = (char*)XPT_MALLOC(arena, XPT_GROW_CHUNK);
         if (!state->pool->data)
             goto err_free_hash;
         state->pool->allocated = XPT_GROW_CHUNK;
     }
 
     return state;
 
  err_free_hash:
@@ -244,17 +244,17 @@ GrowPool(XPTArena *arena, XPTDatapool *p
         XPT_ASSERT(exact > pool->allocated);
         total_size = exact;
     } else {
         total_size = pool->allocated + XPT_GROW_CHUNK;
         if (at_least > total_size)
             total_size = at_least;
     }
 
-    newdata = XPT_MALLOC(arena, total_size);
+    newdata = (char*)XPT_MALLOC(arena, total_size);
     if (!newdata)
         return PR_FALSE;
     if (pool->data) {
         if (old_size)
             memcpy(newdata, pool->data, old_size);
         XPT_FREE(arena, pool->data);
     }
     pool->data = newdata;
@@ -307,17 +307,17 @@ XPT_SeekTo(XPTCursor *cursor, uint32_t o
 XPT_PUBLIC_API(XPTString *)
 XPT_NewString(XPTArena *arena, uint16_t length, char *bytes)
 {
     XPTString *str = XPT_NEW(arena, XPTString);
     if (!str)
         return NULL;
     str->length = length;
     /* Alloc one extra to store the trailing nul. */
-    str->bytes = XPT_MALLOC(arena, length + 1u);
+    str->bytes = (char*)XPT_MALLOC(arena, length + 1u);
     if (!str->bytes) {
         XPT_DELETE(arena, str);
         return NULL;
     }
     memcpy(str->bytes, bytes, length);
     /* nul-terminate it. */
     str->bytes[length] = '\0';
     return str;
@@ -345,17 +345,17 @@ XPT_DoStringInline(XPTArena *arena, XPTC
             return PR_FALSE;
         *strp = str;
     }
 
     if (!XPT_Do16(cursor, &str->length))
         goto error;
 
     if (mode == XPT_DECODE)
-        if (!(str->bytes = XPT_MALLOC(arena, str->length + 1u)))
+        if (!(str->bytes = (char*)XPT_MALLOC(arena, str->length + 1u)))
             goto error;
 
     for (i = 0; i < str->length; i++)
         if (!XPT_Do8(cursor, (uint8_t *)&str->bytes[i]))
             goto error_2;
 
     if (mode == XPT_DECODE)
         str->bytes[str->length] = 0;
@@ -410,17 +410,17 @@ XPT_DoCString(XPTArena *arena, XPTCursor
         end = strchr(start, 0); /* find the end of the string */
         if (!end) {
             fprintf(stderr, "didn't find end of string on decode!\n");
             return PR_FALSE;
         }
         len = end - start;
         XPT_ASSERT(len > 0);
 
-        ident = XPT_MALLOC(arena, len + 1u);
+        ident = (char*)XPT_MALLOC(arena, len + 1u);
         if (!ident)
             return PR_FALSE;
 
         memcpy(ident, start, (size_t)len);
         ident[len] = 0;
         *identp = ident;
 
     } else {
rename from xpcom/typelib/xpt/tests/PrimitiveTest.c
rename to xpcom/typelib/xpt/tests/PrimitiveTest.cpp
--- a/xpcom/typelib/xpt/tests/PrimitiveTest.c
+++ b/xpcom/typelib/xpt/tests/PrimitiveTest.cpp
@@ -33,17 +33,17 @@ struct TestData {
     uint16_t      bit16;
     uint8_t       bit8[2];
     char	*cstr;
     XPTString   *str;
 } input = { 0xdeadbeef, 0xcafe, {0xba, 0xbe}, "foobar", &in_str},
   output = {0, 0, {0, 0}, NULL, NULL };
 
 void
-dump_struct(char *label, struct TestData *str)
+dump_struct(const char *label, struct TestData *str)
 {
     fprintf(stderr, "%s: {%#08x, %#04x, {%#02x, %#02x}, %s, %d/%s}\n",
 	    label, str->bit32, str->bit16, str->bit8[0], str->bit8[1],
 	    str->cstr, str->str->length, str->str->bytes);
 }
 
 PRBool
 XDR(XPTArena *arena, XPTCursor *cursor, struct TestData *str)
@@ -91,17 +91,17 @@ main(int argc, char **argv)
 
     fprintf(stderr, "XDR data %d bytes at %p:",
 	    dlen, data);
     for (i = 0; i < dlen; i++)
 	fprintf(stderr, "%c%02x/%c", i ? ',' : ' ', (uint8_t)data[i],
 		(uint8_t)data[i]);
     fprintf(stderr, "\n");
 
-    whole = malloc(dlen + hlen);
+    whole = (char*)malloc(dlen + hlen);
     if (!whole) {
 	fprintf(stderr, "malloc %d failed!\n", dlen + hlen);
 	return 1;
     }
 
     /* TRY_Q("malloc", (data2 = malloc(len))); */
     memcpy(whole, header, hlen);
     memcpy(whole + hlen, data, dlen);
rename from xpcom/typelib/xpt/tests/SimpleTypeLib.c
rename to xpcom/typelib/xpt/tests/SimpleTypeLib.cpp
--- a/xpcom/typelib/xpt/tests/moz.build
+++ b/xpcom/typelib/xpt/tests/moz.build
@@ -5,10 +5,10 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 SIMPLE_PROGRAMS = [
     'PrimitiveTest',
     'SimpleTypeLib',
 ]
 
 SOURCES += [
-    '%s.c' % s for s in SIMPLE_PROGRAMS
+    '%s.cpp' % s for s in SIMPLE_PROGRAMS
 ]