OSDN Git Service

Make libdex structures tool friendly.
authorCarl Shapiro <cshapiro@google.com>
Wed, 27 Apr 2011 21:16:08 +0000 (14:16 -0700)
committerCarl Shapiro <cshapiro@google.com>
Wed, 27 Apr 2011 21:16:08 +0000 (14:16 -0700)
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

29 files changed:
dalvikvm/Android.mk
dalvikvm/Main.cpp [moved from dalvikvm/Main.c with 86% similarity]
dexdump/Android.mk
dexdump/DexDump.cpp [moved from dexdump/DexDump.c with 99% similarity]
dexlist/Android.mk
dexlist/DexList.cpp [moved from dexlist/DexList.c with 98% similarity]
dexopt/Android.mk
dexopt/OptMain.cpp [moved from dexopt/OptMain.c with 99% similarity]
dvz/Android.mk
dvz/dvz.cpp [moved from dvz/dvz.c with 100% similarity]
libdex/CmdUtils.h
libdex/DexCatch.h
libdex/DexClass.h
libdex/DexDataMap.h
libdex/DexDebugInfo.cpp
libdex/DexDebugInfo.h
libdex/DexFile.h
libdex/DexOpcodes.h
libdex/DexOptData.h
libdex/DexProto.h
libdex/DexSwapVerify.cpp
libdex/DexUtf.h
libdex/InstrUtils.h
libdex/Leb128.h
libdex/OptInvocation.h
libdex/SysUtil.h
libdex/ZipArchive.h
libdex/sha1.cpp
libdex/sha1.h

index b7dda0f..5960a4b 100644 (file)
@@ -20,7 +20,7 @@ LOCAL_PATH:= $(call my-dir)
 #
 
 dalvikvm_src_files := \
-    Main.c
+    Main.cpp
 
 dalvikvm_c_includes := \
     $(JNI_H_INCLUDE) \
similarity index 86%
rename from dalvikvm/Main.c
rename to dalvikvm/Main.cpp
index 666317c..4aa6e20 100644 (file)
@@ -48,14 +48,14 @@ static jobjectArray createStringArray(JNIEnv* env, char* const argv[], int argc)
     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 @@ static jobjectArray createStringArray(JNIEnv* env, char* const argv[], int argc)
     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 @@ static jobjectArray createStringArray(JNIEnv* env, char* const argv[], int argc)
     strArray = NULL;
 
 bail:
-    (*env)->DeleteLocalRef(env, stringClass);
-    (*env)->DeleteLocalRef(env, strArray);
+    env->DeleteLocalRef(stringClass);
+    env->DeleteLocalRef(strArray);
     return result;
 }
 
@@ -98,7 +98,7 @@ static int methodIsPublic(JNIEnv* env, jclass clazz, jmethodID methodId)
     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 @@ static int methodIsPublic(JNIEnv* env, jclass clazz, jmethodID methodId)
      * 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 @@ static int methodIsPublic(JNIEnv* env, jclass clazz, jmethodID methodId)
     result = JNI_TRUE;
 
 bail:
-    (*env)->DeleteLocalRef(env, refMethod);
-    (*env)->DeleteLocalRef(env, methodClass);
+    env->DeleteLocalRef(refMethod);
+    env->DeleteLocalRef(methodClass);
     return result;
 }
 
@@ -246,13 +246,13 @@ int main(int argc, char* const argv[])
         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 @@ int main(int argc, char* const argv[])
     /*
      * 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 @@ bail:
          * 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");*/
     }
index 58fa137..e47acfa 100644 (file)
@@ -18,7 +18,7 @@
 LOCAL_PATH:= $(call my-dir)
 
 dexdump_src_files := \
-               DexDump.c
+               DexDump.cpp
 
 dexdump_c_includes := \
                dalvik \
similarity index 99%
rename from dexdump/DexDump.c
rename to dexdump/DexDump.cpp
index 9353471..7d11752 100644 (file)
 
 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 @@ struct {
     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 @@ static char* descriptorToDot(const char* str)
         }
     }
 
-    newStr = malloc(targetLen + arrayDepth * 2 +1);
+    newStr = (char*)malloc(targetLen + arrayDepth * 2 +1);
 
     /* copy class name over */
     int i;
@@ -825,7 +827,7 @@ static char* indexString(DexFile* pDexFile,
          * 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 @@ bail:
  */
 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 @@ int process(const char* fileName)
     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;
index aacdfb5..a7dd6e2 100644 (file)
@@ -18,7 +18,7 @@
 LOCAL_PATH:= $(call my-dir)
 
 dexdump_src_files := \
-               DexList.c
+               DexList.cpp
 
 dexdump_c_includes := \
                dalvik \
similarity index 98%
rename from dexlist/DexList.c
rename to dexlist/DexList.cpp
index 5326692..03f0230 100644 (file)
@@ -63,7 +63,7 @@ static char* descriptorToDot(const char* str)
         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 @@ int process(const char* fileName)
     }
     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;
index 3bb98a5..241893a 100644 (file)
@@ -19,7 +19,7 @@
 LOCAL_PATH:= $(call my-dir)
 
 local_src_files := \
-               OptMain.c
+               OptMain.cpp
 
 local_c_includes := \
                dalvik \
similarity index 99%
rename from dexopt/OptMain.c
rename to dexopt/OptMain.cpp
index 7ecd1e0..a7a898d 100644 (file)
@@ -65,6 +65,9 @@ static int extractAndProcessZip(int zipFd, int cacheFd,
     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 @@ static int extractAndProcessZip(int zipFd, int cacheFd,
     }
 
     /* 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 @@ bail:
 static int processZipFile(int zipFd, int cacheFd, const char* zipName,
         const char *dexoptFlags)
 {
-    int result = -1;
     char* bcpCopy = NULL;
 
     /*
@@ -218,7 +215,7 @@ static int processZipFile(int zipFd, int cacheFd, const char* zipName,
     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 @@ static int processZipFile(int zipFd, int cacheFd, const char* zipName,
         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 @@ static int preopt(int argc, char* const argv[])
          */
         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 @@ static int preopt(int argc, char* const argv[])
         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 @@ static int fromDex(int argc, char* const argv[])
     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 @@ static int fromDex(int argc, char* const argv[])
     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) {
index 4e4387e..22d0950 100644 (file)
@@ -4,7 +4,7 @@ LOCAL_PATH := $(my-dir)
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-       dvz.c
+       dvz.cpp
 
 LOCAL_SHARED_LIBRARIES := \
        libcutils
similarity index 100%
rename from dvz/dvz.c
rename to dvz/dvz.cpp
index 3f05aff..62ce73a 100644 (file)
 #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 @@ typedef enum UnzipToFileResult {
     kUTFRNoClassesDex,
     kUTFROutputFileProblem,
     kUTFRBadZip,
-} UnzipToFileResult;
+};
 
 /*
  * Map the specified DEX file read-only (possibly after expanding it into a
@@ -74,8 +70,4 @@ UnzipToFileResult dexOpenAndMap(const char* fileName, const char* tempFileName,
 UnzipToFileResult dexUnzipToFile(const char* zipFileName,
     const char* outFileName, bool quiet);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_CMDUTILS*/
index 7c40bc5..19ea541 100644 (file)
 #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 @@ u4 dexGetHandlersSize(const DexCode* pCode);
  * 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 @@ DEX_INLINE bool dexFindCatchHandler(DexCatchIterator *pIterator,
     }
 }
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index 6003fcf..d2d92c0 100644 (file)
 #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 @@ DEX_INLINE void dexReadClassDataMethod(const u1** pData, DexMethod* pMethod,
     *lastIndex = index;
 }
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index 654933c..359d3ad 100644 (file)
 
 #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 @@ DEX_INLINE bool dexDataMapVerify0Ok(DexDataMap* map, u4 offset, u2 type) {
     return dexDataMapVerify(map, offset, type);
 }
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_DEXDATAMAP*/
index c33a1e4..cbb58d4 100644 (file)
@@ -109,13 +109,13 @@ static const char* readTypeIdx(const DexFile* pDexFile,
     }
 }
 
-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)
index c510c57..9ab67f5 100644 (file)
 
 #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 @@ void dexDecodeDebugInfo(
             DexDebugNewPositionCb posCb, DexDebugNewLocalCb localCb,
             void* cnxt);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /* def _LIBDEX_DEXDEBUGINFO */
index 6652286..4a090e1 100644 (file)
 #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 @@ enum {
 /*
  * 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 @@ typedef enum PrimitiveType {
     PRIM_LONG       = 7,
     PRIM_FLOAT      = 8,
     PRIM_DOUBLE     = 9,
-} PrimitiveType;
+};
 
 /*
  * access flags and masks; the "standard" ones are all <= 0x4000
@@ -210,7 +206,7 @@ enum {
 /*
  * 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 @@ typedef struct DexHeader {
     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 @@ typedef struct DexClassDef {
     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 @@ typedef struct DexTypeList {
  * "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 @@ typedef struct DexCode {
     /* 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 @@ typedef struct DexAnnotationsDirectoryItem {
     /* 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 @@ typedef struct DexEncodedArray {
  * 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 @@ typedef struct DexClassLookup {
         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 @@ typedef struct DexClassLookup {
  *
  * 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 @@ typedef struct DexOptHeader {
     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 @@ typedef struct DexOptHeader {
  * 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 @@ typedef struct DexFile {
 
     /* 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 @@ const char* dexGetBoxedTypeDescriptor(PrimitiveType type);
  */
 PrimitiveType dexGetPrimitiveTypeFromDescriptorChar(char descriptorChar);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_DEXFILE*/
index 68b8498..d8dc9a7 100644 (file)
 
 #include "DexFile.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * kMaxOpcodeValue: the highest possible raw (unpacked) opcode value
  *
@@ -70,7 +66,7 @@ extern "C" {
  * 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 @@ typedef enum Opcode {
     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 @@ DEX_INLINE Opcode dexOpcodeFromCodeUnit(u2 codeUnit) {
  */
 const char* dexGetOpcodeName(Opcode op);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_DEXOPCODES*/
index 562553d..69eda01 100644 (file)
 
 #include "libdex/DexFile.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Parse the optimized data tables in the given dex file.
  *
@@ -43,8 +39,4 @@ bool dexParseOptData(const u1* data, size_t length, DexFile* pDexFile);
  */
 u4 dexComputeOptChecksum(const DexOptHeader* pOptHeader);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /* def _LIBDEX_DEXOPTDATA */
index a300d3f..591c274 100644 (file)
 
 #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 @@ extern "C" {
  * 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 @@ char* dexStringCacheAbandon(DexStringCache* pCache, const char* value);
  * 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 @@ int dexProtoCompareToParameterDescriptors(const DexProto* proto,
  * 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 @@ u4 dexParameterIteratorNextIndex(DexParameterIterator* pIterator);
 const char* dexParameterIteratorNextDescriptor(
         DexParameterIterator* pIterator);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_DEXPROTO*/
index 1325937..ea05e0c 100644 (file)
@@ -68,7 +68,7 @@ static u8 endianSwapU8(u8 value) {
 /*
  * 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 @@ typedef struct CheckState {
     u4*               pDefinedClassBits;
 
     const void*       previousItem; // set during section iteration
-} CheckState;
+};
 
 /*
  * Return the file offset of the given pointer.
index 88d98b0..a7eb28c 100644 (file)
 
 #include "DexFile.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Retrieve the next UTF-16 character from a UTF-8 string.
  *
@@ -132,8 +128,4 @@ bool dexIsClassDescriptor(const char* s);
  * is for anything but "void". */
 bool dexIsFieldDescriptor(const char* s);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /* def _LIBDEX_DEXUTF */
index 88804cf..187fd5c 100644 (file)
 #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 @@ typedef enum {
     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 @@ typedef enum {
     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 @@ enum OpcodeFlagsBits {
  * 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 @@ extern InstructionInfoTables gDexOpcodeInfo;
 /*
  * 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 @@ typedef struct DecodedInstruction {
     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 @@ DEX_INLINE InstructionIndexType dexGetIndexTypeFromOpcode(Opcode opcode)
  */
 void dexDecodeInstruction(const u2* insns, DecodedInstruction* pDec);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_INSTRUTILS*/
index 3287c16..41799fe 100644 (file)
 
 #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 @@ DEX_INLINE int unsignedLeb128Size(u4 data)
     return count;
 }
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index 151b187..e44ce54 100644 (file)
 #ifndef _LIBDEX_OPTINVOCATION
 #define _LIBDEX_OPTINVOCATION
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /*
  * Utility routines, used by the VM.
  */
@@ -31,8 +27,4 @@ char* dexOptGenerateCacheFileName(const char* fileName,
     const char* subFileName);
 int dexOptCreateEmptyHeader(int fd);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_OPTINVOCATION*/
index 1f704f4..e297dc0 100644 (file)
 
 #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 @@ extern "C" {
 /*
  * 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 sysWriteFully(int fd, const void* buf, size_t count, const char* logMsg);
  */
 int sysCopyFileToFile(int outFd, int inFd, size_t count);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_DALVIK_SYSUTIL*/
index 872ceed..8d15cf6 100644 (file)
 #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 @@ typedef void* ZipEntry;
 /*
  * 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 @@ typedef struct ZipHashEntry {
  * 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 @@ typedef struct ZipArchive {
      */
     int         mHashTableSize;
     ZipHashEntry* mHashTable;
-} ZipArchive;
+};
 
 /* Zip compression methods we support */
 enum {
@@ -182,8 +177,4 @@ int dexZipExtractEntryToFile(const ZipArchive* pArchive,
 u4 dexInitCrc32(void);
 u4 dexComputeCrc32(u4 crc, const void* buf, size_t len);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_LIBDEX_ZIPARCHIVE*/
index dc7e30a..15a81cc 100644 (file)
@@ -136,10 +136,10 @@ static void SHA1Transform(unsigned long state[5],
     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];
index 0cef623..0d8f691 100644 (file)
@@ -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 @@ void SHA1Update(SHA1_CTX* context, const unsigned char* data,
     unsigned long len);
 void SHA1Final(unsigned char digest[HASHSIZE], SHA1_CTX* context);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /*_DALVIK_SHA1*/