<NME> J2ObjC_common.h
<BEF> // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Common definitions needed by all J2ObjC generated files.

#ifndef _J2OBJC_COMMON_H_
#define _J2OBJC_COMMON_H_

#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>

#import "J2ObjC_types.h"

@class IOSClass;
@class JavaLangRefWeakReference;
@protocol JavaLangIterable;

#ifndef __has_feature
#define __has_feature(x) 0  // Compatibility with non-clang compilers.
#endif

# ifndef OBJC_METHOD_FAMILY_NONE
#  if __has_attribute(objc_method_family)
#   define OBJC_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
#  else
#   define OBJC_METHOD_FAMILY_NONE
#  endif
# endif

# if __has_feature(objc_arc)
#  define ARCBRIDGE __bridge
#  define ARCBRIDGE_TRANSFER __bridge_transfer
#  define ARC_CONSUME_PARAMETER __attribute((ns_consumed))
#  define AUTORELEASE(x) x
#  define RELEASE_(x) x
#  define RETAIN_(x) x
#  define RETAIN_AND_AUTORELEASE(x) x
# else
#  define ARCBRIDGE
#  define ARCBRIDGE_TRANSFER
#  define ARC_CONSUME_PARAMETER
#  define AUTORELEASE(x) [x autorelease]
#  define RELEASE_(x) [x release]
#  define RETAIN_(x) [x retain]
#  define RETAIN_AND_AUTORELEASE(x) [[x retain] autorelease]
# endif

#if __has_feature(objc_arc_weak)
# define WEAK_ __weak
#else
# define WEAK_ __unsafe_unretained
#endif

CF_EXTERN_C_BEGIN

id JreThrowNullPointerException(void) __attribute__((noreturn));
void JreThrowClassCastException(id p, Class cls) __attribute__((noreturn));
 #define J2OBJC_DISABLE_ARRAY_TYPE_CHECKS 1
#endif

CF_EXTERN_C_BEGIN

void JreThrowNullPointerException() __attribute__((noreturn));
void JreCloneVolatileStrong(volatile_id *pVar, volatile_id *pOther);
void JreReleaseVolatile(volatile_id *pVar);
id JreRetainedLocalValue(id value);

id JreRetainedWithAssign(id parent, __strong id *pIvar, id value);
id JreVolatileRetainedWithAssign(id parent, volatile_id *pIvar, id value);
void JreRetainedWithRelease(id parent, id child);
void JreVolatileRetainedWithRelease(id parent, volatile_id *pVar);

NSString *JreStrcat(const char *types, ...);

jboolean JreAnnotationEquals(id a1, id a2);
jint JreAnnotationHashCode(id a);

NSUInteger JreDefaultFastEnumeration(
    id<JavaLangIterable> obj, NSFastEnumerationState *state, id __unsafe_unretained *stackbuf);

CF_EXTERN_C_END

/*!
 * The nil_chk macro is used wherever a Java object is dereferenced and needs to
 * be checked for null. A macro is used instead of an inline function because it
 * allows the line number of the dereference to be derived from the stack frame.
 *
 * @param p The object to check for nil.
 */
#define nil_chk(p) (p ?: JreThrowNullPointerException())

#if !__has_feature(objc_arc)
__attribute__((always_inline)) inline id JreAutoreleasedAssign(
    id *pIvar, NS_RELEASES_ARGUMENT id value) {
  [*pIvar autorelease];
  return *pIvar = value;
}
#endif

/*!
 * Utility macro for passing an argument that contains a comma.
 */
#define J2OBJC_ARG(...) __VA_ARGS__

#define J2OBJC_VOLATILE_ACCESS_DEFN(NAME, TYPE) \
  __attribute__((always_inline)) inline TYPE JreLoadVolatile##NAME(volatile_##TYPE *pVar) { \
    return __c11_atomic_load(pVar, __ATOMIC_SEQ_CST); \
  } \
  __attribute__((always_inline)) inline TYPE JreAssignVolatile##NAME( \
      volatile_##TYPE *pVar, TYPE value) { \
    __c11_atomic_store(pVar, value, __ATOMIC_SEQ_CST); \
    return value; \
  }

J2OBJC_VOLATILE_ACCESS_DEFN(Boolean, jboolean)
J2OBJC_VOLATILE_ACCESS_DEFN(Char, jchar)
J2OBJC_VOLATILE_ACCESS_DEFN(Byte, jbyte)
J2OBJC_VOLATILE_ACCESS_DEFN(Short, jshort)
J2OBJC_VOLATILE_ACCESS_DEFN(Int, jint)
J2OBJC_VOLATILE_ACCESS_DEFN(Long, jlong)
J2OBJC_VOLATILE_ACCESS_DEFN(Float, jfloat)
J2OBJC_VOLATILE_ACCESS_DEFN(Double, jdouble)
#undef J2OBJC_VOLATILE_ACCESS_DEFN

/*!
 * Defines the initialized flag for a class.
 *
 * @define J2OBJC_INITIALIZED_DEFN
 * @param CLASS The class for which the initialized flag is defined.
 */
#define J2OBJC_INITIALIZED_DEFN(CLASS) \
  _Atomic(jboolean) CLASS##__initialized = false;

/*!
 * Defines the code to set a class's initialized flag. This should be used at
 * the end of each class's initialize class method.
 *
 * @define J2OBJC_SET_INITIALIZED
 * @param CLASS The class who's flag is to be set.
 */
#define J2OBJC_SET_INITIALIZED(CLASS) \
  __c11_atomic_store(&CLASS##__initialized, true, __ATOMIC_RELEASE);

/*!
 * Defines an init function for a class that will ensure that the class is
 * initialized. For class "Foo" the function will have the following signature:
 *   inline void Foo_initialize();
 *
 * @define J2OBJC_STATIC_INIT
 * @param CLASS The class to declare the init function for.
 */
#define J2OBJC_STATIC_INIT(CLASS)                                                           \
  FOUNDATION_EXPORT _Atomic(jboolean) CLASS##__initialized;                                 \
  __attribute__((always_inline)) inline void CLASS##_initialize(void) {                     \
    if (__builtin_expect(!__c11_atomic_load(&CLASS##__initialized, __ATOMIC_ACQUIRE), 0)) { \
      [CLASS class];                                                                        \
    }                                                                                       \
  }

/*!
 * Defines an empty init function for a class that has no initialization code.
 *
 * @define J2OBJC_EMPTY_STATIC_INIT
 * @param CLASS The class to declare the init function for.
 */
#define J2OBJC_EMPTY_STATIC_INIT(CLASS) \
  __attribute__((always_inline)) inline void CLASS##_initialize(void) {}

/*!
 * Declares the type literal accessor for a type. This macro should be added to
 * the header of each generated Java type.
 *
 * @define J2OBJC_TYPE_LITERAL_HEADER
 * @param TYPE The name of the type to declare the accessor for.
 */
#define J2OBJC_TYPE_LITERAL_HEADER(TYPE) \
  FOUNDATION_EXPORT IOSClass *TYPE##_class_(void);

/*!
 * Defines the type literal accessor for a class or enum type. This macro should
 * be added to the implementation of each generated Java type.
 *
 * @define J2OBJC_CLASS_TYPE_LITERAL_SOURCE
 * @param TYPE The name of the type to define the accessor for.
 */
#define J2OBJC_CLASS_TYPE_LITERAL_SOURCE(TYPE) \
  IOSClass *TYPE##_class_() { \
    static IOSClass *cls; \
    static dispatch_once_t token; \
    TYPE##_initialize(); \
    dispatch_once(&token, ^{ cls = IOSClass_fromClass([TYPE class]); }); \
    return cls; \
  }

/*!
 * Defines the type literal accessor for a interface or annotation type. This
 * macro should be added to the implementation of each generated Java type.
 *
 * @define J2OBJC_INTERFACE_TYPE_LITERAL_SOURCE
 * @param TYPE The name of the type to define the accessor for.
 */
#define J2OBJC_INTERFACE_TYPE_LITERAL_SOURCE(TYPE) \
  IOSClass *TYPE##_class_() { \
    static IOSClass *cls; \
    static dispatch_once_t token; \
    TYPE##_initialize(); \
    dispatch_once(&token, ^{ cls = IOSClass_fromProtocol(@protocol(TYPE)); }); \
    return cls; \
  }

#if __has_feature(objc_arc)
#define J2OBJC_FIELD_SETTER(CLASS, FIELD, TYPE) \
  __attribute__((unused)) static inline TYPE CLASS##_set_##FIELD(CLASS *instance, TYPE value) { \
    return instance->FIELD = value; \
  }
#else
#define J2OBJC_FIELD_SETTER(CLASS, FIELD, TYPE) \
  __attribute__((unused)) static inline TYPE CLASS##_set_##FIELD(CLASS *instance, TYPE value) { \
    return JreStrongAssign(&instance->FIELD, value); \
  }\
  __attribute__((unused)) static inline TYPE CLASS##_setAndConsume_##FIELD( \
        CLASS *instance, NS_RELEASES_ARGUMENT TYPE value) { \
    return JreStrongAssignAndConsume(&instance->FIELD, value); \
  }
#endif

#define J2OBJC_VOLATILE_FIELD_SETTER(CLASS, FIELD, TYPE) \
  __attribute__((unused)) static inline TYPE CLASS##_set_##FIELD(CLASS *instance, TYPE value) { \
    return JreVolatileStrongAssign(&instance->FIELD, value); \
  }

/*!
 * Adds noop implementations for the memory management methods. This helps to
 * avoid the cost of incrementing and decrementing the retain count for objects
 * that should never be dealloc'ed.
 *
 * @define J2OBJC_ETERNAL_SINGLETON
 */
#define J2OBJC_ETERNAL_SINGLETON \
  - (id)retain { return self; } \
  - (oneway void)release {} \
  - (id)autorelease { return self; }

/*!
 A type to represent an Objective C class.
 This is actually an `objc_class` but the runtime headers will not allow us to
 reference `objc_class`, so we have defined our own.

 Adapted from:
 https://github.com/protocolbuffers/protobuf/blob/master/objectivec/GPBRuntimeTypes.h
*/
typedef struct J2ObjCClass_t J2ObjCClass_t;

/*!
 Macros for generating a Class from a class name. These are used wherever a
 static Objective C class reference is needed for a generated class. Unlike
 "[classname class]", this macro doesn't trigger class initialization, avoiding
 the chance of Objective C initialization deadlocks.

 Adapted from:
 https://github.com/protocolbuffers/protobuf/blob/master/objectivec/GPBUtilities_PackagePrivate.h
 */
#define J2OBJC_CLASS_SYMBOL(name) OBJC_CLASS_$_##name
#define J2OBJC_CLASS_REFERENCE(name) \
    ((__bridge Class)&(J2OBJC_CLASS_SYMBOL(name)))
#define J2OBJC_CLASS_DECLARATION(name) \
    extern const J2ObjCClass_t J2OBJC_CLASS_SYMBOL(name)

#endif // _J2OBJC_COMMON_H_

<MSG> Define STATIC_CAST macro to eliminate old-style-cast warnings with Objective-C++.
	Change on 2015/12/11 by tball <tball@google.com>
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=110022707

<DFF> @@ -67,6 +67,12 @@
  #define J2OBJC_DISABLE_ARRAY_TYPE_CHECKS 1
 #endif
 
+#ifdef __cplusplus
+#define J2_STATIC_CAST(T,E) static_cast<T>(E)
+#else
+#define J2_STATIC_CAST(T,E) ((T)(E))
+#endif
+
 CF_EXTERN_C_BEGIN
 
 void JreThrowNullPointerException() __attribute__((noreturn));

{'commit': 'diff --git a/jre_emul/Classes/IOSObjectArray.h b/jre_emul/Classes/IOSObjectArray.h\nindex 3064db1aa..dd1c6c504 100644\n--- a/jre_emul/Classes/IOSObjectArray.h\n+++ b/jre_emul/Classes/IOSObjectArray.h\n@@ -132,7 +132,7 @@ FOUNDATION_EXPORT id IOSObjectArray_SetAndConsume(\n \n __attribute__((always_inline)) inline id IOSObjectArray_Get(\n     __unsafe_unretained IOSObjectArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return array->buffer_[index];\n }\n \n@@ -146,7 +146,7 @@ typedef struct JreArrayRef {\n // Internal only functions.\n __attribute__((always_inline)) inline JreArrayRef IOSObjectArray_GetRef(\n     __unsafe_unretained IOSObjectArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return (JreArrayRef){ .arr = array, .pValue = &array->buffer_[index] };\n }\n FOUNDATION_EXPORT id IOSObjectArray_SetRef(JreArrayRef ref, id value);\ndiff --git a/jre_emul/Classes/IOSPrimitiveArray.h b/jre_emul/Classes/IOSPrimitiveArray.h\nindex 18df61b2d..34384b833 100644\n--- a/jre_emul/Classes/IOSPrimitiveArray.h\n+++ b/jre_emul/Classes/IOSPrimitiveArray.h\n@@ -107,7 +107,7 @@\n  */\n __attribute__((always_inline)) inline jboolean IOSBooleanArray_Get(\n     __unsafe_unretained IOSBooleanArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return array->buffer_[index];\n }\n \n@@ -117,7 +117,7 @@ __attribute__((always_inline)) inline jboolean IOSBooleanArray_Get(\n  */\n __attribute__((always_inline)) inline jboolean *IOSBooleanArray_GetRef(\n     __unsafe_unretained IOSBooleanArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return &array->buffer_[index];\n }\n \n@@ -128,8 +128,8 @@ __attribute__((always_inline)) inline void IOSBooleanArray_GetRange(\n     jboolean *buffer, __unsafe_unretained const IOSBooleanArray *array,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(buffer, array->buffer_ + ((size_t)offset * sizeof(jboolean)),\n-      (size_t)length * sizeof(jboolean));\n+  memcpy(buffer, array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jboolean)),\n+      J2_STATIC_CAST(size_t, length) * sizeof(jboolean));\n }\n \n /**\n@@ -139,8 +139,8 @@ __attribute__((always_inline)) inline void IOSBooleanArray_SetRange(\n     __unsafe_unretained IOSBooleanArray *array, const jboolean *buffer,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(array->buffer_ + ((size_t)offset * sizeof(jboolean)), buffer,\n-      (size_t)length * sizeof(jboolean));\n+  memcpy(array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jboolean)), buffer,\n+      J2_STATIC_CAST(size_t, length) * sizeof(jboolean));\n }\n \n \n@@ -222,7 +222,7 @@ __attribute__((always_inline)) inline void IOSBooleanArray_SetRange(\n  */\n __attribute__((always_inline)) inline jchar IOSCharArray_Get(\n     __unsafe_unretained IOSCharArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return array->buffer_[index];\n }\n \n@@ -232,7 +232,7 @@ __attribute__((always_inline)) inline jchar IOSCharArray_Get(\n  */\n __attribute__((always_inline)) inline jchar *IOSCharArray_GetRef(\n     __unsafe_unretained IOSCharArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return &array->buffer_[index];\n }\n \n@@ -243,7 +243,8 @@ __attribute__((always_inline)) inline void IOSCharArray_GetRange(\n     jchar *buffer, __unsafe_unretained const IOSCharArray *array,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(buffer, array->buffer_ + ((size_t)offset * sizeof(jchar)), (size_t)length * sizeof(jchar));\n+  memcpy(buffer, array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jchar)),\n+      J2_STATIC_CAST(size_t, length) * sizeof(jchar));\n }\n \n /**\n@@ -253,7 +254,8 @@ __attribute__((always_inline)) inline void IOSCharArray_SetRange(\n     __unsafe_unretained IOSCharArray *array, const jchar *buffer,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(array->buffer_ + ((size_t)offset * sizeof(jchar)), buffer, (size_t)length * sizeof(jchar));\n+  memcpy(array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jchar)), buffer,\n+      J2_STATIC_CAST(size_t, length) * sizeof(jchar));\n }\n \n \n@@ -349,7 +351,7 @@ __attribute__((always_inline)) inline void IOSCharArray_SetRange(\n  */\n __attribute__((always_inline)) inline jbyte IOSByteArray_Get(\n     __unsafe_unretained IOSByteArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return array->buffer_[index];\n }\n \n@@ -359,7 +361,7 @@ __attribute__((always_inline)) inline jbyte IOSByteArray_Get(\n  */\n __attribute__((always_inline)) inline jbyte *IOSByteArray_GetRef(\n     __unsafe_unretained IOSByteArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return &array->buffer_[index];\n }\n \n@@ -370,7 +372,8 @@ __attribute__((always_inline)) inline void IOSByteArray_GetRange(\n     jbyte *buffer, __unsafe_unretained const IOSByteArray *array,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(buffer, array->buffer_ + ((size_t)offset * sizeof(jbyte)), (size_t)length * sizeof(jbyte));\n+  memcpy(buffer, array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jbyte)),\n+      J2_STATIC_CAST(size_t, length) * sizeof(jbyte));\n }\n \n /**\n@@ -380,7 +383,8 @@ __attribute__((always_inline)) inline void IOSByteArray_SetRange(\n     __unsafe_unretained IOSByteArray *array, const jbyte *buffer,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(array->buffer_ + ((size_t)offset * sizeof(jbyte)), buffer, (size_t)length * sizeof(jbyte));\n+  memcpy(array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jbyte)), buffer,\n+      J2_STATIC_CAST(size_t, length) * sizeof(jbyte));\n }\n \n \n@@ -457,7 +461,7 @@ __attribute__((always_inline)) inline void IOSByteArray_SetRange(\n  */\n __attribute__((always_inline)) inline jshort IOSShortArray_Get(\n     __unsafe_unretained IOSShortArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return array->buffer_[index];\n }\n \n@@ -467,7 +471,7 @@ __attribute__((always_inline)) inline jshort IOSShortArray_Get(\n  */\n __attribute__((always_inline)) inline jshort *IOSShortArray_GetRef(\n     __unsafe_unretained IOSShortArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return &array->buffer_[index];\n }\n \n@@ -478,8 +482,8 @@ __attribute__((always_inline)) inline void IOSShortArray_GetRange(\n     jshort *buffer, __unsafe_unretained const IOSShortArray *array,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(buffer, array->buffer_ + ((size_t)offset * sizeof(jshort)),\n-      (size_t)length * sizeof(jshort));\n+  memcpy(buffer, array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jshort)),\n+      J2_STATIC_CAST(size_t, length) * sizeof(jshort));\n }\n \n /**\n@@ -489,8 +493,8 @@ __attribute__((always_inline)) inline void IOSShortArray_SetRange(\n     __unsafe_unretained IOSShortArray *array, const jshort *buffer,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(array->buffer_ + ((size_t)offset * sizeof(jshort)), buffer,\n-      (size_t)length * sizeof(jshort));\n+  memcpy(array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jshort)), buffer,\n+      J2_STATIC_CAST(size_t, length) * sizeof(jshort));\n }\n \n \n@@ -568,7 +572,7 @@ __attribute__((always_inline)) inline void IOSShortArray_SetRange(\n  */\n __attribute__((always_inline)) inline jint IOSIntArray_Get(\n     __unsafe_unretained IOSIntArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return array->buffer_[index];\n }\n \n@@ -578,7 +582,7 @@ __attribute__((always_inline)) inline jint IOSIntArray_Get(\n  */\n __attribute__((always_inline)) inline jint *IOSIntArray_GetRef(\n     __unsafe_unretained IOSIntArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return &array->buffer_[index];\n }\n \n@@ -589,7 +593,8 @@ __attribute__((always_inline)) inline void IOSIntArray_GetRange(\n     jint *buffer, __unsafe_unretained const IOSIntArray *array,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(buffer, array->buffer_ + ((size_t)offset * sizeof(jint)), (size_t)length * sizeof(jint));\n+  memcpy(buffer, array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jint)),\n+      J2_STATIC_CAST(size_t, length) * sizeof(jint));\n }\n \n /**\n@@ -599,7 +604,8 @@ __attribute__((always_inline)) inline void IOSIntArray_SetRange(\n     __unsafe_unretained IOSIntArray *array, const jint *buffer,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(array->buffer_ + ((size_t)offset * sizeof(jint)), buffer, (size_t)length * sizeof(jint));\n+  memcpy(array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jint)), buffer,\n+      J2_STATIC_CAST(size_t, length) * sizeof(jint));\n }\n \n \n@@ -677,7 +683,7 @@ __attribute__((always_inline)) inline void IOSIntArray_SetRange(\n  */\n __attribute__((always_inline)) inline jlong IOSLongArray_Get(\n     __unsafe_unretained IOSLongArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return array->buffer_[index];\n }\n \n@@ -687,7 +693,7 @@ __attribute__((always_inline)) inline jlong IOSLongArray_Get(\n  */\n __attribute__((always_inline)) inline jlong *IOSLongArray_GetRef(\n     __unsafe_unretained IOSLongArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return &array->buffer_[index];\n }\n \n@@ -698,7 +704,8 @@ __attribute__((always_inline)) inline void IOSLongArray_GetRange(\n     jlong *buffer, __unsafe_unretained const IOSLongArray *array,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(buffer, array->buffer_ + ((size_t)offset * sizeof(jlong)), (size_t)length * sizeof(jlong));\n+  memcpy(buffer, array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jlong)),\n+      J2_STATIC_CAST(size_t, length) * sizeof(jlong));\n }\n \n /**\n@@ -708,7 +715,8 @@ __attribute__((always_inline)) inline void IOSLongArray_SetRange(\n     __unsafe_unretained IOSLongArray *array, const jlong *buffer,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(array->buffer_ + ((size_t)offset * sizeof(jlong)), buffer, (size_t)length * sizeof(jlong));\n+  memcpy(array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jlong)), buffer,\n+      J2_STATIC_CAST(size_t, length) * sizeof(jlong));\n }\n \n \n@@ -785,7 +793,7 @@ __attribute__((always_inline)) inline void IOSLongArray_SetRange(\n  */\n __attribute__((always_inline)) inline jfloat IOSFloatArray_Get(\n     __unsafe_unretained IOSFloatArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return array->buffer_[index];\n }\n \n@@ -795,7 +803,7 @@ __attribute__((always_inline)) inline jfloat IOSFloatArray_Get(\n  */\n __attribute__((always_inline)) inline jfloat *IOSFloatArray_GetRef(\n     __unsafe_unretained IOSFloatArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return &array->buffer_[index];\n }\n \n@@ -806,8 +814,8 @@ __attribute__((always_inline)) inline void IOSFloatArray_GetRange(\n     jfloat *buffer, __unsafe_unretained const IOSFloatArray *array,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(buffer, array->buffer_ + ((size_t)offset * sizeof(jfloat)),\n-      (size_t)length * sizeof(jfloat));\n+  memcpy(buffer, array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jfloat)),\n+      J2_STATIC_CAST(size_t, length) * sizeof(jfloat));\n }\n \n /**\n@@ -817,8 +825,8 @@ __attribute__((always_inline)) inline void IOSFloatArray_SetRange(\n     __unsafe_unretained IOSFloatArray *array, const jfloat *buffer,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(array->buffer_ + ((size_t)offset * sizeof(jfloat)), buffer,\n-      (size_t)length * sizeof(jfloat));\n+  memcpy(array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jfloat)), buffer,\n+      J2_STATIC_CAST(size_t, length) * sizeof(jfloat));\n }\n \n \n@@ -895,7 +903,7 @@ __attribute__((always_inline)) inline void IOSFloatArray_SetRange(\n  */\n __attribute__((always_inline)) inline jdouble IOSDoubleArray_Get(\n     __unsafe_unretained IOSDoubleArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return array->buffer_[index];\n }\n \n@@ -905,7 +913,7 @@ __attribute__((always_inline)) inline jdouble IOSDoubleArray_Get(\n  */\n __attribute__((always_inline)) inline jdouble *IOSDoubleArray_GetRef(\n     __unsafe_unretained IOSDoubleArray *array, NSUInteger index) {\n-  IOSArray_checkIndex(array->size_, (jint)index);\n+  IOSArray_checkIndex(array->size_, J2_STATIC_CAST(jint, index));\n   return &array->buffer_[index];\n }\n \n@@ -916,8 +924,8 @@ __attribute__((always_inline)) inline void IOSDoubleArray_GetRange(\n     jdouble *buffer, __unsafe_unretained const IOSDoubleArray *array,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(buffer, array->buffer_ + ((size_t)offset * sizeof(jdouble)),\n-      (size_t)length * sizeof(jdouble));\n+  memcpy(buffer, array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jdouble)),\n+      J2_STATIC_CAST(size_t, length) * sizeof(jdouble));\n }\n \n /**\n@@ -927,8 +935,8 @@ __attribute__((always_inline)) inline void IOSDoubleArray_SetRange(\n     __unsafe_unretained IOSDoubleArray *array, const jdouble *buffer,\n     jint offset, jint length) {\n   IOSArray_checkRange(array->size_, offset, length);\n-  memcpy(array->buffer_ + ((size_t)offset * sizeof(jdouble)), buffer,\n-      (size_t)length * sizeof(jdouble));\n+  memcpy(array->buffer_ + (J2_STATIC_CAST(size_t, offset) * sizeof(jdouble)), buffer,\n+      J2_STATIC_CAST(size_t, length) * sizeof(jdouble));\n }\n \n \ndiff --git a/jre_emul/Classes/J2ObjC_common.h b/jre_emul/Classes/J2ObjC_common.h\nindex 465c3c175..455dfd2ae 100644\n--- a/jre_emul/Classes/J2ObjC_common.h\n+++ b/jre_emul/Classes/J2ObjC_common.h\n@@ -67,6 +67,12 @@\n  #define J2OBJC_DISABLE_ARRAY_TYPE_CHECKS 1\n #endif\n \n+#ifdef __cplusplus\n+#define J2_STATIC_CAST(T,E) static_cast<T>(E)\n+#else\n+#define J2_STATIC_CAST(T,E) ((T)(E))\n+#endif\n+\n CF_EXTERN_C_BEGIN\n \n void JreThrowNullPointerException() __attribute__((noreturn));\n', 'commit_subject': 'Define STATIC_CAST macro to eliminate old-style-cast warnings with Objective-C++. \tChange on 2015/12/11 by tball <tball@google.com> ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=110022707', 'repo_name': 'google/j2objc', 'committer': {'name': 'Tom Ball', 'email': '413a605d00e3df24790ca07c68ba8993b8d2bae1@google.com', 'time_sec': '1450111597', 'tz_offset': '-480', 'date': {'seconds': '1450111597'}}, 'commit_tree': 'a956c2171e6cbca3bc71f885351eaa7ebcba9e3d', 'commit_message': 'Define STATIC_CAST macro to eliminate old-style-cast warnings with Objective-C++.\n\tChange on 2015/12/11 by tball <tball@google.com>\n-------------\nCreated by MOE: https://github.com/google/moe\nMOE_MIGRATED_REVID=110022707\n', 'language_name': 'C++', 'license': 'apache-2.0', 'hunks': '@@ -67,6 +67,12 @@\n  #define J2OBJC_DISABLE_ARRAY_TYPE_CHECKS 1\n #endif\n \n+#ifdef __cplusplus\n+#define J2_STATIC_CAST(T,E) static_cast<T>(E)\n+#else\n+#define J2_STATIC_CAST(T,E) ((T)(E))\n+#endif\n+\n CF_EXTERN_C_BEGIN\n \n void JreThrowNullPointerException() __attribute__((noreturn));\n', 'addition_count': 6, 'deletion_count': 0, 'src_file': 'a/jre_emul/Classes/J2ObjC_common.h', 'tgt_file': 'b/jre_emul/Classes/J2ObjC_common.h', 'file_extension': '.h', 'before_file': '// Licensed under the Apache License, Version 2.0 (the "License");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an "AS IS" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Common definitions needed by all J2ObjC generated files.\n\n#ifndef _J2OBJC_COMMON_H_\n#define _J2OBJC_COMMON_H_\n\n#import <CoreFoundation/CoreFoundation.h>\n#import <Foundation/Foundation.h>\n\n#import "J2ObjC_types.h"\n\n@class IOSClass;\n@class JavaLangRefWeakReference;\n@protocol JavaLangIterable;\n\n#ifndef __has_feature\n#define __has_feature(x) 0  // Compatibility with non-clang compilers.\n#endif\n\n# ifndef OBJC_METHOD_FAMILY_NONE\n#  if __has_attribute(objc_method_family)\n#   define OBJC_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))\n#  else\n#   define OBJC_METHOD_FAMILY_NONE\n#  endif\n# endif\n\n# if __has_feature(objc_arc)\n#  define ARCBRIDGE __bridge\n#  define ARCBRIDGE_TRANSFER __bridge_transfer\n#  define ARC_CONSUME_PARAMETER __attribute((ns_consumed))\n#  define AUTORELEASE(x) x\n#  define RELEASE_(x) x\n#  define RETAIN_(x) x\n#  define RETAIN_AND_AUTORELEASE(x) x\n# else\n#  define ARCBRIDGE\n#  define ARCBRIDGE_TRANSFER\n#  define ARC_CONSUME_PARAMETER\n#  define AUTORELEASE(x) [x autorelease]\n#  define RELEASE_(x) [x release]\n#  define RETAIN_(x) [x retain]\n#  define RETAIN_AND_AUTORELEASE(x) [[x retain] autorelease]\n# endif\n\n#if __has_feature(objc_arc_weak)\n# define WEAK_ __weak\n#else\n# define WEAK_ __unsafe_unretained\n#endif\n\nCF_EXTERN_C_BEGIN\n\nid JreThrowNullPointerException(void) __attribute__((noreturn));\nvoid JreThrowClassCastException(id p, Class cls) __attribute__((noreturn));\n #define J2OBJC_DISABLE_ARRAY_TYPE_CHECKS 1\n#endif\n\nCF_EXTERN_C_BEGIN\n\nvoid JreThrowNullPointerException() __attribute__((noreturn));\nvoid JreCloneVolatileStrong(volatile_id *pVar, volatile_id *pOther);\nvoid JreReleaseVolatile(volatile_id *pVar);\nid JreRetainedLocalValue(id value);\n\nid JreRetainedWithAssign(id parent, __strong id *pIvar, id value);\nid JreVolatileRetainedWithAssign(id parent, volatile_id *pIvar, id value);\nvoid JreRetainedWithRelease(id parent, id child);\nvoid JreVolatileRetainedWithRelease(id parent, volatile_id *pVar);\n\nNSString *JreStrcat(const char *types, ...);\n\njboolean JreAnnotationEquals(id a1, id a2);\njint JreAnnotationHashCode(id a);\n\nNSUInteger JreDefaultFastEnumeration(\n    id<JavaLangIterable> obj, NSFastEnumerationState *state, id __unsafe_unretained *stackbuf);\n\nCF_EXTERN_C_END\n\n/*!\n * The nil_chk macro is used wherever a Java object is dereferenced and needs to\n * be checked for null. A macro is used instead of an inline function because it\n * allows the line number of the dereference to be derived from the stack frame.\n *\n * @param p The object to check for nil.\n */\n#define nil_chk(p) (p ?: JreThrowNullPointerException())\n\n#if !__has_feature(objc_arc)\n__attribute__((always_inline)) inline id JreAutoreleasedAssign(\n    id *pIvar, NS_RELEASES_ARGUMENT id value) {\n  [*pIvar autorelease];\n  return *pIvar = value;\n}\n#endif\n\n/*!\n * Utility macro for passing an argument that contains a comma.\n */\n#define J2OBJC_ARG(...) __VA_ARGS__\n\n#define J2OBJC_VOLATILE_ACCESS_DEFN(NAME, TYPE) \\\n  __attribute__((always_inline)) inline TYPE JreLoadVolatile##NAME(volatile_##TYPE *pVar) { \\\n    return __c11_atomic_load(pVar, __ATOMIC_SEQ_CST); \\\n  } \\\n  __attribute__((always_inline)) inline TYPE JreAssignVolatile##NAME( \\\n      volatile_##TYPE *pVar, TYPE value) { \\\n    __c11_atomic_store(pVar, value, __ATOMIC_SEQ_CST); \\\n    return value; \\\n  }\n\nJ2OBJC_VOLATILE_ACCESS_DEFN(Boolean, jboolean)\nJ2OBJC_VOLATILE_ACCESS_DEFN(Char, jchar)\nJ2OBJC_VOLATILE_ACCESS_DEFN(Byte, jbyte)\nJ2OBJC_VOLATILE_ACCESS_DEFN(Short, jshort)\nJ2OBJC_VOLATILE_ACCESS_DEFN(Int, jint)\nJ2OBJC_VOLATILE_ACCESS_DEFN(Long, jlong)\nJ2OBJC_VOLATILE_ACCESS_DEFN(Float, jfloat)\nJ2OBJC_VOLATILE_ACCESS_DEFN(Double, jdouble)\n#undef J2OBJC_VOLATILE_ACCESS_DEFN\n\n/*!\n * Defines the initialized flag for a class.\n *\n * @define J2OBJC_INITIALIZED_DEFN\n * @param CLASS The class for which the initialized flag is defined.\n */\n#define J2OBJC_INITIALIZED_DEFN(CLASS) \\\n  _Atomic(jboolean) CLASS##__initialized = false;\n\n/*!\n * Defines the code to set a class\'s initialized flag. This should be used at\n * the end of each class\'s initialize class method.\n *\n * @define J2OBJC_SET_INITIALIZED\n * @param CLASS The class who\'s flag is to be set.\n */\n#define J2OBJC_SET_INITIALIZED(CLASS) \\\n  __c11_atomic_store(&CLASS##__initialized, true, __ATOMIC_RELEASE);\n\n/*!\n * Defines an init function for a class that will ensure that the class is\n * initialized. For class "Foo" the function will have the following signature:\n *   inline void Foo_initialize();\n *\n * @define J2OBJC_STATIC_INIT\n * @param CLASS The class to declare the init function for.\n */\n#define J2OBJC_STATIC_INIT(CLASS)                                                           \\\n  FOUNDATION_EXPORT _Atomic(jboolean) CLASS##__initialized;                                 \\\n  __attribute__((always_inline)) inline void CLASS##_initialize(void) {                     \\\n    if (__builtin_expect(!__c11_atomic_load(&CLASS##__initialized, __ATOMIC_ACQUIRE), 0)) { \\\n      [CLASS class];                                                                        \\\n    }                                                                                       \\\n  }\n\n/*!\n * Defines an empty init function for a class that has no initialization code.\n *\n * @define J2OBJC_EMPTY_STATIC_INIT\n * @param CLASS The class to declare the init function for.\n */\n#define J2OBJC_EMPTY_STATIC_INIT(CLASS) \\\n  __attribute__((always_inline)) inline void CLASS##_initialize(void) {}\n\n/*!\n * Declares the type literal accessor for a type. This macro should be added to\n * the header of each generated Java type.\n *\n * @define J2OBJC_TYPE_LITERAL_HEADER\n * @param TYPE The name of the type to declare the accessor for.\n */\n#define J2OBJC_TYPE_LITERAL_HEADER(TYPE) \\\n  FOUNDATION_EXPORT IOSClass *TYPE##_class_(void);\n\n/*!\n * Defines the type literal accessor for a class or enum type. This macro should\n * be added to the implementation of each generated Java type.\n *\n * @define J2OBJC_CLASS_TYPE_LITERAL_SOURCE\n * @param TYPE The name of the type to define the accessor for.\n */\n#define J2OBJC_CLASS_TYPE_LITERAL_SOURCE(TYPE) \\\n  IOSClass *TYPE##_class_() { \\\n    static IOSClass *cls; \\\n    static dispatch_once_t token; \\\n    TYPE##_initialize(); \\\n    dispatch_once(&token, ^{ cls = IOSClass_fromClass([TYPE class]); }); \\\n    return cls; \\\n  }\n\n/*!\n * Defines the type literal accessor for a interface or annotation type. This\n * macro should be added to the implementation of each generated Java type.\n *\n * @define J2OBJC_INTERFACE_TYPE_LITERAL_SOURCE\n * @param TYPE The name of the type to define the accessor for.\n */\n#define J2OBJC_INTERFACE_TYPE_LITERAL_SOURCE(TYPE) \\\n  IOSClass *TYPE##_class_() { \\\n    static IOSClass *cls; \\\n    static dispatch_once_t token; \\\n    TYPE##_initialize(); \\\n    dispatch_once(&token, ^{ cls = IOSClass_fromProtocol(@protocol(TYPE)); }); \\\n    return cls; \\\n  }\n\n#if __has_feature(objc_arc)\n#define J2OBJC_FIELD_SETTER(CLASS, FIELD, TYPE) \\\n  __attribute__((unused)) static inline TYPE CLASS##_set_##FIELD(CLASS *instance, TYPE value) { \\\n    return instance->FIELD = value; \\\n  }\n#else\n#define J2OBJC_FIELD_SETTER(CLASS, FIELD, TYPE) \\\n  __attribute__((unused)) static inline TYPE CLASS##_set_##FIELD(CLASS *instance, TYPE value) { \\\n    return JreStrongAssign(&instance->FIELD, value); \\\n  }\\\n  __attribute__((unused)) static inline TYPE CLASS##_setAndConsume_##FIELD( \\\n        CLASS *instance, NS_RELEASES_ARGUMENT TYPE value) { \\\n    return JreStrongAssignAndConsume(&instance->FIELD, value); \\\n  }\n#endif\n\n#define J2OBJC_VOLATILE_FIELD_SETTER(CLASS, FIELD, TYPE) \\\n  __attribute__((unused)) static inline TYPE CLASS##_set_##FIELD(CLASS *instance, TYPE value) { \\\n    return JreVolatileStrongAssign(&instance->FIELD, value); \\\n  }\n\n/*!\n * Adds noop implementations for the memory management methods. This helps to\n * avoid the cost of incrementing and decrementing the retain count for objects\n * that should never be dealloc\'ed.\n *\n * @define J2OBJC_ETERNAL_SINGLETON\n */\n#define J2OBJC_ETERNAL_SINGLETON \\\n  - (id)retain { return self; } \\\n  - (oneway void)release {} \\\n  - (id)autorelease { return self; }\n\n/*!\n A type to represent an Objective C class.\n This is actually an `objc_class` but the runtime headers will not allow us to\n reference `objc_class`, so we have defined our own.\n\n Adapted from:\n https://github.com/protocolbuffers/protobuf/blob/master/objectivec/GPBRuntimeTypes.h\n*/\ntypedef struct J2ObjCClass_t J2ObjCClass_t;\n\n/*!\n Macros for generating a Class from a class name. These are used wherever a\n static Objective C class reference is needed for a generated class. Unlike\n "[classname class]", this macro doesn\'t trigger class initialization, avoiding\n the chance of Objective C initialization deadlocks.\n\n Adapted from:\n https://github.com/protocolbuffers/protobuf/blob/master/objectivec/GPBUtilities_PackagePrivate.h\n */\n#define J2OBJC_CLASS_SYMBOL(name) OBJC_CLASS_$_##name\n#define J2OBJC_CLASS_REFERENCE(name) \\\n    ((__bridge Class)&(J2OBJC_CLASS_SYMBOL(name)))\n#define J2OBJC_CLASS_DECLARATION(name) \\\n    extern const J2ObjCClass_t J2OBJC_CLASS_SYMBOL(name)\n\n#endif // _J2OBJC_COMMON_H_\n', 'message': 'Define STATIC_CAST macro to eliminate old-style-cast warnings with Objective-C++.\n\tChange on 2015/12/11 by tball <tball@google.com>\n-------------\nCreated by MOE: https://github.com/google/moe\nMOE_MIGRATED_REVID=110022707\n', 'author_name': 'Tom Ball', 'lang': 'h'}