Bug 1248534 (part 3) - Remove almost all support for XPT annotations. r=khuey.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 22 Feb 2016 09:52:39 +1100
changeset 321856 14ba54064f33d9dc0dbcdca7ebd2dff582973fcf
parent 321855 475874efad984c2141afd6818007f48846999d46
child 321857 a0ce7857613ec423ec143fb3c22c3eee8646fd4e
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1248534
milestone47.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 1248534 (part 3) - Remove almost all support for XPT annotations. r=khuey. XPT supports annotations but xpt.py doesn't generate them except for a single empty annotation (to indicate there are no real annotations). So we can remove almost all support for them. This also allows XPTString to be removed.
xpcom/typelib/xpt/xpt_struct.cpp
xpcom/typelib/xpt/xpt_struct.h
xpcom/typelib/xpt/xpt_xdr.cpp
xpcom/typelib/xpt/xpt_xdr.h
--- a/xpcom/typelib/xpt/xpt_struct.cpp
+++ b/xpcom/typelib/xpt/xpt_struct.cpp
@@ -21,17 +21,17 @@ static PRBool
 DoConstDescriptor(XPTArena *arena, XPTCursor *cursor, XPTConstDescriptor *cd,
                   XPTInterfaceDescriptor *id);
 
 static PRBool
 DoMethodDescriptor(XPTArena *arena, XPTCursor *cursor, XPTMethodDescriptor *md, 
                    XPTInterfaceDescriptor *id);
 
 static PRBool
-DoAnnotation(XPTArena *arena, XPTCursor *cursor, XPTAnnotation **annp);
+DoAnnotations(XPTCursor *cursor);
 
 static PRBool
 DoInterfaceDescriptor(XPTArena *arena, XPTCursor *outer, XPTInterfaceDescriptor **idp);
 
 static PRBool
 DoTypeDescriptorPrefix(XPTArena *arena, XPTCursor *cursor, XPTTypeDescriptorPrefix *tdp);
 
 static PRBool
@@ -92,17 +92,16 @@ XPT_DoHeaderPrologue(XPTArena *arena, XP
 }
 
 XPT_PUBLIC_API(PRBool)
 XPT_DoHeader(XPTArena *arena, XPTCursor *cursor, XPTHeader **headerp)
 {
     XPTHeader * header;
     uint32_t ide_offset;
     int i;
-    XPTAnnotation *ann, *next, **annp;
 
     if (!XPT_DoHeaderPrologue(arena, cursor, headerp, &ide_offset))
         return PR_FALSE;
     header = *headerp;
     /* 
      * Make sure the file length reported in the header is the same size as
      * as our buffer unless it is zero (not set) 
      */
@@ -121,36 +120,18 @@ XPT_DoHeader(XPTArena *arena, XPTCursor 
     if (header->num_interfaces) {
         header->interface_directory = 
             (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.
-     */
-    ann = next = header->annotations;
-    annp = &header->annotations;
-    do {
-        ann = next;
-        if (!DoAnnotation(arena, cursor, &ann))
-            goto error;
-
-        /*
-         * Make sure that we store the address of the newly allocated
-         * annotation in the previous annotation's ``next'' slot, or
-         * header->annotations for the first one.
-         */
-        *annp = ann;
-        annp = &ann->next;
-        next = ann->next;
-    } while (!XPT_ANN_IS_LAST(ann->flags));
+    if (!DoAnnotations(cursor))
+        goto error;
 
     /* shouldn't be necessary now, but maybe later */
     XPT_SeekTo(cursor, ide_offset); 
 
     for (i = 0; i < header->num_interfaces; i++) {
         if (!DoInterfaceDirectoryEntry(arena, cursor, 
                                        &header->interface_directory[i]))
             goto error;
@@ -419,34 +400,23 @@ DoTypeDescriptor(XPTArena *arena, XPTCur
         break;
     }
     return PR_TRUE;
     
     XPT_ERROR_HANDLE(arena, td);    
 }
 
 PRBool
-DoAnnotation(XPTArena *arena, XPTCursor *cursor, XPTAnnotation **annp)
+DoAnnotations(XPTCursor *cursor)
 {
-    XPTAnnotation* ann = XPT_NEWZAP(arena, XPTAnnotation);
-    if (!ann)
+    uint8_t flags;
+    if (!XPT_Do8(cursor, &flags))
         return PR_FALSE;
-    *annp = ann;
 
-    if (!XPT_Do8(cursor, &ann->flags))
-        goto error;
-
-    if (XPT_ANN_IS_PRIVATE(ann->flags)) {
-        if (!XPT_DoStringInline(arena, cursor, &ann->creator) ||
-            !XPT_DoStringInline(arena, cursor, &ann->private_data))
-            goto error_2;
+    // All we handle now is a single, empty annotation.
+    if (XPT_ANN_IS_PRIVATE(flags) || !XPT_ANN_IS_LAST(flags)) {
+        fprintf(stderr, "private annotations are no longer handled\n");
+        return PR_FALSE;
     }
 
     return PR_TRUE;
-    
- error_2:
-    if (ann && XPT_ANN_IS_PRIVATE(ann->flags)) {
-        XPT_FREEIF(arena, ann->creator);
-        XPT_FREEIF(arena, ann->private_data);
-    }
-    XPT_ERROR_HANDLE(arena, ann);
 }
 
--- a/xpcom/typelib/xpt/xpt_struct.h
+++ b/xpcom/typelib/xpt/xpt_struct.h
@@ -30,18 +30,16 @@ extern "C" {
 typedef struct XPTHeader XPTHeader;
 typedef struct XPTInterfaceDirectoryEntry XPTInterfaceDirectoryEntry;
 typedef struct XPTInterfaceDescriptor XPTInterfaceDescriptor;
 typedef struct XPTConstDescriptor XPTConstDescriptor;
 typedef struct XPTMethodDescriptor XPTMethodDescriptor;
 typedef struct XPTParamDescriptor XPTParamDescriptor;
 typedef struct XPTTypeDescriptor XPTTypeDescriptor;
 typedef struct XPTTypeDescriptorPrefix XPTTypeDescriptorPrefix;
-typedef struct XPTString XPTString;
-typedef struct XPTAnnotation XPTAnnotation;
 
 #ifndef nsID_h__
 /*
  * We can't include nsID.h, because it's full of C++ goop and we're not doing
  * C++ here, so we define our own minimal struct.  We protect against multiple
  * definitions of this struct, though, and use the same field naming.
  */
 struct nsID {
@@ -60,17 +58,16 @@ typedef struct nsID nsID;
 struct XPTHeader {
     uint8_t                     magic[16];
     uint8_t                     major_version;
     uint8_t                     minor_version;
     uint16_t                    num_interfaces;
     uint32_t                    file_length;
     XPTInterfaceDirectoryEntry  *interface_directory;
     uint32_t                    data_pool;
-    XPTAnnotation               *annotations;
 };
 
 #define XPT_MAGIC "XPCOM\nTypeLib\r\n\032"
 /* For error messages. */
 #define XPT_MAGIC_STRING "XPCOM\\nTypeLib\\r\\n\\032"
 #define XPT_MAJOR_VERSION 0x01
 #define XPT_MINOR_VERSION 0x02
 
@@ -144,25 +141,16 @@ struct XPTInterfaceDescriptor {
 #define XPT_ID_IS_FUNCTION(flags) (!!(flags & XPT_ID_FUNCTION))
 #define XPT_ID_IS_BUILTINCLASS(flags) (!!(flags & XPT_ID_BUILTINCLASS))
 #define XPT_ID_IS_MAIN_PROCESS_SCRIPTABLE_ONLY(flags) (!!(flags & XPT_ID_MAIN_PROCESS_SCRIPTABLE_ONLY))
 
 extern XPT_PUBLIC_API(PRBool)
 XPT_InterfaceDescriptorAddTypes(XPTArena *arena, XPTInterfaceDescriptor *id, 
                                 uint16_t num);
 
-/*
- * This is our special string struct with a length value associated with it,
- * which means that it can contains embedded NULs.
- */
-struct XPTString {
-    uint16_t length;
-    char   *bytes;
-};
-
 /* 
  * A TypeDescriptor is a variable-size record used to identify the type of a 
  * method argument or return value. 
  *
  * There are three types of TypeDescriptors:
  *
  * SimpleTypeDescriptor
  * InterfaceTypeDescriptor
@@ -257,17 +245,16 @@ union XPTConstValue {
     int64_t   i64; 
     uint64_t  ui64; 
     float     flt;
     double    dbl;
     PRBool    bul;
     char      ch; 
     uint16_t  wch;
     nsID      *iid;
-    XPTString *string;
     char      *str;
     uint16_t  *wstr;
 }; /* varies according to type */
 
 struct XPTConstDescriptor {
     char                *name;
     XPTTypeDescriptor   type;
     union XPTConstValue value;
@@ -338,26 +325,21 @@ struct XPTMethodDescriptor {
  * EmptyAnnotation
  * PrivateAnnotation
  *
  * The tag field of the prefix discriminates among the variant record 
  * types for Annotation's.  If the tag is 0, this record is an 
  * EmptyAnnotation. EmptyAnnotation's are ignored - they're only used to 
  * indicate an array of Annotation's that's completely empty.  If the tag 
  * is 1, the record is a PrivateAnnotation. 
+ *
+ * WARNING: we no longer support PrivateAnnotations. Each typelib can now only
+ * contain a single EmptyAnnotation.
  */
 
-struct XPTAnnotation {
-    XPTAnnotation *next;
-    uint8_t       flags;
-    /* remaining fields are present in typelib iff XPT_ANN_IS_PRIVATE */
-    XPTString     *creator;
-    XPTString     *private_data;
-};
-
 #define XPT_ANN_LAST	                0x80
 #define XPT_ANN_IS_LAST(flags)          (flags & XPT_ANN_LAST)
 #define XPT_ANN_PRIVATE                 0x40
 #define XPT_ANN_IS_PRIVATE(flags)       (flags & XPT_ANN_PRIVATE)
 
 }
 
 #endif /* __xpt_struct_h__ */
--- a/xpcom/typelib/xpt/xpt_xdr.cpp
+++ b/xpcom/typelib/xpt/xpt_xdr.cpp
@@ -115,48 +115,16 @@ XPT_PUBLIC_API(PRBool)
 XPT_SeekTo(XPTCursor *cursor, uint32_t offset)
 {
     /* XXX do some real checking and update len and stuff */
     cursor->offset = offset;
     return PR_TRUE;
 }
 
 XPT_PUBLIC_API(PRBool)
-XPT_DoStringInline(XPTArena *arena, XPTCursor *cursor, XPTString **strp)
-{
-    XPTString *str = *strp;
-    int i;
-
-    str = XPT_NEWZAP(arena, XPTString);
-    if (!str)
-        return PR_FALSE;
-    *strp = str;
-
-    if (!XPT_Do16(cursor, &str->length))
-        goto error;
-
-    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;
-
-    str->bytes[str->length] = 0;
-
-    return PR_TRUE;
-
- error_2:
-    XPT_DELETE(arena, str->bytes);
- error:
-    XPT_DELETE(arena, str);
-    return PR_FALSE;
-}
-
-XPT_PUBLIC_API(PRBool)
 XPT_DoCString(XPTArena *arena, XPTCursor *cursor, char **identp)
 {
     uint32_t offset = 0;
     if (!XPT_Do32(cursor, &offset))
         return PR_FALSE;
 
     if (!offset) {
         *identp = NULL;
--- a/xpcom/typelib/xpt/xpt_xdr.h
+++ b/xpcom/typelib/xpt/xpt_xdr.h
@@ -16,19 +16,16 @@
 extern "C" {
 #endif
 
 typedef struct XPTState         XPTState;
 typedef struct XPTDatapool      XPTDatapool;
 typedef struct XPTCursor        XPTCursor;
 
 extern XPT_PUBLIC_API(PRBool)
-XPT_DoStringInline(XPTArena *arena, XPTCursor *cursor, XPTString **strp);
-
-extern XPT_PUBLIC_API(PRBool)
 XPT_DoCString(XPTArena *arena, XPTCursor *cursor, char **strp);
 
 extern XPT_PUBLIC_API(PRBool)
 XPT_DoIID(XPTCursor *cursor, nsID *iidp);
 
 extern XPT_PUBLIC_API(PRBool)
 XPT_Do64(XPTCursor *cursor, int64_t *u64p);