Bug 1438257, part 3 - C++-ize XPT files. r=froydnj
These are nominally in C, but I don't see any reason for that, given
that we no longer have external consumers. I got rid of "typedef
struct Foo Foo" at the same time.
Also replace a tab I noticed in the definnition of XPT_ANN_LAST.
MozReview-Commit-ID: CFgfiWmuo6r
--- a/xpcom/typelib/xpt/xpt_arena.h
+++ b/xpcom/typelib/xpt/xpt_arena.h
@@ -10,25 +10,21 @@
#ifndef __xpt_arena_h__
#define __xpt_arena_h__
#include <stdlib.h>
#include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h"
#include <stdint.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* Simple Arena support. Use with caution!
*/
-typedef struct XPTArena XPTArena;
+struct XPTArena;
XPTArena*
XPT_NewArena(size_t block_size8, size_t block_size1);
void
XPT_DestroyArena(XPTArena *arena);
void*
@@ -50,13 +46,9 @@ void
XPT_AssertFailed(const char *s, const char *file, uint32_t lineno)
MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS;
#define XPT_ASSERT(_expr) \
((_expr)?((void)0):XPT_AssertFailed(# _expr, __FILE__, __LINE__))
#else
#define XPT_ASSERT(_expr) ((void)0)
#endif
-#ifdef __cplusplus
-}
-#endif
-
#endif /* __xpt_arena_h__ */
--- a/xpcom/typelib/xpt/xpt_struct.h
+++ b/xpcom/typelib/xpt/xpt_struct.h
@@ -9,37 +9,35 @@
*/
#ifndef __xpt_struct_h__
#define __xpt_struct_h__
#include "xpt_arena.h"
#include <stdint.h>
-extern "C" {
-
/*
* Originally, I was going to have structures that exactly matched the on-disk
* representation, but that proved difficult: different compilers can pack
* their structs differently, and that makes overlaying them atop a
* read-from-disk byte buffer troublesome. So now I just have some structures
* that are used in memory, and we're going to write a nice XDR library to
* write them to disk and stuff. It is pure joy. -- shaver
*/
/* Structures for the typelib components */
-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;
+struct XPTHeader;
+struct XPTInterfaceDirectoryEntry;
+struct XPTInterfaceDescriptor;
+struct XPTConstDescriptor;
+struct XPTMethodDescriptor;
+struct XPTParamDescriptor;
+struct XPTTypeDescriptor;
+struct XPTTypeDescriptorPrefix;
#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 {
@@ -351,16 +349,14 @@ struct XPTMethodDescriptor {
* 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.
*
* We don't actually store annotations; we just skip over them if they are
* present.
*/
-#define XPT_ANN_LAST 0x80
+#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.h
+++ b/xpcom/typelib/xpt/xpt_xdr.h
@@ -10,22 +10,18 @@
#ifndef __xpt_xdr_h__
#define __xpt_xdr_h__
#include "xpt_struct.h"
#include "mozilla/NotNull.h"
using mozilla::NotNull;
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct XPTState XPTState;
-typedef struct XPTCursor XPTCursor;
+struct XPTState;
+struct XPTCursor;
bool
XPT_SkipStringInline(NotNull<XPTCursor*> cursor);
bool
XPT_DoCString(XPTArena *arena, NotNull<XPTCursor*> cursor, char **strp,
bool ignore = false);
@@ -42,20 +38,20 @@ bool
XPT_Do16(NotNull<XPTCursor*> cursor, uint16_t *u16p);
bool
XPT_Do8(NotNull<XPTCursor*> cursor, uint8_t *u8p);
bool
XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor*> cursor, XPTHeader **headerp);
-typedef enum {
+enum XPTPool {
XPT_HEADER = 0,
XPT_DATA = 1
-} XPTPool;
+};
struct XPTState {
uint32_t data_offset;
uint32_t next_cursor[2];
char *pool_data;
uint32_t pool_allocated;
};
@@ -74,13 +70,9 @@ XPT_MakeCursor(XPTState *state, XPTPool
NotNull<XPTCursor*> cursor);
bool
XPT_SeekTo(NotNull<XPTCursor*> cursor, uint32_t offset);
void
XPT_SetDataOffset(XPTState *state, uint32_t data_offset);
-#ifdef __cplusplus
-}
-#endif
-
#endif /* __xpt_xdr_h__ */