Make libdex structures tool friendly.

Previously, the struct name and its typedef name were identical.  This
confuses emacs and etags.  This change eliminates the typedef names and
removes the extern "C" wrapping the libdex header files.  To support
this change the transitive C dependencies have been made to compile as
C++ instead.

Change-Id: I7065f32d61d776f9b09c7b461adf2502268d852f
diff --git a/dalvikvm/Android.mk b/dalvikvm/Android.mk
index b7dda0f..5960a4b 100644
--- a/dalvikvm/Android.mk
+++ b/dalvikvm/Android.mk
@@ -20,7 +20,7 @@
 #
 
 dalvikvm_src_files := \
-    Main.c
+    Main.cpp
 
 dalvikvm_c_includes := \
     $(JNI_H_INCLUDE) \
diff --git a/dalvikvm/Main.c b/dalvikvm/Main.cpp
similarity index 86%
rename from dalvikvm/Main.c
rename to dalvikvm/Main.cpp
index 666317c..4aa6e20 100644
--- a/dalvikvm/Main.c
+++ b/dalvikvm/Main.cpp
@@ -48,14 +48,14 @@
     jobjectArray result = NULL;
     int i;
 
-    stringClass = (*env)->FindClass(env, "java/lang/String");
-    if ((*env)->ExceptionCheck(env)) {
+    stringClass = env->FindClass("java/lang/String");
+    if (env->ExceptionCheck()) {
         fprintf(stderr, "Got exception while finding class String\n");
         goto bail;
     }
     assert(stringClass != NULL);
-    strArray = (*env)->NewObjectArray(env, argc, stringClass, NULL);
-    if ((*env)->ExceptionCheck(env)) {
+    strArray = env->NewObjectArray(argc, stringClass, NULL);
+    if (env->ExceptionCheck()) {
         fprintf(stderr, "Got exception while creating String array\n");
         goto bail;
     }
@@ -64,14 +64,14 @@
     for (i = 0; i < argc; i++) {
         jstring argStr;
 
-        argStr = (*env)->NewStringUTF(env, argv[i]);
-        if ((*env)->ExceptionCheck(env)) {
+        argStr = env->NewStringUTF(argv[i]);
+        if (env->ExceptionCheck()) {
             fprintf(stderr, "Got exception while allocating Strings\n");
             goto bail;
         }
         assert(argStr != NULL);
-        (*env)->SetObjectArrayElement(env, strArray, i, argStr);
-        (*env)->DeleteLocalRef(env, argStr);
+        env->SetObjectArrayElement(strArray, i, argStr);
+        env->DeleteLocalRef(argStr);
     }
 
     /* return the array, and ensure we don't delete the local ref to it */
@@ -79,8 +79,8 @@
     strArray = NULL;
 
 bail:
-    (*env)->DeleteLocalRef(env, stringClass);
-    (*env)->DeleteLocalRef(env, strArray);
+    env->DeleteLocalRef(stringClass);
+    env->DeleteLocalRef(strArray);
     return result;
 }
 
@@ -98,7 +98,7 @@
     int modifiers;
     int result = JNI_FALSE;
 
-    refMethod = (*env)->ToReflectedMethod(env, clazz, methodId, JNI_FALSE);
+    refMethod = env->ToReflectedMethod(clazz, methodId, JNI_FALSE);
     if (refMethod == NULL) {
         fprintf(stderr, "Dalvik VM unable to get reflected method\n");
         goto bail;
@@ -108,19 +108,19 @@
      * We now have a Method instance.  We need to call
      * its getModifiers() method.
      */
-    methodClass = (*env)->FindClass(env, "java/lang/reflect/Method");
+    methodClass = env->FindClass("java/lang/reflect/Method");
     if (methodClass == NULL) {
         fprintf(stderr, "Dalvik VM unable to find class Method\n");
         goto bail;
     }
-    getModifiersId = (*env)->GetMethodID(env, methodClass,
+    getModifiersId = env->GetMethodID(methodClass,
                         "getModifiers", "()I");
     if (getModifiersId == NULL) {
         fprintf(stderr, "Dalvik VM unable to find reflect.Method.getModifiers\n");
         goto bail;
     }
 
-    modifiers = (*env)->CallIntMethod(env, refMethod, getModifiersId);
+    modifiers = env->CallIntMethod(refMethod, getModifiersId);
     if ((modifiers & PUBLIC) == 0) {
         fprintf(stderr, "Dalvik VM: main() is not public\n");
         goto bail;
@@ -129,8 +129,8 @@
     result = JNI_TRUE;
 
 bail:
-    (*env)->DeleteLocalRef(env, refMethod);
-    (*env)->DeleteLocalRef(env, methodClass);
+    env->DeleteLocalRef(refMethod);
+    env->DeleteLocalRef(methodClass);
     return result;
 }
 
@@ -246,13 +246,13 @@
         if (*cp == '.')
             *cp = '/';
 
-    startClass = (*env)->FindClass(env, slashClass);
+    startClass = env->FindClass(slashClass);
     if (startClass == NULL) {
         fprintf(stderr, "Dalvik VM unable to locate class '%s'\n", slashClass);
         goto bail;
     }
 
-    startMeth = (*env)->GetStaticMethodID(env, startClass,
+    startMeth = env->GetStaticMethodID(startClass,
                     "main", "([Ljava/lang/String;)V");
     if (startMeth == NULL) {
         fprintf(stderr, "Dalvik VM unable to find static main(String[]) in '%s'\n",
@@ -270,9 +270,9 @@
     /*
      * Invoke main().
      */
-    (*env)->CallStaticVoidMethod(env, startClass, startMeth, strArray);
+    env->CallStaticVoidMethod(startClass, startMeth, strArray);
 
-    if (!(*env)->ExceptionCheck(env))
+    if (!env->ExceptionCheck())
         result = 0;
 
 bail:
@@ -282,12 +282,12 @@
          * This allows join() and isAlive() on the main thread to work
          * correctly, and also provides uncaught exception handling.
          */
-        if ((*vm)->DetachCurrentThread(vm) != JNI_OK) {
+        if (vm->DetachCurrentThread() != JNI_OK) {
             fprintf(stderr, "Warning: unable to detach main thread\n");
             result = 1;
         }
 
-        if ((*vm)->DestroyJavaVM(vm) != 0)
+        if (vm->DestroyJavaVM() != 0)
             fprintf(stderr, "Warning: Dalvik VM did not shut down cleanly\n");
         /*printf("\nDalvik VM has exited\n");*/
     }
diff --git a/dexdump/Android.mk b/dexdump/Android.mk
index 58fa137..e47acfa 100644
--- a/dexdump/Android.mk
+++ b/dexdump/Android.mk
@@ -18,7 +18,7 @@
 LOCAL_PATH:= $(call my-dir)
 
 dexdump_src_files := \
-		DexDump.c
+		DexDump.cpp
 
 dexdump_c_includes := \
 		dalvik \
diff --git a/dexdump/DexDump.c b/dexdump/DexDump.cpp
similarity index 98%
rename from dexdump/DexDump.c
rename to dexdump/DexDump.cpp
index 9353471..7d11752 100644
--- a/dexdump/DexDump.c
+++ b/dexdump/DexDump.cpp
@@ -52,13 +52,13 @@
 
 static const char* gProgName = "dexdump";
 
-typedef enum OutputFormat {
+enum OutputFormat {
     OUTPUT_PLAIN = 0,               /* default */
     OUTPUT_XML,                     /* fancy */
-} OutputFormat;
+};
 
 /* command-line options */
-struct {
+struct Options {
     bool checksumOnly;
     bool disassemble;
     bool showFileHeaders;
@@ -69,14 +69,16 @@
     const char* tempFileName;
     bool exportsOnly;
     bool verbose;
-} gOptions;
+};
+
+struct Options gOptions;
 
 /* basic info about a field or method */
-typedef struct FieldMethodInfo {
+struct FieldMethodInfo {
     const char* classDescriptor;
     const char* name;
     const char* signature;
-} FieldMethodInfo;
+};
 
 /*
  * Get 2 little-endian bytes.
@@ -150,7 +152,7 @@
         }
     }
 
-    newStr = malloc(targetLen + arrayDepth * 2 +1);
+    newStr = (char*)malloc(targetLen + arrayDepth * 2 +1);
 
     /* copy class name over */
     int i;
@@ -825,7 +827,7 @@
          * size, so we add explicit space for it here.
          */
         outSize++;
-        buf = malloc(outSize);
+        buf = (char*)malloc(outSize);
         if (buf == NULL) {
             return NULL;
         }
@@ -1647,7 +1649,7 @@
  */
 void dumpRegisterMaps(DexFile* pDexFile)
 {
-    const u1* pClassPool = pDexFile->pRegisterMapPool;
+    const u1* pClassPool = (const u1*)pDexFile->pRegisterMapPool;
     const u4* classOffsets;
     const u1* ptr;
     u4 numClasses;
@@ -1781,15 +1783,16 @@
     if (gOptions.verbose)
         printf("Processing '%s'...\n", fileName);
 
-    if (dexOpenAndMap(fileName, gOptions.tempFileName, &map, false) != 0)
-        goto bail;
+    if (dexOpenAndMap(fileName, gOptions.tempFileName, &map, false) != 0) {
+        return result;
+    }
     mapped = true;
 
     int flags = kDexParseVerifyChecksum;
     if (gOptions.ignoreBadChecksum)
         flags |= kDexParseContinueOnError;
 
-    pDexFile = dexFileParse(map.addr, map.length, flags);
+    pDexFile = dexFileParse((u1*)map.addr, map.length, flags);
     if (pDexFile == NULL) {
         fprintf(stderr, "ERROR: DEX parse failed\n");
         goto bail;
diff --git a/dexlist/Android.mk b/dexlist/Android.mk
index aacdfb5..a7dd6e2 100644
--- a/dexlist/Android.mk
+++ b/dexlist/Android.mk
@@ -18,7 +18,7 @@
 LOCAL_PATH:= $(call my-dir)
 
 dexdump_src_files := \
-		DexList.c
+		DexList.cpp
 
 dexdump_c_includes := \
 		dalvik \
diff --git a/dexlist/DexList.c b/dexlist/DexList.cpp
similarity index 97%
rename from dexlist/DexList.c
rename to dexlist/DexList.cpp
index 5326692..03f0230 100644
--- a/dexlist/DexList.c
+++ b/dexlist/DexList.cpp
@@ -63,7 +63,7 @@
         str++; /* Skip the 'L'. */
     }
 
-    newStr = malloc(at + 1); /* Add one for the '\0'. */
+    newStr = (char*)malloc(at + 1); /* Add one for the '\0'. */
     newStr[at] = '\0';
 
     while (at > 0) {
@@ -217,7 +217,7 @@
     }
     mapped = true;
 
-    pDexFile = dexFileParse(map.addr, map.length, kDexParseDefault);
+    pDexFile = dexFileParse((u1*)map.addr, map.length, kDexParseDefault);
     if (pDexFile == NULL) {
         fprintf(stderr, "Warning: DEX parse failed for '%s'\n", fileName);
         goto bail;
diff --git a/dexopt/Android.mk b/dexopt/Android.mk
index 3bb98a5..241893a 100644
--- a/dexopt/Android.mk
+++ b/dexopt/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_PATH:= $(call my-dir)
 
 local_src_files := \
-		OptMain.c
+		OptMain.cpp
 
 local_c_includes := \
 		dalvik \
diff --git a/dexopt/OptMain.c b/dexopt/OptMain.cpp
similarity index 98%
rename from dexopt/OptMain.c
rename to dexopt/OptMain.cpp
index 7ecd1e0..a7a898d 100644
--- a/dexopt/OptMain.c
+++ b/dexopt/OptMain.cpp
@@ -65,6 +65,9 @@
     off_t dexOffset;
     int err;
     int result = -1;
+    int dexoptFlags = 0;        /* bit flags, from enum DexoptFlags */
+    DexClassVerifyMode verifyMode = VERIFY_MODE_ALL;
+    DexOptimizerMode dexOptMode = OPTIMIZE_MODE_VERIFIED;
 
     memset(&zippy, 0, sizeof(zippy));
 
@@ -126,11 +129,6 @@
     }
 
     /* Parse the options. */
-
-    DexClassVerifyMode verifyMode = VERIFY_MODE_ALL;
-    DexOptimizerMode dexOptMode = OPTIMIZE_MODE_VERIFIED;
-    int dexoptFlags = 0;        /* bit flags, from enum DexoptFlags */
-
     if (dexoptFlagStr[0] != '\0') {
         const char* opc;
         const char* val;
@@ -208,7 +206,6 @@
 static int processZipFile(int zipFd, int cacheFd, const char* zipName,
         const char *dexoptFlags)
 {
-    int result = -1;
     char* bcpCopy = NULL;
 
     /*
@@ -218,7 +215,7 @@
     const char* bcp = getenv("BOOTCLASSPATH");
     if (bcp == NULL) {
         LOGE("DexOptZ: BOOTCLASSPATH not set\n");
-        goto bail;
+        return -1;
     }
 
     bool isBootstrap = false;
@@ -248,10 +245,9 @@
         isBootstrap = true;
     }
 
-    result = extractAndProcessZip(zipFd, cacheFd, zipName, isBootstrap,
+    int result = extractAndProcessZip(zipFd, cacheFd, zipName, isBootstrap,
             bcp, dexoptFlags);
 
-bail:
     free(bcpCopy);
     return result;
 }
@@ -348,7 +344,7 @@
          */
         fprintf(stderr, "Wrong number of args for --preopt (found %d)\n",
                 argc);
-        goto bail;
+        return -1;
     }
 
     const char* zipName = argv[2];
@@ -359,13 +355,13 @@
         strstr(dexoptFlags, "u=n") == NULL)
     {
         fprintf(stderr, "Either 'u=y' or 'u=n' must be specified\n");
-        goto bail;
+        return -1;
     }
 
     zipFd = open(zipName, O_RDONLY);
     if (zipFd < 0) {
         perror(argv[0]);
-        goto bail;
+        return -1;
     }
 
     outFd = open(outName, O_RDWR | O_EXCL | O_CREAT, 0666);
@@ -427,6 +423,9 @@
     const char* debugFileName;
     u4 crc, modWhen;
     char* endp;
+    bool onlyOptVerifiedDex = false;
+    DexClassVerifyMode verifyMode;
+    DexOptimizerMode dexOptMode;
 
     if (argc < 10) {
         /* don't have all mandatory args */
@@ -492,9 +491,6 @@
     LOGV("  bootclasspath is '%s'\n", bootClassPath);
 
     /* start the VM partway */
-    bool onlyOptVerifiedDex = false;
-    DexClassVerifyMode verifyMode;
-    DexOptimizerMode dexOptMode;
 
     /* ugh -- upgrade these to a bit field if they get any more complex */
     if ((flags & DEXOPT_VERIFY_ENABLED) != 0) {
diff --git a/dvz/Android.mk b/dvz/Android.mk
index 4e4387e..22d0950 100644
--- a/dvz/Android.mk
+++ b/dvz/Android.mk
@@ -4,7 +4,7 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-  	dvz.c
+	dvz.cpp
 
 LOCAL_SHARED_LIBRARIES := \
 	libcutils
diff --git a/dvz/dvz.c b/dvz/dvz.cpp
similarity index 100%
rename from dvz/dvz.c
rename to dvz/dvz.cpp
diff --git a/libdex/CmdUtils.h b/libdex/CmdUtils.h
index 3f05aff..62ce73a 100644
--- a/libdex/CmdUtils.h
+++ b/libdex/CmdUtils.h
@@ -31,12 +31,8 @@
 #ifndef _LIBDEX_CMDUTILS
 #define _LIBDEX_CMDUTILS
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* encode the result of unzipping to a file */
-typedef enum UnzipToFileResult {
+enum UnzipToFileResult {
     kUTFRSuccess = 0,
     kUTFRGenericFailure,
     kUTFRBadArgs,
@@ -44,7 +40,7 @@
     kUTFRNoClassesDex,
     kUTFROutputFileProblem,
     kUTFRBadZip,
-} UnzipToFileResult;
+};
 
 /*
  * Map the specified DEX file read-only (possibly after expanding it into a
@@ -74,8 +70,4 @@
 UnzipToFileResult dexUnzipToFile(const char* zipFileName,
     const char* outFileName, bool quiet);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_CMDUTILS*/
diff --git a/libdex/DexCatch.h b/libdex/DexCatch.h
index 7c40bc5..19ea541 100644
--- a/libdex/DexCatch.h
+++ b/libdex/DexCatch.h
@@ -24,17 +24,13 @@
 #include "DexFile.h"
 #include "Leb128.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Catch handler entry, used while iterating over catch_handler_items.
  */
-typedef struct DexCatchHandler {
+struct DexCatchHandler {
     u4          typeIdx;    /* type index of the caught exception type */
     u4          address;    /* handler address */
-} DexCatchHandler;
+};
 
 /* Get the first handler offset for the given DexCode.
  * It's not 0 because the handlers list is prefixed with its size
@@ -48,12 +44,12 @@
  * Iterator over catch handler data. This structure should be treated as
  * opaque.
  */
-typedef struct DexCatchIterator {
+struct DexCatchIterator {
     const u1* pEncodedData;
     bool catchesAll;
     u4 countRemaining;
     DexCatchHandler handler;
-} DexCatchIterator;
+};
 
 /* Initialize a DexCatchIterator to emptiness. This mostly exists to
  * squelch innocuous warnings. */
@@ -163,8 +159,4 @@
     }
 }
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
diff --git a/libdex/DexClass.h b/libdex/DexClass.h
index 6003fcf..d2d92c0 100644
--- a/libdex/DexClass.h
+++ b/libdex/DexClass.h
@@ -24,41 +24,37 @@
 #include "DexFile.h"
 #include "Leb128.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* expanded form of a class_data_item header */
-typedef struct DexClassDataHeader {
+struct DexClassDataHeader {
     u4 staticFieldsSize;
     u4 instanceFieldsSize;
     u4 directMethodsSize;
     u4 virtualMethodsSize;
-} DexClassDataHeader;
+};
 
 /* expanded form of encoded_field */
-typedef struct DexField {
+struct DexField {
     u4 fieldIdx;    /* index to a field_id_item */
     u4 accessFlags;
-} DexField;
+};
 
 /* expanded form of encoded_method */
-typedef struct DexMethod {
+struct DexMethod {
     u4 methodIdx;    /* index to a method_id_item */
     u4 accessFlags;
     u4 codeOff;      /* file offset to a code_item */
-} DexMethod;
+};
 
 /* expanded form of class_data_item. Note: If a particular item is
  * absent (e.g., no static fields), then the corresponding pointer
  * is set to NULL. */
-typedef struct DexClassData {
+struct DexClassData {
     DexClassDataHeader header;
     DexField*          staticFields;
     DexField*          instanceFields;
     DexMethod*         directMethods;
     DexMethod*         virtualMethods;
-} DexClassData;
+};
 
 /* Read and verify the header of a class_data_item. This updates the
  * given data pointer to point past the end of the read data and
@@ -163,8 +159,4 @@
     *lastIndex = index;
 }
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
diff --git a/libdex/DexDataMap.h b/libdex/DexDataMap.h
index 654933c..359d3ad 100644
--- a/libdex/DexDataMap.h
+++ b/libdex/DexDataMap.h
@@ -23,16 +23,12 @@
 
 #include "DexFile.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct DexDataMap {
+struct DexDataMap {
     u4 count;    /* number of items currently in the map */
     u4 max;      /* maximum number of items that may be held */
     u4* offsets; /* array of item offsets */
     u2* types;   /* corresponding array of item types */
-} DexDataMap;
+};
 
 /*
  * Allocate and initialize a DexDataMap. Returns NULL on failure.
@@ -74,8 +70,4 @@
     return dexDataMapVerify(map, offset, type);
 }
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_DEXDATAMAP*/
diff --git a/libdex/DexDebugInfo.cpp b/libdex/DexDebugInfo.cpp
index c33a1e4..cbb58d4 100644
--- a/libdex/DexDebugInfo.cpp
+++ b/libdex/DexDebugInfo.cpp
@@ -109,13 +109,13 @@
     }
 }
 
-typedef struct LocalInfo {
+struct LocalInfo {
     const char *name;
     const char *descriptor;
     const char *signature;
     u2 startAddress;
     bool live;
-} LocalInfo;
+};
 
 static void emitLocalCbIfLive(void *cnxt, int reg, u4 endAddress,
         LocalInfo *localInReg, DexDebugNewLocalCb localCb)
diff --git a/libdex/DexDebugInfo.h b/libdex/DexDebugInfo.h
index c510c57..9ab67f5 100644
--- a/libdex/DexDebugInfo.h
+++ b/libdex/DexDebugInfo.h
@@ -23,10 +23,6 @@
 
 #include "DexFile.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Callback for "new position table entry".
  * Returning non-0 causes the decoder to stop early.
@@ -56,8 +52,4 @@
             DexDebugNewPositionCb posCb, DexDebugNewLocalCb localCb,
             void* cnxt);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /* def _LIBDEX_DEXDEBUGINFO */
diff --git a/libdex/DexFile.h b/libdex/DexFile.h
index 6652286..4a090e1 100644
--- a/libdex/DexFile.h
+++ b/libdex/DexFile.h
@@ -36,10 +36,6 @@
 #include "vm/Common.h"      // basic type defs, e.g. u1/u2/u4/u8, and LOG
 #include "libdex/SysUtil.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * gcc-style inline management -- ensures we have a copy of all functions
  * in the library, so code that links against us will work whether or not
@@ -77,7 +73,7 @@
 /*
  * Enumeration of all the primitive types.
  */
-typedef enum PrimitiveType {
+enum PrimitiveType {
     PRIM_NOT        = 0,       /* value is a reference type, not a primitive type */
     PRIM_VOID       = 1,
     PRIM_BOOLEAN    = 2,
@@ -88,7 +84,7 @@
     PRIM_LONG       = 7,
     PRIM_FLOAT      = 8,
     PRIM_DOUBLE     = 9,
-} PrimitiveType;
+};
 
 /*
  * access flags and masks; the "standard" ones are all <= 0x4000
@@ -210,7 +206,7 @@
 /*
  * Direct-mapped "header_item" struct.
  */
-typedef struct DexHeader {
+struct DexHeader {
     u1  magic[8];           /* includes version number */
     u4  checksum;           /* adler32 checksum */
     u1  signature[kSHA1DigestLen]; /* SHA-1 hash */
@@ -234,71 +230,71 @@
     u4  classDefsOff;
     u4  dataSize;
     u4  dataOff;
-} DexHeader;
+};
 
 /*
  * Direct-mapped "map_item".
  */
-typedef struct DexMapItem {
-    u2  type;              /* type code (see kDexType* above) */
-    u2  unused;
-    u4  size;              /* count of items of the indicated type */
-    u4  offset;            /* file offset to the start of data */
-} DexMapItem;
+struct DexMapItem {
+    u2 type;              /* type code (see kDexType* above) */
+    u2 unused;
+    u4 size;              /* count of items of the indicated type */
+    u4 offset;            /* file offset to the start of data */
+};
 
 /*
  * Direct-mapped "map_list".
  */
-typedef struct DexMapList {
+struct DexMapList {
     u4  size;               /* #of entries in list */
     DexMapItem list[1];     /* entries */
-} DexMapList;
+};
 
 /*
  * Direct-mapped "string_id_item".
  */
-typedef struct DexStringId {
-    u4  stringDataOff;      /* file offset to string_data_item */
-} DexStringId;
+struct DexStringId {
+    u4 stringDataOff;      /* file offset to string_data_item */
+};
 
 /*
  * Direct-mapped "type_id_item".
  */
-typedef struct DexTypeId {
+struct DexTypeId {
     u4  descriptorIdx;      /* index into stringIds list for type descriptor */
-} DexTypeId;
+};
 
 /*
  * Direct-mapped "field_id_item".
  */
-typedef struct DexFieldId {
+struct DexFieldId {
     u2  classIdx;           /* index into typeIds list for defining class */
     u2  typeIdx;            /* index into typeIds for field type */
     u4  nameIdx;            /* index into stringIds for field name */
-} DexFieldId;
+};
 
 /*
  * Direct-mapped "method_id_item".
  */
-typedef struct DexMethodId {
+struct DexMethodId {
     u2  classIdx;           /* index into typeIds list for defining class */
     u2  protoIdx;           /* index into protoIds for method prototype */
     u4  nameIdx;            /* index into stringIds for method name */
-} DexMethodId;
+};
 
 /*
  * Direct-mapped "proto_id_item".
  */
-typedef struct DexProtoId {
+struct DexProtoId {
     u4  shortyIdx;          /* index into stringIds for shorty descriptor */
     u4  returnTypeIdx;      /* index into typeIds list for return type */
     u4  parametersOff;      /* file offset to type_list for parameter types */
-} DexProtoId;
+};
 
 /*
  * Direct-mapped "class_def_item".
  */
-typedef struct DexClassDef {
+struct DexClassDef {
     u4  classIdx;           /* index into typeIds for this class */
     u4  accessFlags;
     u4  superclassIdx;      /* index into typeIds for superclass */
@@ -307,22 +303,22 @@
     u4  annotationsOff;     /* file offset to annotations_directory_item */
     u4  classDataOff;       /* file offset to class_data_item */
     u4  staticValuesOff;    /* file offset to DexEncodedArray */
-} DexClassDef;
+};
 
 /*
  * Direct-mapped "type_item".
  */
-typedef struct DexTypeItem {
+struct DexTypeItem {
     u2  typeIdx;            /* index into typeIds */
-} DexTypeItem;
+};
 
 /*
  * Direct-mapped "type_list".
  */
-typedef struct DexTypeList {
+struct DexTypeList {
     u4  size;               /* #of entries in list */
     DexTypeItem list[1];    /* entries */
-} DexTypeList;
+};
 
 /*
  * Direct-mapped "code_item".
@@ -331,7 +327,7 @@
  * "debugInfo" is used when displaying an exception stack trace or
  * debugging. An offset of zero indicates that there are no entries.
  */
-typedef struct DexCode {
+struct DexCode {
     u2  registersSize;
     u2  insSize;
     u2  outsSize;
@@ -343,29 +339,29 @@
     /* followed by try_item[triesSize] */
     /* followed by uleb128 handlersSize */
     /* followed by catch_handler_item[handlersSize] */
-} DexCode;
+};
 
 /*
  * Direct-mapped "try_item".
  */
-typedef struct DexTry {
+struct DexTry {
     u4  startAddr;          /* start address, in 16-bit code units */
     u2  insnCount;          /* instruction count, in 16-bit code units */
     u2  handlerOff;         /* offset in encoded handler data to handlers */
-} DexTry;
+};
 
 /*
  * Link table.  Currently undefined.
  */
-typedef struct DexLink {
+struct DexLink {
     u1  bleargh;
-} DexLink;
+};
 
 
 /*
  * Direct-mapped "annotations_directory_item".
  */
-typedef struct DexAnnotationsDirectoryItem {
+struct DexAnnotationsDirectoryItem {
     u4  classAnnotationsOff;  /* offset to DexAnnotationSetItem */
     u4  fieldsSize;           /* count of DexFieldAnnotationsItem */
     u4  methodsSize;          /* count of DexMethodAnnotationsItem */
@@ -373,73 +369,73 @@
     /* followed by DexFieldAnnotationsItem[fieldsSize] */
     /* followed by DexMethodAnnotationsItem[methodsSize] */
     /* followed by DexParameterAnnotationsItem[parametersSize] */
-} DexAnnotationsDirectoryItem;
+};
 
 /*
  * Direct-mapped "field_annotations_item".
  */
-typedef struct DexFieldAnnotationsItem {
+struct DexFieldAnnotationsItem {
     u4  fieldIdx;
     u4  annotationsOff;             /* offset to DexAnnotationSetItem */
-} DexFieldAnnotationsItem;
+};
 
 /*
  * Direct-mapped "method_annotations_item".
  */
-typedef struct DexMethodAnnotationsItem {
+struct DexMethodAnnotationsItem {
     u4  methodIdx;
     u4  annotationsOff;             /* offset to DexAnnotationSetItem */
-} DexMethodAnnotationsItem;
+};
 
 /*
  * Direct-mapped "parameter_annotations_item".
  */
-typedef struct DexParameterAnnotationsItem {
+struct DexParameterAnnotationsItem {
     u4  methodIdx;
     u4  annotationsOff;             /* offset to DexAnotationSetRefList */
-} DexParameterAnnotationsItem;
+};
 
 /*
  * Direct-mapped "annotation_set_ref_item".
  */
-typedef struct DexAnnotationSetRefItem {
+struct DexAnnotationSetRefItem {
     u4  annotationsOff;             /* offset to DexAnnotationSetItem */
-} DexAnnotationSetRefItem;
+};
 
 /*
  * Direct-mapped "annotation_set_ref_list".
  */
-typedef struct DexAnnotationSetRefList {
+struct DexAnnotationSetRefList {
     u4  size;
     DexAnnotationSetRefItem list[1];
-} DexAnnotationSetRefList;
+};
 
 /*
  * Direct-mapped "annotation_set_item".
  */
-typedef struct DexAnnotationSetItem {
+struct DexAnnotationSetItem {
     u4  size;
     u4  entries[1];                 /* offset to DexAnnotationItem */
-} DexAnnotationSetItem;
+};
 
 /*
  * Direct-mapped "annotation_item".
  *
  * NOTE: this structure is byte-aligned.
  */
-typedef struct DexAnnotationItem {
+struct DexAnnotationItem {
     u1  visibility;
     u1  annotation[1];              /* data in encoded_annotation format */
-} DexAnnotationItem;
+};
 
 /*
  * Direct-mapped "encoded_array".
  *
  * NOTE: this structure is byte-aligned.
  */
-typedef struct DexEncodedArray {
+struct DexEncodedArray {
     u1  array[1];                   /* data in encoded_array format */
-} DexEncodedArray;
+};
 
 /*
  * Lookup table for classes.  It provides a mapping from class name to
@@ -450,7 +446,7 @@
  * a hash table with direct pointers to the items, but because it's shared
  * there's less of a penalty for using a fairly sparse table.
  */
-typedef struct DexClassLookup {
+struct DexClassLookup {
     int     size;                       // total size, including "size"
     int     numEntries;                 // size of table[]; always power of 2
     struct {
@@ -458,7 +454,7 @@
         int     classDescriptorOffset;  // in bytes, from start of DEX
         int     classDefOffset;         // in bytes, from start of DEX
     } table[1];
-} DexClassLookup;
+};
 
 /*
  * Header added by DEX optimization pass.  Values are always written in
@@ -468,7 +464,7 @@
  *
  * Try to keep this simple and fixed-size.
  */
-typedef struct DexOptHeader {
+struct DexOptHeader {
     u1  magic[8];           /* includes version number */
 
     u4  dexOffset;          /* file offset of DEX header */
@@ -482,7 +478,7 @@
     u4  checksum;           /* adler32 checksum covering deps/opt */
 
     /* pad for 64-bit alignment if necessary */
-} DexOptHeader;
+};
 
 #define DEX_OPT_FLAG_BIG            (1<<1)  /* swapped to big-endian */
 
@@ -494,7 +490,7 @@
  * Code should regard DexFile as opaque, using the API calls provided here
  * to access specific structures.
  */
-typedef struct DexFile {
+struct DexFile {
     /* directly-mapped "opt" header */
     const DexOptHeader* pOptHeader;
 
@@ -523,7 +519,7 @@
 
     /* additional app-specific data structures associated with the DEX */
     //void*               auxData;
-} DexFile;
+};
 
 /*
  * Utility function -- rounds up to the nearest power of 2.
@@ -964,8 +960,4 @@
  */
 PrimitiveType dexGetPrimitiveTypeFromDescriptorChar(char descriptorChar);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_DEXFILE*/
diff --git a/libdex/DexOpcodes.h b/libdex/DexOpcodes.h
index 68b8498..d8dc9a7 100644
--- a/libdex/DexOpcodes.h
+++ b/libdex/DexOpcodes.h
@@ -30,10 +30,6 @@
 
 #include "DexFile.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * kMaxOpcodeValue: the highest possible raw (unpacked) opcode value
  *
@@ -70,7 +66,7 @@
  * can find the next instruction" aren't possible. (This is
  * correctable, but probably not useful.)
  */
-typedef enum Opcode {
+enum Opcode {
     // BEGIN(libdex-opcode-enum); GENERATED AUTOMATICALLY BY opcode-gen
     OP_NOP                          = 0x00,
     OP_MOVE                         = 0x01,
@@ -585,7 +581,7 @@
     OP_SPUT_OBJECT_VOLATILE_JUMBO   = 0x1fe,
     OP_THROW_VERIFICATION_ERROR_JUMBO = 0x1ff,
     // END(libdex-opcode-enum)
-} Opcode;
+};
 
 /*
  * Macro used to generate a computed goto table for use in implementing
@@ -1137,8 +1133,4 @@
  */
 const char* dexGetOpcodeName(Opcode op);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_DEXOPCODES*/
diff --git a/libdex/DexOptData.h b/libdex/DexOptData.h
index 562553d..69eda01 100644
--- a/libdex/DexOptData.h
+++ b/libdex/DexOptData.h
@@ -24,10 +24,6 @@
 
 #include "libdex/DexFile.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Parse the optimized data tables in the given dex file.
  *
@@ -43,8 +39,4 @@
  */
 u4 dexComputeOptChecksum(const DexOptHeader* pOptHeader);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /* def _LIBDEX_DEXOPTDATA */
diff --git a/libdex/DexProto.h b/libdex/DexProto.h
index a300d3f..591c274 100644
--- a/libdex/DexProto.h
+++ b/libdex/DexProto.h
@@ -23,10 +23,6 @@
 
 #include "DexFile.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Single-thread single-string cache. This structure holds a pointer to
  * a string which is semi-automatically manipulated by some of the
@@ -34,11 +30,11 @@
  * generally return a string that is valid until the next
  * time the same DexStringCache is used.
  */
-typedef struct DexStringCache {
+struct DexStringCache {
     char* value;          /* the latest value */
     size_t allocatedSize; /* size of the allocated buffer, if allocated */
     char buffer[120];     /* buffer used to hold small-enough results */
-} DexStringCache;
+};
 
 /*
  * Make sure that the given cache can hold a string of the given length,
@@ -80,10 +76,10 @@
  * Method prototype structure, which refers to a protoIdx in a
  * particular DexFile.
  */
-typedef struct DexProto {
+struct DexProto {
     const DexFile* dexFile;     /* file the idx refers to */
     u4 protoIdx;                /* index into proto_ids table of dexFile */
-} DexProto;
+};
 
 /*
  * Set the given DexProto to refer to the prototype of the given MethodId.
@@ -203,12 +199,12 @@
  * Single-thread prototype parameter iterator. This structure holds a
  * pointer to a prototype and its parts, along with a cursor.
  */
-typedef struct DexParameterIterator {
+struct DexParameterIterator {
     const DexProto* proto;
     const DexTypeList* parameters;
     int parameterCount;
     int cursor;
-} DexParameterIterator;
+};
 
 /*
  * Initialize the given DexParameterIterator to be at the start of the
@@ -230,8 +226,4 @@
 const char* dexParameterIteratorNextDescriptor(
         DexParameterIterator* pIterator);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_DEXPROTO*/
diff --git a/libdex/DexSwapVerify.cpp b/libdex/DexSwapVerify.cpp
index 1325937..ea05e0c 100644
--- a/libdex/DexSwapVerify.cpp
+++ b/libdex/DexSwapVerify.cpp
@@ -68,7 +68,7 @@
 /*
  * Some information we pass around to help verify values.
  */
-typedef struct CheckState {
+struct CheckState {
     const DexHeader*  pHeader;
     const u1*         fileStart;
     const u1*         fileEnd;      // points to fileStart + fileLen
@@ -84,7 +84,7 @@
     u4*               pDefinedClassBits;
 
     const void*       previousItem; // set during section iteration
-} CheckState;
+};
 
 /*
  * Return the file offset of the given pointer.
diff --git a/libdex/DexUtf.h b/libdex/DexUtf.h
index 88d98b0..a7eb28c 100644
--- a/libdex/DexUtf.h
+++ b/libdex/DexUtf.h
@@ -23,10 +23,6 @@
 
 #include "DexFile.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Retrieve the next UTF-16 character from a UTF-8 string.
  *
@@ -132,8 +128,4 @@
  * is for anything but "void". */
 bool dexIsFieldDescriptor(const char* s);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /* def _LIBDEX_DEXUTF */
diff --git a/libdex/InstrUtils.h b/libdex/InstrUtils.h
index 88804cf..187fd5c 100644
--- a/libdex/InstrUtils.h
+++ b/libdex/InstrUtils.h
@@ -23,17 +23,13 @@
 #include "DexFile.h"
 #include "DexOpcodes.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Possible instruction formats associated with Dalvik opcodes.
  *
  * See the file opcode-gen/README.txt for information about updating
  * opcodes and instruction formats.
  */
-typedef enum {
+enum InstructionFormat {
     kFmt00x = 0,    // unknown format (also used for "breakpoint" opcode)
     kFmt10x,        // op
     kFmt12x,        // op vA, vB
@@ -71,13 +67,13 @@
     kFmt41c,        // exop vAAAA, thing@BBBBBBBB
     kFmt52c,        // exop vAAAA, vBBBB, thing@CCCCCCCC
     kFmt5rc,        // exop {vCCCC .. v(CCCC+AAAA-1)}, thing@BBBBBBBB
-} InstructionFormat;
+};
 
 /*
  * Types of indexed reference that are associated with opcodes whose
  * formats include such an indexed reference (e.g., 21c and 35c).
  */
-typedef enum {
+enum InstructionIndexType {
     kIndexUnknown = 0,
     kIndexNone,         // has no index
     kIndexVaries,       // "It depends." Used for throw-verification-error
@@ -88,7 +84,7 @@
     kIndexInlineMethod, // inline method index (for inline linked methods)
     kIndexVtableOffset, // vtable offset (for static linked methods)
     kIndexFieldOffset   // field offset (for static linked fields)
-} InstructionIndexType;
+};
 
 /*
  * Instruction width implied by an opcode's format; a value in the
@@ -121,12 +117,12 @@
  * that works for both C and C++, but in the mean time, this will
  * suffice.
  */
-typedef struct InstructionInfoTables {
+struct InstructionInfoTables {
     u1*                formats;    /* InstructionFormat elements */
     u1*                indexTypes; /* InstructionIndexType elements */
     OpcodeFlags*       flags;
     InstructionWidth*  widths;
-} InstructionInfoTables;
+};
 
 /*
  * Global InstructionInfoTables struct.
@@ -136,7 +132,7 @@
 /*
  * Holds the contents of a decoded instruction.
  */
-typedef struct DecodedInstruction {
+struct DecodedInstruction {
     u4      vA;
     u4      vB;
     u8      vB_wide;        /* for kFmt51l */
@@ -144,7 +140,7 @@
     u4      arg[5];         /* vC/D/E/F/G in invoke or filled-new-array */
     Opcode  opcode;
     InstructionIndexType indexType;
-} DecodedInstruction;
+};
 
 /*
  * Return the instruction width of the specified opcode, or 0 if not defined.
@@ -202,8 +198,4 @@
  */
 void dexDecodeInstruction(const u2* insns, DecodedInstruction* pDec);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_INSTRUTILS*/
diff --git a/libdex/Leb128.h b/libdex/Leb128.h
index 3287c16..41799fe 100644
--- a/libdex/Leb128.h
+++ b/libdex/Leb128.h
@@ -23,10 +23,6 @@
 
 #include "DexFile.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Reads an unsigned LEB128 value, updating the given pointer to point
  * just past the end of the read value. This function tolerates
@@ -165,8 +161,4 @@
     return count;
 }
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
diff --git a/libdex/OptInvocation.h b/libdex/OptInvocation.h
index 151b187..e44ce54 100644
--- a/libdex/OptInvocation.h
+++ b/libdex/OptInvocation.h
@@ -20,10 +20,6 @@
 #ifndef _LIBDEX_OPTINVOCATION
 #define _LIBDEX_OPTINVOCATION
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Utility routines, used by the VM.
  */
@@ -31,8 +27,4 @@
     const char* subFileName);
 int dexOptCreateEmptyHeader(int fd);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_OPTINVOCATION*/
diff --git a/libdex/SysUtil.h b/libdex/SysUtil.h
index 1f704f4..e297dc0 100644
--- a/libdex/SysUtil.h
+++ b/libdex/SysUtil.h
@@ -22,10 +22,6 @@
 
 #include <sys/types.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * System page size.  Normally you're expected to get this from
  * sysconf(_SC_PAGESIZE) or some system-specific define (usually PAGESIZE
@@ -40,13 +36,13 @@
 /*
  * Use this to keep track of mapped segments.
  */
-typedef struct MemMapping {
+struct MemMapping {
     void*   addr;           /* start of data */
     size_t  length;         /* length of data */
 
     void*   baseAddr;       /* page-aligned base address */
     size_t  baseLength;     /* length of mapping */
-} MemMapping;
+};
 
 /*
  * Copy a map.
@@ -123,8 +119,4 @@
  */
 int sysCopyFileToFile(int outFd, int inFd, size_t count);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_DALVIK_SYSUTIL*/
diff --git a/libdex/ZipArchive.h b/libdex/ZipArchive.h
index 872ceed..8d15cf6 100644
--- a/libdex/ZipArchive.h
+++ b/libdex/ZipArchive.h
@@ -23,10 +23,6 @@
 #include "SysUtil.h"
 #include "DexFile.h"            // need DEX_INLINE
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Trivial typedef to ensure that ZipEntry is not treated as a simple
  * integer.  We use NULL to indicate an invalid value.
@@ -36,11 +32,10 @@
 /*
  * One entry in the hash table.
  */
-typedef struct ZipHashEntry {
+struct ZipHashEntry {
     const char*     name;
     unsigned short  nameLen;
-    //unsigned int    hash;
-} ZipHashEntry;
+};
 
 /*
  * Read-only Zip archive.
@@ -61,7 +56,7 @@
  * every page that the Central Directory touches.  Easier to tuck a copy
  * of the string length into the hash table entry.
  */
-typedef struct ZipArchive {
+struct ZipArchive {
     /* open Zip archive */
     int         mFd;
 
@@ -78,7 +73,7 @@
      */
     int         mHashTableSize;
     ZipHashEntry* mHashTable;
-} ZipArchive;
+};
 
 /* Zip compression methods we support */
 enum {
@@ -182,8 +177,4 @@
 u4 dexInitCrc32(void);
 u4 dexComputeCrc32(u4 crc, const void* buf, size_t len);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_ZIPARCHIVE*/
diff --git a/libdex/sha1.cpp b/libdex/sha1.cpp
index dc7e30a..15a81cc 100644
--- a/libdex/sha1.cpp
+++ b/libdex/sha1.cpp
@@ -136,10 +136,10 @@
     const unsigned char buffer[64])
 {
 unsigned long a, b, c, d, e;
-typedef union {
+union CHAR64LONG16 {
     unsigned char c[64];
     unsigned long l[16];
-} CHAR64LONG16;
+};
 CHAR64LONG16* block;
 #ifdef SHA1HANDSOFF
 static unsigned char workspace[64];
diff --git a/libdex/sha1.h b/libdex/sha1.h
index 0cef623..0d8f691 100644
--- a/libdex/sha1.h
+++ b/libdex/sha1.h
@@ -4,15 +4,11 @@
 #ifndef _DALVIK_SHA1
 #define _DALVIK_SHA1
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
+struct SHA1_CTX {
     unsigned long state[5];
     unsigned long count[2];
     unsigned char buffer[64];
-} SHA1_CTX;
+};
 
 #define HASHSIZE 20
 
@@ -21,8 +17,4 @@
     unsigned long len);
 void SHA1Final(unsigned char digest[HASHSIZE], SHA1_CTX* context);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_DALVIK_SHA1*/