Move unix_lite_jni code into a C++ namespace.
RELNOTES: None.
PiperOrigin-RevId: 278463090
diff --git a/src/main/native/fsevents.cc b/src/main/native/fsevents.cc
index 22f9d98..74b2454 100644
--- a/src/main/native/fsevents.cc
+++ b/src/main/native/fsevents.cc
@@ -18,6 +18,8 @@
#include <list>
#include <string>
+namespace {
+
// A structure to pass around the FSEvents info and the list of paths.
struct JNIEventsDiffAwareness {
// FSEvents run loop (thread)
@@ -111,6 +113,8 @@
return reinterpret_cast<JNIEventsDiffAwareness *>(field);
}
+} // namespace
+
extern "C" JNIEXPORT void JNICALL
Java_com_google_devtools_build_lib_skyframe_MacOSXFsEventsDiffAwareness_run(
JNIEnv *env, jobject fsEventsDiffAwareness) {
diff --git a/src/main/native/latin1_jni_path.cc b/src/main/native/latin1_jni_path.cc
index 4f56511..572afa0 100644
--- a/src/main/native/latin1_jni_path.cc
+++ b/src/main/native/latin1_jni_path.cc
@@ -16,6 +16,8 @@
#include <string.h>
+namespace blaze_jni {
+
jstring NewStringLatin1(JNIEnv *env, const char *str) {
int len = strlen(str);
jchar buf[512];
@@ -92,3 +94,5 @@
* GetStringLatin1Chars.
*/
void ReleaseStringLatin1Chars(const char *s) { delete[] s; }
+
+} // namespace blaze_jni
diff --git a/src/main/native/latin1_jni_path.h b/src/main/native/latin1_jni_path.h
index d75589c..fa6754a 100644
--- a/src/main/native/latin1_jni_path.h
+++ b/src/main/native/latin1_jni_path.h
@@ -17,6 +17,8 @@
#include <jni.h>
+namespace blaze_jni {
+
// Latin1 <--> java.lang.String conversion functions.
// Derived from similar routines in Sun JDK. See:
// j2se/src/solaris/native/java/io/UnixFileSystem_md.c
@@ -44,4 +46,6 @@
*/
void ReleaseStringLatin1Chars(const char *s);
+} // namespace blaze_jni
+
#endif // THIRD_PARTY_BAZEL_SRC_MAIN_NATIVE_LATIN1_JNI_PATH_H_
diff --git a/src/main/native/unix_jni.cc b/src/main/native/unix_jni.cc
index d9eaf53..d2d3cc3 100644
--- a/src/main/native/unix_jni.cc
+++ b/src/main/native/unix_jni.cc
@@ -42,6 +42,8 @@
#define PORTABLE_O_DIRECTORY 0
#endif
+namespace blaze_jni {
+
// See unix_jni.h.
void PostException(JNIEnv *env, int error_number, const std::string& message) {
// Keep consistent with package-info.html!
@@ -154,17 +156,17 @@
// See unix_jni.h.
void PostFileException(JNIEnv *env, int error_number, const char *filename) {
- ::PostException(env, error_number,
- std::string(filename) + " (" + ErrorMessage(error_number)
- + ")");
+ PostException(
+ env, error_number,
+ std::string(filename) + " (" + ErrorMessage(error_number) + ")");
}
// See unix_jni.h.
void PostSystemException(JNIEnv *env, int error_number, const char *function,
const char *name) {
- ::PostException(env, error_number, std::string(function) + "(" +
- std::string(name) + ")" + " (" +
- ErrorMessage(error_number) + ")");
+ PostException(env, error_number,
+ std::string(function) + "(" + std::string(name) + ")" + " (" +
+ ErrorMessage(error_number) + ")");
}
// TODO(bazel-team): split out all the FileSystem class's native methods
@@ -178,7 +180,7 @@
char target[PATH_MAX] = "";
jstring r = NULL;
if (readlink(path_chars, target, arraysize(target)) == -1) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
} else {
r = NewStringLatin1(env, target);
}
@@ -193,7 +195,7 @@
jint mode) {
const char *path_chars = GetStringLatin1Chars(env, path);
if (chmod(path_chars, static_cast<int>(mode)) == -1) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
}
ReleaseStringLatin1Chars(path_chars);
}
@@ -205,7 +207,7 @@
const char *oldpath_chars = GetStringLatin1Chars(env, oldpath);
const char *newpath_chars = GetStringLatin1Chars(env, newpath);
if (link_function(oldpath_chars, newpath_chars) == -1) {
- ::PostFileException(env, errno, newpath_chars);
+ PostFileException(env, errno, newpath_chars);
}
ReleaseStringLatin1Chars(oldpath_chars);
ReleaseStringLatin1Chars(newpath_chars);
@@ -327,15 +329,15 @@
// ENOMEM -> OutOfMemoryError
if (PostRuntimeException(env, saved_errno, path_chars)) {
- ::ReleaseStringLatin1Chars(path_chars);
+ ReleaseStringLatin1Chars(path_chars);
return NULL;
} else if (should_throw) {
- ::PostFileException(env, saved_errno, path_chars);
- ::ReleaseStringLatin1Chars(path_chars);
+ PostFileException(env, saved_errno, path_chars);
+ ReleaseStringLatin1Chars(path_chars);
return NULL;
}
}
- ::ReleaseStringLatin1Chars(path_chars);
+ ReleaseStringLatin1Chars(path_chars);
return should_throw
? NewFileStatus(env, statbuf)
@@ -352,7 +354,7 @@
Java_com_google_devtools_build_lib_unix_NativePosixFiles_stat(JNIEnv *env,
jclass clazz,
jstring path) {
- return ::StatCommon(env, path, portable_stat, true);
+ return StatCommon(env, path, portable_stat, true);
}
/*
@@ -365,7 +367,7 @@
Java_com_google_devtools_build_lib_unix_NativePosixFiles_lstat(JNIEnv *env,
jclass clazz,
jstring path) {
- return ::StatCommon(env, path, portable_lstat, true);
+ return StatCommon(env, path, portable_lstat, true);
}
/*
@@ -377,7 +379,7 @@
Java_com_google_devtools_build_lib_unix_NativePosixFiles_errnoStat(JNIEnv *env,
jclass clazz,
jstring path) {
- return ::StatCommon(env, path, portable_stat, false);
+ return StatCommon(env, path, portable_stat, false);
}
/*
@@ -389,7 +391,7 @@
Java_com_google_devtools_build_lib_unix_NativePosixFiles_errnoLstat(JNIEnv *env,
jclass clazz,
jstring path) {
- return ::StatCommon(env, path, portable_lstat, false);
+ return StatCommon(env, path, portable_lstat, false);
}
/*
@@ -408,7 +410,7 @@
#ifdef __linux
struct timespec spec[2] = {{0, UTIME_OMIT}, {modtime, now ? UTIME_NOW : 0}};
if (::utimensat(AT_FDCWD, path_chars, spec, 0) == -1) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
}
#else
struct utimbuf buf = { modtime, modtime };
@@ -417,7 +419,7 @@
// EACCES ENOENT EMULTIHOP ELOOP EINTR
// ENOTDIR ENOLINK EPERM EROFS -> IOException
// EFAULT ENAMETOOLONG -> RuntimeException
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
}
#endif
ReleaseStringLatin1Chars(path_chars);
@@ -457,7 +459,7 @@
if (errno == EEXIST) {
result = false;
} else {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
}
}
ReleaseStringLatin1Chars(path_chars);
@@ -484,11 +486,11 @@
if (portable_stat(path_chars, &statbuf) == 0) {
if (!S_ISDIR(statbuf.st_mode)) {
// Exists but is not a directory.
- ::PostFileException(env, ENOTDIR, path_chars);
+ PostFileException(env, ENOTDIR, path_chars);
}
goto cleanup;
} else if (errno != ENOENT) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
goto cleanup;
}
@@ -506,7 +508,7 @@
// with ENOTDIR.
break;
} else if (errno != ENOENT) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
goto cleanup;
}
}
@@ -522,23 +524,23 @@
// Note that somebody could have raced to create a file here, but that
// will get handled by a ENOTDIR by a subsequent mkdir call.
if (res != 0 && errno != EEXIST) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
goto cleanup;
}
}
}
if (::mkdir(path_chars, mode) != 0) {
if (errno != EEXIST) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
goto cleanup;
}
if (portable_stat(path_chars, &statbuf) != 0) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
goto cleanup;
}
if (!S_ISDIR(statbuf.st_mode)) {
// Exists but is not a directory.
- ::PostFileException(env, ENOTDIR, path_chars);
+ PostFileException(env, ENOTDIR, path_chars);
goto cleanup;
}
}
@@ -610,7 +612,7 @@
if (dirh == NULL) {
// EACCES EMFILE ENFILE ENOENT ENOTDIR -> IOException
// ENOMEM -> OutOfMemoryError
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
}
ReleaseStringLatin1Chars(path_chars);
if (dirh == NULL) {
@@ -632,7 +634,7 @@
if (errno == EINTR) continue; // interrupted by a signal
if (errno == EIO) continue; // glibc returns this on transient errors
// Otherwise, this is a real error we should report.
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
::closedir(dirh);
return NULL;
}
@@ -648,7 +650,7 @@
}
if (::closedir(dirh) < 0 && errno != EINTR) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
return NULL;
}
@@ -700,7 +702,7 @@
// EFAULT ENAMETOOLONG -> RuntimeException
// ENOMEM -> OutOfMemoryError
std::string filename(std::string(oldpath_chars) + " -> " + newpath_chars);
- ::PostFileException(env, errno, filename.c_str());
+ PostFileException(env, errno, filename.c_str());
}
ReleaseStringLatin1Chars(oldpath_chars);
ReleaseStringLatin1Chars(newpath_chars);
@@ -723,7 +725,7 @@
bool ok = remove(path_chars) != -1;
if (!ok) {
if (errno != ENOENT && errno != ENOTDIR) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
}
}
ReleaseStringLatin1Chars(path_chars);
@@ -743,7 +745,7 @@
jint mode) {
const char *path_chars = GetStringLatin1Chars(env, path);
if (mkfifo(path_chars, mode) == -1) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
}
ReleaseStringLatin1Chars(path_chars);
}
@@ -986,7 +988,7 @@
&attr_not_found);
if (size == -1) {
if (!attr_not_found) {
- ::PostFileException(env, errno, path_chars);
+ PostFileException(env, errno, path_chars);
}
} else {
result = env->NewByteArray(size);
@@ -1002,7 +1004,7 @@
jclass clazz,
jstring path,
jstring name) {
- return ::getxattr_common(env, path, name, ::portable_getxattr);
+ return getxattr_common(env, path, name, portable_getxattr);
}
extern "C" JNIEXPORT jbyteArray JNICALL
@@ -1010,7 +1012,7 @@
jclass clazz,
jstring path,
jstring name) {
- return ::getxattr_common(env, path, name, ::portable_lgetxattr);
+ return getxattr_common(env, path, name, portable_lgetxattr);
}
extern "C" JNIEXPORT jint JNICALL
@@ -1023,8 +1025,8 @@
}
if (fd == -1) {
// The interface only allows FileNotFoundException.
- ::PostException(env, ENOENT,
- std::string(path_chars) + " (" + ErrorMessage(errno) + ")");
+ PostException(env, ENOENT,
+ std::string(path_chars) + " (" + ErrorMessage(errno) + ")");
}
ReleaseStringLatin1Chars(path_chars);
return fd;
@@ -1036,7 +1038,7 @@
jint fd,
jobject ingore) {
if (close(fd) == -1) {
- ::PostException(env, errno, "error when closing file");
+ PostException(env, errno, "error when closing file");
}
}
@@ -1053,7 +1055,7 @@
}
jbyte *buf = static_cast<jbyte *>(malloc(len));
if (buf == nullptr) {
- ::PostException(env, ENOMEM, "out of memory");
+ PostException(env, ENOMEM, "out of memory");
return;
}
env->GetByteArrayRegion(data, off, len, buf);
@@ -1066,7 +1068,7 @@
ssize_t res = write(fd, p, len);
if (res == -1) {
if (errno != EINTR) {
- ::PostException(env, errno, "writing file failed");
+ PostException(env, errno, "writing file failed");
break;
}
} else {
@@ -1085,7 +1087,7 @@
long r;
size_t len = sizeof(r);
if (portable_sysctlbyname(name_chars, &r, &len) == -1) {
- ::PostSystemException(env, errno, "sysctlbyname", name_chars);
+ PostSystemException(env, errno, "sysctlbyname", name_chars);
}
ReleaseStringLatin1Chars(name_chars);
return (jlong)r;
@@ -1099,7 +1101,7 @@
extern "C" JNIEXPORT jint JNICALL
Java_com_google_devtools_build_lib_platform_SleepPreventionModule_00024SleepPrevention_pushDisableSleep(
JNIEnv *, jclass) {
- return ::portable_push_disable_sleep();
+ return portable_push_disable_sleep();
}
/*
@@ -1110,5 +1112,7 @@
extern "C" JNIEXPORT jint JNICALL
Java_com_google_devtools_build_lib_platform_SleepPreventionModule_00024SleepPrevention_popDisableSleep(
JNIEnv *, jclass) {
- return ::portable_pop_disable_sleep();
+ return portable_pop_disable_sleep();
}
+
+} // namespace blaze_jni
diff --git a/src/main/native/unix_jni.h b/src/main/native/unix_jni.h
index 4fef085..4769458 100644
--- a/src/main/native/unix_jni.h
+++ b/src/main/native/unix_jni.h
@@ -22,6 +22,8 @@
#include <string>
+namespace blaze_jni {
+
#define CHECK(condition) \
do { \
if (!(condition)) { \
@@ -108,4 +110,6 @@
int portable_push_disable_sleep();
int portable_pop_disable_sleep();
+} // namespace blaze_jni
+
#endif // BAZEL_SRC_MAIN_NATIVE_UNIX_JNI_H__
diff --git a/src/main/native/unix_jni_darwin.cc b/src/main/native/unix_jni_darwin.cc
index eb4ece8..c2d668d 100644
--- a/src/main/native/unix_jni_darwin.cc
+++ b/src/main/native/unix_jni_darwin.cc
@@ -31,6 +31,8 @@
#include <mutex> // NOLINT
#include <string>
+namespace blaze_jni {
+
const int PATH_MAX2 = PATH_MAX * 2;
using std::string;
@@ -165,3 +167,5 @@
}
return 0;
}
+
+} // namespace blaze_jni
diff --git a/src/main/native/unix_jni_freebsd.cc b/src/main/native/unix_jni_freebsd.cc
index 9835a49..be0d59b 100644
--- a/src/main/native/unix_jni_freebsd.cc
+++ b/src/main/native/unix_jni_freebsd.cc
@@ -27,6 +27,8 @@
#include <string>
+namespace blaze_jni {
+
using std::string;
// See unix_jni.h.
@@ -101,3 +103,5 @@
// https://wiki.freebsd.org/SuspendResume
return -1;
}
+
+} // namespace blaze_jni
diff --git a/src/main/native/unix_jni_linux.cc b/src/main/native/unix_jni_linux.cc
index 0079571..7408526 100644
--- a/src/main/native/unix_jni_linux.cc
+++ b/src/main/native/unix_jni_linux.cc
@@ -22,6 +22,8 @@
#include <string>
+namespace blaze_jni {
+
std::string ErrorMessage(int error_number) {
char buf[1024] = "";
@@ -101,3 +103,5 @@
// Currently not supported.
return -1;
}
+
+} // namespace blaze_jni