Merge remote-tracking branch 'goog/mirror-m-wireless-internal-release' into master_merge
diff --git a/Android.mk b/Android.mk
index e4fba5c..a5ead4a 100644
--- a/Android.mk
+++ b/Android.mk
@@ -34,8 +34,8 @@
LOCAL_MODULE := libnativehelper
LOCAL_CLANG := true
LOCAL_CFLAGS := -Werror -fvisibility=protected
-LOCAL_C_INCLUDES := external/stlport/stlport bionic/ bionic/libstdc++/include libcore/include
-LOCAL_SHARED_LIBRARIES += libcutils libstlport libdl
+LOCAL_C_INCLUDES := libcore/include
+LOCAL_SHARED_LIBRARIES += libcutils libdl
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
include $(BUILD_SHARED_LIBRARY)
diff --git a/JNIHelp.cpp b/JNIHelp.cpp
index fcad2f4..49c4f94 100644
--- a/JNIHelp.cpp
+++ b/JNIHelp.cpp
@@ -14,6 +14,11 @@
* limitations under the License.
*/
+#if defined(__ANDROID__)
+/* libnativehelper is built by NDK 19 in one variant, which doesn't yet have the GNU strerror_r. */
+#undef _GNU_SOURCE
+#endif
+
#define LOG_TAG "JNIHelp"
#include "JniConstants.h"
@@ -54,12 +59,10 @@
}
private:
- C_JNIEnv* mEnv;
+ C_JNIEnv* const mEnv;
T mLocalRef;
- // Disallow copy and assignment.
- scoped_local_ref(const scoped_local_ref&);
- void operator=(const scoped_local_ref&);
+ DISALLOW_COPY_AND_ASSIGN(scoped_local_ref);
};
static jclass findClass(C_JNIEnv* env, const char* className) {
diff --git a/JniConstants.cpp b/JniConstants.cpp
index 9a77859..a07466d 100644
--- a/JniConstants.cpp
+++ b/JniConstants.cpp
@@ -76,6 +76,7 @@
jclass JniConstants::structTimevalClass;
jclass JniConstants::structUcredClass;
jclass JniConstants::structUtsnameClass;
+jclass JniConstants::zipEntryClass;
static jclass findClass(JNIEnv* env, const char* name) {
ScopedLocalRef<jclass> localClass(env, env->FindClass(name));
@@ -142,4 +143,5 @@
structTimevalClass = findClass(env, "android/system/StructTimeval");
structUcredClass = findClass(env, "android/system/StructUcred");
structUtsnameClass = findClass(env, "android/system/StructUtsname");
+ zipEntryClass = findClass(env, "java/util/zip/ZipEntry");
}
diff --git a/include/nativehelper/JNIHelp.h b/include/nativehelper/JNIHelp.h
index cfab8f7..bf01986 100644
--- a/include/nativehelper/JNIHelp.h
+++ b/include/nativehelper/JNIHelp.h
@@ -172,6 +172,20 @@
jniLogException(&env->functions, priority, tag, exception);
}
+#if !defined(DISALLOW_COPY_AND_ASSIGN)
+// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. It goes in the private:
+// declarations in a class.
+#if __cplusplus >= 201103L
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ TypeName(const TypeName&) = delete; \
+ void operator=(const TypeName&) = delete
+#else
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ TypeName(const TypeName&); \
+ void operator=(const TypeName&)
+#endif // __has_feature(cxx_deleted_functions)
+#endif // !defined(DISALLOW_COPY_AND_ASSIGN)
+
#endif
/*
diff --git a/include/nativehelper/JniConstants.h b/include/nativehelper/JniConstants.h
index 40a0315..2017e57 100644
--- a/include/nativehelper/JniConstants.h
+++ b/include/nativehelper/JniConstants.h
@@ -93,6 +93,7 @@
static jclass structTimevalClass;
static jclass structUcredClass;
static jclass structUtsnameClass;
+ static jclass zipEntryClass;
};
#define NATIVE_METHOD(className, functionName, signature) \
diff --git a/include/nativehelper/ScopedBytes.h b/include/nativehelper/ScopedBytes.h
index cb2614b..fec46e8 100644
--- a/include/nativehelper/ScopedBytes.h
+++ b/include/nativehelper/ScopedBytes.h
@@ -48,17 +48,15 @@
}
private:
- JNIEnv* mEnv;
- jobject mObject;
+ JNIEnv* const mEnv;
+ const jobject mObject;
jbyteArray mByteArray;
protected:
jbyte* mPtr;
private:
- // Disallow copy and assignment.
- ScopedBytes(const ScopedBytes&);
- void operator=(const ScopedBytes&);
+ DISALLOW_COPY_AND_ASSIGN(ScopedBytes);
};
class ScopedBytesRO : public ScopedBytes<true> {
diff --git a/include/nativehelper/ScopedFd.h b/include/nativehelper/ScopedFd.h
index 795f50c..5ef41f8 100644
--- a/include/nativehelper/ScopedFd.h
+++ b/include/nativehelper/ScopedFd.h
@@ -25,7 +25,7 @@
// but needs to be cleaned up on exit.
class ScopedFd {
public:
- explicit ScopedFd(int fd) : fd(fd) {
+ explicit ScopedFd(int fd) : fd_(fd) {
}
~ScopedFd() {
@@ -33,28 +33,26 @@
}
int get() const {
- return fd;
+ return fd_;
}
int release() __attribute__((warn_unused_result)) {
- int localFd = fd;
- fd = -1;
+ int localFd = fd_;
+ fd_ = -1;
return localFd;
}
void reset(int new_fd = -1) {
- if (fd != -1) {
- TEMP_FAILURE_RETRY(close(fd));
+ if (fd_ != -1) {
+ TEMP_FAILURE_RETRY(close(fd_));
}
- fd = new_fd;
+ fd_ = new_fd;
}
private:
- int fd;
+ int fd_;
- // Disallow copy and assignment.
- ScopedFd(const ScopedFd&);
- void operator=(const ScopedFd&);
+ DISALLOW_COPY_AND_ASSIGN(ScopedFd);
};
#endif // SCOPED_FD_H_included
diff --git a/include/nativehelper/ScopedLocalFrame.h b/include/nativehelper/ScopedLocalFrame.h
index 35b6ad8..b739e24 100644
--- a/include/nativehelper/ScopedLocalFrame.h
+++ b/include/nativehelper/ScopedLocalFrame.h
@@ -30,11 +30,9 @@
}
private:
- JNIEnv* mEnv;
+ JNIEnv* const mEnv;
- // Disallow copy and assignment.
- ScopedLocalFrame(const ScopedLocalFrame&);
- void operator=(const ScopedLocalFrame&);
+ DISALLOW_COPY_AND_ASSIGN(ScopedLocalFrame);
};
#endif // SCOPED_LOCAL_FRAME_H_included
diff --git a/include/nativehelper/ScopedLocalRef.h b/include/nativehelper/ScopedLocalRef.h
index 71d5776..6e30eb3 100644
--- a/include/nativehelper/ScopedLocalRef.h
+++ b/include/nativehelper/ScopedLocalRef.h
@@ -20,6 +20,7 @@
#include "jni.h"
#include <stddef.h>
+#include "JNIHelp.h" // for DISALLOW_COPY_AND_ASSIGN.
// A smart pointer that deletes a JNI local reference when it goes out of scope.
template<typename T>
@@ -52,12 +53,10 @@
}
private:
- JNIEnv* mEnv;
+ JNIEnv* const mEnv;
T mLocalRef;
- // Disallow copy and assignment.
- ScopedLocalRef(const ScopedLocalRef&);
- void operator=(const ScopedLocalRef&);
+ DISALLOW_COPY_AND_ASSIGN(ScopedLocalRef);
};
#endif // SCOPED_LOCAL_REF_H_included
diff --git a/include/nativehelper/ScopedPrimitiveArray.h b/include/nativehelper/ScopedPrimitiveArray.h
index d797b9d..b573bd6 100644
--- a/include/nativehelper/ScopedPrimitiveArray.h
+++ b/include/nativehelper/ScopedPrimitiveArray.h
@@ -50,11 +50,10 @@
const PRIMITIVE_TYPE& operator[](size_t n) const { return mRawArray[n]; } \
size_t size() const { return mEnv->GetArrayLength(mJavaArray); } \
private: \
- JNIEnv* mEnv; \
+ JNIEnv* const mEnv; \
PRIMITIVE_TYPE ## Array mJavaArray; \
PRIMITIVE_TYPE* mRawArray; \
- Scoped ## NAME ## ArrayRO(const Scoped ## NAME ## ArrayRO&); \
- void operator=(const Scoped ## NAME ## ArrayRO&); \
+ DISALLOW_COPY_AND_ASSIGN(Scoped ## NAME ## ArrayRO); \
}
INSTANTIATE_SCOPED_PRIMITIVE_ARRAY_RO(jboolean, Boolean);
@@ -101,11 +100,10 @@
PRIMITIVE_TYPE& operator[](size_t n) { return mRawArray[n]; } \
size_t size() const { return mEnv->GetArrayLength(mJavaArray); } \
private: \
- JNIEnv* mEnv; \
+ JNIEnv* const mEnv; \
PRIMITIVE_TYPE ## Array mJavaArray; \
PRIMITIVE_TYPE* mRawArray; \
- Scoped ## NAME ## ArrayRW(const Scoped ## NAME ## ArrayRW&); \
- void operator=(const Scoped ## NAME ## ArrayRW&); \
+ DISALLOW_COPY_AND_ASSIGN(Scoped ## NAME ## ArrayRW); \
}
INSTANTIATE_SCOPED_PRIMITIVE_ARRAY_RW(jboolean, Boolean);
diff --git a/include/nativehelper/ScopedStringChars.h b/include/nativehelper/ScopedStringChars.h
index cfbd247..688291d 100644
--- a/include/nativehelper/ScopedStringChars.h
+++ b/include/nativehelper/ScopedStringChars.h
@@ -61,14 +61,12 @@
}
private:
- JNIEnv* env_;
- jstring string_;
+ JNIEnv* const env_;
+ const jstring string_;
const jchar* chars_;
size_t size_;
- // Disallow copy and assignment.
- ScopedStringChars(const ScopedStringChars&);
- void operator=(const ScopedStringChars&);
+ DISALLOW_COPY_AND_ASSIGN(ScopedStringChars);
};
#endif // SCOPED_STRING_CHARS_H_included
diff --git a/include/nativehelper/ScopedUtfChars.h b/include/nativehelper/ScopedUtfChars.h
index 7761450..9cfa9a0 100644
--- a/include/nativehelper/ScopedUtfChars.h
+++ b/include/nativehelper/ScopedUtfChars.h
@@ -59,13 +59,11 @@
}
private:
- JNIEnv* env_;
- jstring string_;
+ JNIEnv* const env_;
+ const jstring string_;
const char* utf_chars_;
- // Disallow copy and assignment.
- ScopedUtfChars(const ScopedUtfChars&);
- void operator=(const ScopedUtfChars&);
+ DISALLOW_COPY_AND_ASSIGN(ScopedUtfChars);
};
#endif // SCOPED_UTF_CHARS_H_included
diff --git a/include/nativehelper/UniquePtr.h b/include/nativehelper/UniquePtr.h
index 50f75b2..ac88be1 100644
--- a/include/nativehelper/UniquePtr.h
+++ b/include/nativehelper/UniquePtr.h
@@ -18,11 +18,7 @@
#define UNIQUE_PTR_H_included
#include <cstdlib> // For NULL.
-
-// This is a fake declaration of std::swap to avoid including <algorithm>
-namespace std {
-template <class T> void swap(T&, T&);
-}
+#include "JNIHelp.h" // For DISALLOW_COPY_AND_ASSIGN.
// Default deleter for pointer types.
template <typename T>
@@ -85,11 +81,6 @@
}
}
- // Swap with another unique pointer.
- void swap(UniquePtr<T>& other) {
- std::swap(mPtr, other.mPtr);
- }
-
private:
// The raw pointer.
T* mPtr;
@@ -98,9 +89,7 @@
template <typename T2> bool operator==(const UniquePtr<T2>& p) const;
template <typename T2> bool operator!=(const UniquePtr<T2>& p) const;
- // Disallow copy and assignment.
- UniquePtr(const UniquePtr&);
- void operator=(const UniquePtr&);
+ DISALLOW_COPY_AND_ASSIGN(UniquePtr);
};
// Partial specialization for array types. Like std::unique_ptr, this removes
@@ -136,9 +125,7 @@
private:
T* mPtr;
- // Disallow copy and assignment.
- UniquePtr(const UniquePtr&);
- void operator=(const UniquePtr&);
+ DISALLOW_COPY_AND_ASSIGN(UniquePtr);
};
#if UNIQUE_PTR_TESTS