Skip to content

Commit

Permalink
Run clang-format and apply patches
Browse files Browse the repository at this point in the history
Summary:
Run clang-format and add .clang-tidy with `clang-diagnostic-*` to several more directories in order to catch any problems.

Changelog:
[Internal]

Reviewed By: shergin

Differential Revision: D19860169

fbshipit-source-id: 7785aab010c8e6945cc6b5c9b68cb8ee0cdbb7fa
  • Loading branch information
hramos authored and facebook-github-bot committed Feb 27, 2020
1 parent f0c7178 commit 8ae3174
Show file tree
Hide file tree
Showing 41 changed files with 1,729 additions and 1,399 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "HermesSamplingProfiler.h"

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return facebook::jni::initialize(vm, [] {
facebook::jsi::jni::HermesSamplingProfiler::registerNatives();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HermesExecutorFactory : public JSExecutorFactory {
public:
explicit HermesExecutorFactory(
JSIExecutor::RuntimeInstaller runtimeInstaller,
const JSIScopedTimeoutInvoker& timeoutInvoker =
const JSIScopedTimeoutInvoker &timeoutInvoker =
JSIExecutor::defaultTimeoutInvoker,
::hermes::vm::RuntimeConfig runtimeConfig = ::hermes::vm::RuntimeConfig())
: runtimeInstaller_(runtimeInstaller),
Expand All @@ -44,7 +44,7 @@ class HermesExecutor : public JSIExecutor {
std::shared_ptr<jsi::Runtime> runtime,
std::shared_ptr<ExecutorDelegate> delegate,
std::shared_ptr<MessageQueueThread> jsQueue,
const JSIScopedTimeoutInvoker& timeoutInvoker,
const JSIScopedTimeoutInvoker &timeoutInvoker,
RuntimeInstaller runtimeInstaller);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
namespace facebook {
namespace react {

CallInvokerHolder::CallInvokerHolder(
std::shared_ptr<CallInvoker> callInvoker)
CallInvokerHolder::CallInvokerHolder(std::shared_ptr<CallInvoker> callInvoker)
: _callInvoker(callInvoker) {}

std::shared_ptr<CallInvoker> CallInvokerHolder::getCallInvoker() {
Expand Down
5 changes: 5 additions & 0 deletions ReactAndroid/src/main/jni/first-party/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
Checks: '>
clang-diagnostic-*,
'
...
30 changes: 15 additions & 15 deletions ReactAndroid/src/main/jni/first-party/fb/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

#include <cstdarg>
#include <stdio.h>
#include <cstdarg>

#include <fb/assert.h>
#include <fb/log.h>
Expand All @@ -17,23 +17,23 @@ namespace facebook {
static char sAssertBuf[ASSERT_BUF_SIZE];
static AssertHandler gAssertHandler;

void assertInternal(const char* formatstr ...) {
va_list va_args;
va_start(va_args, formatstr);
vsnprintf(sAssertBuf, sizeof(sAssertBuf), formatstr, va_args);
va_end(va_args);
if (gAssertHandler != NULL) {
gAssertHandler(sAssertBuf);
}
FBLOG(LOG_FATAL, "fbassert", "%s", sAssertBuf);
// crash at this specific address so that we can find our crashes easier
*(int*)0xdeadb00c = 0;
// let the compiler know we won't reach the end of the function
__builtin_unreachable();
void assertInternal(const char *formatstr...) {
va_list va_args;
va_start(va_args, formatstr);
vsnprintf(sAssertBuf, sizeof(sAssertBuf), formatstr, va_args);
va_end(va_args);
if (gAssertHandler != NULL) {
gAssertHandler(sAssertBuf);
}
FBLOG(LOG_FATAL, "fbassert", "%s", sAssertBuf);
// crash at this specific address so that we can find our crashes easier
*(int *)0xdeadb00c = 0;
// let the compiler know we won't reach the end of the function
__builtin_unreachable();
}

void setAssertHandler(AssertHandler assertHandler) {
gAssertHandler = assertHandler;
gAssertHandler = assertHandler;
}

} // namespace facebook
61 changes: 31 additions & 30 deletions ReactAndroid/src/main/jni/first-party/fb/include/fb/ALog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,64 @@
namespace facebook {
namespace alog {

template<typename... ARGS>
inline void log(int level, const char* tag, const char* msg, ARGS... args) noexcept {
template <typename... ARGS>
inline void
log(int level, const char *tag, const char *msg, ARGS... args) noexcept {
__android_log_print(level, tag, msg, args...);
}

template<typename... ARGS>
inline void log(int level, const char* tag, const char* msg) noexcept {
template <typename... ARGS>
inline void log(int level, const char *tag, const char *msg) noexcept {
__android_log_write(level, tag, msg);
}

template<typename... ARGS>
inline void logv(const char* tag, const char* msg, ARGS... args) noexcept {
template <typename... ARGS>
inline void logv(const char *tag, const char *msg, ARGS... args) noexcept {
log(ANDROID_LOG_VERBOSE, tag, msg, args...);
}

template<typename... ARGS>
inline void logd(const char* tag, const char* msg, ARGS... args) noexcept {
template <typename... ARGS>
inline void logd(const char *tag, const char *msg, ARGS... args) noexcept {
log(ANDROID_LOG_DEBUG, tag, msg, args...);
}

template<typename... ARGS>
inline void logi(const char* tag, const char* msg, ARGS... args) noexcept {
template <typename... ARGS>
inline void logi(const char *tag, const char *msg, ARGS... args) noexcept {
log(ANDROID_LOG_INFO, tag, msg, args...);
}

template<typename... ARGS>
inline void logw(const char* tag, const char* msg, ARGS... args) noexcept {
template <typename... ARGS>
inline void logw(const char *tag, const char *msg, ARGS... args) noexcept {
log(ANDROID_LOG_WARN, tag, msg, args...);
}

template<typename... ARGS>
inline void loge(const char* tag, const char* msg, ARGS... args) noexcept {
template <typename... ARGS>
inline void loge(const char *tag, const char *msg, ARGS... args) noexcept {
log(ANDROID_LOG_ERROR, tag, msg, args...);
}

template<typename... ARGS>
inline void logf(const char* tag, const char* msg, ARGS... args) noexcept {
template <typename... ARGS>
inline void logf(const char *tag, const char *msg, ARGS... args) noexcept {
log(ANDROID_LOG_FATAL, tag, msg, args...);
}


#ifdef LOG_TAG
# define ALOGV(...) ::facebook::alog::logv(LOG_TAG, __VA_ARGS__)
# define ALOGD(...) ::facebook::alog::logd(LOG_TAG, __VA_ARGS__)
# define ALOGI(...) ::facebook::alog::logi(LOG_TAG, __VA_ARGS__)
# define ALOGW(...) ::facebook::alog::logw(LOG_TAG, __VA_ARGS__)
# define ALOGE(...) ::facebook::alog::loge(LOG_TAG, __VA_ARGS__)
# define ALOGF(...) ::facebook::alog::logf(LOG_TAG, __VA_ARGS__)
#define ALOGV(...) ::facebook::alog::logv(LOG_TAG, __VA_ARGS__)
#define ALOGD(...) ::facebook::alog::logd(LOG_TAG, __VA_ARGS__)
#define ALOGI(...) ::facebook::alog::logi(LOG_TAG, __VA_ARGS__)
#define ALOGW(...) ::facebook::alog::logw(LOG_TAG, __VA_ARGS__)
#define ALOGE(...) ::facebook::alog::loge(LOG_TAG, __VA_ARGS__)
#define ALOGF(...) ::facebook::alog::logf(LOG_TAG, __VA_ARGS__)
#endif

}}
} // namespace alog
} // namespace facebook

#else
# define ALOGV(...) ((void)0)
# define ALOGD(...) ((void)0)
# define ALOGI(...) ((void)0)
# define ALOGW(...) ((void)0)
# define ALOGE(...) ((void)0)
# define ALOGF(...) ((void)0)
#define ALOGV(...) ((void)0)
#define ALOGD(...) ((void)0)
#define ALOGI(...) ((void)0)
#define ALOGW(...) ((void)0)
#define ALOGE(...) ((void)0)
#define ALOGF(...) ((void)0)
#endif
12 changes: 6 additions & 6 deletions ReactAndroid/src/main/jni/first-party/fb/include/fb/Build.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdlib.h>

#if defined(__ANDROID__)
# include <sys/system_properties.h>
#include <sys/system_properties.h>
#endif

namespace facebook {
Expand All @@ -19,13 +19,13 @@ namespace build {
struct Build {
static int getAndroidSdk() {
static auto android_sdk = ([] {
char sdk_version_str[PROP_VALUE_MAX];
__system_property_get("ro.build.version.sdk", sdk_version_str);
return atoi(sdk_version_str);
char sdk_version_str[PROP_VALUE_MAX];
__system_property_get("ro.build.version.sdk", sdk_version_str);
return atoi(sdk_version_str);
})();
return android_sdk;
}
};

} // build
} // facebook
} // namespace build
} // namespace facebook
16 changes: 8 additions & 8 deletions ReactAndroid/src/main/jni/first-party/fb/include/fb/Countable.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
*/

#pragma once
#include <atomic>
#include <fb/RefPtr.h>
#include <fb/assert.h>
#include <fb/noncopyable.h>
#include <fb/nonmovable.h>
#include <fb/RefPtr.h>
#include <atomic>

namespace facebook {

class Countable : public noncopyable, public nonmovable {
public:
public:
// RefPtr expects refcount to start at 0
Countable() : m_refcount(0) {}
virtual ~Countable()
{
virtual ~Countable() {
FBASSERT(m_refcount == 0);
}

private:
private:
void ref() {
++m_refcount;
}
Expand All @@ -38,8 +37,9 @@ class Countable : public noncopyable, public nonmovable {
return m_refcount == 1;
}

template <typename T> friend class RefPtr;
template <typename T>
friend class RefPtr;
std::atomic<int> m_refcount;
};

}
} // namespace facebook
71 changes: 38 additions & 33 deletions ReactAndroid/src/main/jni/first-party/fb/include/fb/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,65 @@
*/

#pragma once
#include <jni.h>
#include <functional>
#include <string>
#include <jni.h>

#include <fb/visibility.h>

namespace facebook {
namespace jni {

namespace internal {
struct CacheEnvTag {};
}
struct CacheEnvTag {};
} // namespace internal

// Keeps a thread-local reference to the current thread's JNIEnv.
struct Environment {
// May be null if this thread isn't attached to the JVM
FBEXPORT static JNIEnv* current();
static void initialize(JavaVM* vm);
FBEXPORT static JNIEnv *current();
static void initialize(JavaVM *vm);

// There are subtle issues with calling the next functions directly. It is
// much better to always use a ThreadScope to manage attaching/detaching for
// you.
FBEXPORT static JNIEnv* ensureCurrentThreadIsAttached();
FBEXPORT static JNIEnv *ensureCurrentThreadIsAttached();
FBEXPORT static void detachCurrentThread();
};

/**
* RAII Object that attaches a thread to the JVM. Failing to detach from a thread before it
* exits will cause a crash, as will calling Detach an extra time, and this guard class helps
* keep that straight. In addition, it remembers whether it performed the attach or not, so it
* is safe to nest it with itself or with non-fbjni code that manages the attachment correctly.
* RAII Object that attaches a thread to the JVM. Failing to detach from a
* thread before it exits will cause a crash, as will calling Detach an extra
* time, and this guard class helps keep that straight. In addition, it
* remembers whether it performed the attach or not, so it is safe to nest it
* with itself or with non-fbjni code that manages the attachment correctly.
*
* Potential concerns:
* - Attaching to the JVM is fast (~100us on MotoG), but ideally you would attach while the
* app is not busy.
* - Having a thread detach at arbitrary points is not safe in Dalvik; you need to be sure that
* there is no Java code on the current stack or you run the risk of a crash like:
* ERROR: detaching thread with interp frames (count=18)
* (More detail at https://groups.google.com/forum/#!topic/android-ndk/2H8z5grNqjo)
* ThreadScope won't do a detach if the thread was already attached before the guard is
* - Attaching to the JVM is fast (~100us on MotoG), but ideally you would
* attach while the app is not busy.
* - Having a thread detach at arbitrary points is not safe in Dalvik; you need
* to be sure that there is no Java code on the current stack or you run the
* risk of a crash like: ERROR: detaching thread with interp frames (count=18)
* (More detail at
* https://groups.google.com/forum/#!topic/android-ndk/2H8z5grNqjo) ThreadScope
* won't do a detach if the thread was already attached before the guard is
* instantiated, but there's probably some usage that could trip this up.
* - Newly attached C++ threads only get the bootstrap class loader -- i.e. java language
* classes, not any of our application's classes. This will be different behavior than threads
* that were initiated on the Java side. A workaround is to pass a global reference for a
* class or instance to the new thread; this bypasses the need for the class loader.
* (See http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html#attach_current_thread)
* If you need access to the application's classes, you can use ThreadScope::WithClassLoader.
* - Newly attached C++ threads only get the bootstrap class loader -- i.e.
* java language classes, not any of our application's classes. This will be
* different behavior than threads that were initiated on the Java side. A
* workaround is to pass a global reference for a class or instance to the new
* thread; this bypasses the need for the class loader. (See
* http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html#attach_current_thread)
* If you need access to the application's classes, you can use
* ThreadScope::WithClassLoader.
*/
class FBEXPORT ThreadScope {
public:
ThreadScope();
ThreadScope(ThreadScope&) = delete;
ThreadScope(ThreadScope&&) = default;
ThreadScope& operator=(ThreadScope&) = delete;
ThreadScope& operator=(ThreadScope&&) = delete;
ThreadScope(ThreadScope &) = delete;
ThreadScope(ThreadScope &&) = default;
ThreadScope &operator=(ThreadScope &) = delete;
ThreadScope &operator=(ThreadScope &&) = delete;
~ThreadScope();

/**
Expand All @@ -69,20 +73,21 @@ class FBEXPORT ThreadScope {
* running in the closure will have access to the same classes as in a normal
* java-create thread.
*/
static void WithClassLoader(std::function<void()>&& runnable);
static void WithClassLoader(std::function<void()> &&runnable);

static void OnLoad();

// This constructor is only used internally by fbjni.
ThreadScope(JNIEnv*, internal::CacheEnvTag);
ThreadScope(JNIEnv *, internal::CacheEnvTag);

private:
friend struct Environment;
ThreadScope* previous_;
ThreadScope *previous_;
// If the JNIEnv* is set, it is guaranteed to be valid at least through the
// lifetime of this ThreadScope. The only case where that guarantee can be
// made is when there is a java frame in the stack below this.
JNIEnv* env_;
JNIEnv *env_;
bool attachedWithThisScope_;
};
}
}
} // namespace jni
} // namespace facebook
Loading

0 comments on commit 8ae3174

Please sign in to comment.