diff --git a/classpath/jni-util.h b/classpath/jni-util.h index 57e545a14b..a73905fadf 100644 --- a/classpath/jni-util.h +++ b/classpath/jni-util.h @@ -15,6 +15,8 @@ #include "stdlib.h" #include "string.h" +#include "util/runtime-array.h" + #undef JNIEXPORT #if (defined __MINGW32__) || (defined _MSC_VER) @@ -121,30 +123,5 @@ allocate(JNIEnv* e, unsigned size) } return p; } -#ifdef _MSC_VER - -template -class RuntimeArray { - public: - RuntimeArray(unsigned size): - body(static_cast(malloc(size * sizeof(T)))) - { } - - ~RuntimeArray() { - free(body); - } - - T* body; -}; - -# define RUNTIME_ARRAY(type, name, size) RuntimeArray name(size); -# define RUNTIME_ARRAY_BODY(name) name.body - -#else // not _MSC_VER - -# define RUNTIME_ARRAY(type, name, size) type name[size]; -# define RUNTIME_ARRAY_BODY(name) name - -#endif // not _MSC_VER #endif//JNI_UTIL diff --git a/src/builtin.cpp b/src/builtin.cpp index 1edec99bef..eaa66ed101 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -13,6 +13,8 @@ #include "processor.h" #include "util.h" +#include "util/runtime-array.h" + using namespace vm; namespace { diff --git a/src/classpath-avian.cpp b/src/classpath-avian.cpp index 09fca657ef..f313bffa01 100644 --- a/src/classpath-avian.cpp +++ b/src/classpath-avian.cpp @@ -12,6 +12,8 @@ #include "classpath-common.h" #include "process.h" +#include "util/runtime-array.h" + using namespace vm; namespace { diff --git a/src/classpath-common.h b/src/classpath-common.h index dad0fd3559..11c22b913f 100644 --- a/src/classpath-common.h +++ b/src/classpath-common.h @@ -13,6 +13,8 @@ #include "tokenizer.h" +#include "util/runtime-array.h" + namespace vm { object diff --git a/src/common.h b/src/common.h index 3032bafae7..f401a22ecd 100644 --- a/src/common.h +++ b/src/common.h @@ -226,23 +226,6 @@ alias(void* p, unsigned offset) #ifdef _MSC_VER -template -class RuntimeArray { - public: - RuntimeArray(unsigned size): - body(static_cast(malloc(size * sizeof(T)))) - { } - - ~RuntimeArray() { - free(body); - } - - T* body; -}; - -# define RUNTIME_ARRAY(type, name, size) RuntimeArray name(size); -# define RUNTIME_ARRAY_BODY(name) name.body - inline int vsnprintf(char* dst, size_t size, const char* format, va_list a) { @@ -272,9 +255,6 @@ fopen(const char* name, const char* mode) #else // not _MSC_VER -# define RUNTIME_ARRAY(type, name, size) type name[size]; -# define RUNTIME_ARRAY_BODY(name) name - inline int vsnprintf(char* dst, size_t size, const char* format, va_list a) { diff --git a/src/compile.cpp b/src/compile.cpp index 9e387aff19..51d141e990 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -17,6 +17,8 @@ #include "compiler.h" #include "arch.h" +#include "util/runtime-array.h" + using namespace vm; extern "C" uint64_t diff --git a/src/compiler.cpp b/src/compiler.cpp index a216663de7..90efb622b8 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -12,6 +12,8 @@ #include "assembler.h" #include "target.h" +#include "util/runtime-array.h" + using namespace vm; namespace { diff --git a/src/finder.cpp b/src/finder.cpp index bfe6214a9e..479761c19f 100644 --- a/src/finder.cpp +++ b/src/finder.cpp @@ -14,6 +14,8 @@ #include "finder.h" #include "lzma.h" +#include "util/runtime-array.h" + using namespace vm; namespace { diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 3a61046473..966494320d 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -14,6 +14,8 @@ #include "processor.h" #include "constants.h" +#include "util/runtime-array.h" + using namespace vm; namespace { diff --git a/src/machine.cpp b/src/machine.cpp index fb66d5a87d..cb4f4c066c 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -17,6 +17,8 @@ #include "arch.h" #include "lzma.h" +#include "util/runtime-array.h" + using namespace vm; namespace { diff --git a/src/main.cpp b/src/main.cpp index fe2793c10d..e70555e73e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,8 @@ #include "system.h" #include "finder.h" +#include "util/runtime-array.h" + #if (defined __MINGW32__) || (defined _MSC_VER) # define PATH_SEPARATOR ';' #else @@ -29,28 +31,6 @@ # define and && # define xor ^ -template -class RuntimeArray { - public: - RuntimeArray(unsigned size): - body(static_cast(malloc(size * sizeof(T)))) - { } - - ~RuntimeArray() { - free(body); - } - - T* body; -}; - -# define RUNTIME_ARRAY(type, name, size) RuntimeArray name(size); -# define RUNTIME_ARRAY_BODY(name) name.body - -#else // not _MSC_VER - -# define RUNTIME_ARRAY(type, name, size) type name[size]; -# define RUNTIME_ARRAY_BODY(name) name - #endif // not _MSC_VER #ifdef BOOT_LIBRARY diff --git a/src/process.cpp b/src/process.cpp index ac1c21917e..b13aa7ca4f 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -10,6 +10,8 @@ #include "process.h" +#include "util/runtime-array.h" + using namespace vm; namespace { diff --git a/src/util/runtime-array.h b/src/util/runtime-array.h new file mode 100644 index 0000000000..378718708d --- /dev/null +++ b/src/util/runtime-array.h @@ -0,0 +1,40 @@ +/* Copyright (c) 2008-2012, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#ifndef UTIL_RUNTIME_ARRAY_H +#define UTIL_RUNTIME_ARRAY_H + +#ifdef _MSC_VER + +template +class RuntimeArray { + public: + RuntimeArray(unsigned size): + body(static_cast(malloc(size * sizeof(T)))) + { } + + ~RuntimeArray() { + free(body); + } + + T* body; +}; + +# define RUNTIME_ARRAY(type, name, size) RuntimeArray name(size); +# define RUNTIME_ARRAY_BODY(name) name.body + +#else // not _MSC_VER + +# define RUNTIME_ARRAY(type, name, size) type name[size]; +# define RUNTIME_ARRAY_BODY(name) name + +#endif + +#endif \ No newline at end of file diff --git a/src/x86.cpp b/src/x86.cpp index fc92e661f2..3a3942dca7 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -13,6 +13,8 @@ #include "target.h" #include "vector.h" +#include "util/runtime-array.h" + #define CAST1(x) reinterpret_cast(x) #define CAST2(x) reinterpret_cast(x) #define CAST_BRANCH(x) reinterpret_cast(x)