Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add core .clang-format and format all source #4087

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add core .clang-format and clang-format all cpp/hpp files
Using: for i in `find src -name "*.?pp" | grep -v catch`;  do echo $i; clang-format --style=file $i -i; done
  • Loading branch information
realm-ci authored and Tom Duncalf committed Nov 22, 2021
commit ff52a40b8541ef55ae1feb7b917f44f8fecb1170
136 changes: 136 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
BasedOnStyle: LLVM
TabWidth: 4
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved
UseTab: Never
---
Language: JavaScript
DisableFormat: true
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 118
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
- SECTION
- TEST_CASE
- DYNAMIC_SECTION
- BENCHMARK
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseTab: Never
kraenhansen marked this conversation as resolved.
Show resolved Hide resolved
...

24 changes: 12 additions & 12 deletions src/android/hack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@

#if REALM_WRAP_MEMMOVE
extern "C" {
void* __wrap_memmove(void *dest, const void *src, size_t n);
void* __real_memmove(void *dest, const void *src, size_t n);
void* __wrap_memmove(void* dest, const void* src, size_t n);
void* __real_memmove(void* dest, const void* src, size_t n);

void* __wrap_memcpy(void *dest, const void *src, size_t n);
void* __real_memcpy(void *dest, const void *src, size_t n);
void* __wrap_memcpy(void* dest, const void* src, size_t n);
void* __real_memcpy(void* dest, const void* src, size_t n);
}

using namespace realm::jni_util;

typedef void* (*MemMoveFunc)(void *dest, const void *src, size_t n);
typedef void* (*MemMoveFunc)(void* dest, const void* src, size_t n);
static MemMoveFunc s_wrap_memmove_ptr = &__real_memmove;
static MemMoveFunc s_wrap_memcpy_ptr = &__real_memcpy;

Expand Down Expand Up @@ -71,12 +71,12 @@ static void* hacked_memcpy(void* s1, const void* s2, size_t n)
return static_cast<void*>(s1);
}

void* __wrap_memmove(void *dest, const void *src, size_t n)
void* __wrap_memmove(void* dest, const void* src, size_t n)
{
return (*s_wrap_memmove_ptr)(dest, src, n);
}

void* __wrap_memcpy(void *dest, const void *src, size_t n)
void* __wrap_memcpy(void* dest, const void* src, size_t n)
{
return (*s_wrap_memcpy_ptr)(dest, src, n);
}
Expand All @@ -93,9 +93,10 @@ static void check_memmove()
size_t len = strlen(array);
void* ptr = __real_memmove(array + 1, array, len - 1);
if (ptr != array + 1 || strncmp(array, "FFooba", len) != 0) {
__android_log_print(ANDROID_LOG_DEBUG, "JSRealm", "memmove is broken on this device. Switching to the builtin implementation.");
__android_log_print(ANDROID_LOG_DEBUG, "JSRealm",
"memmove is broken on this device. Switching to the builtin implementation.");
s_wrap_memmove_ptr = &hacked_memmove;
s_wrap_memcpy_ptr = &hacked_memcpy;
s_wrap_memcpy_ptr = &hacked_memcpy;
}
free(array);
}
Expand All @@ -111,6 +112,5 @@ void hack_init()
#endif
}

}
}

} // namespace jni_util
} // namespace realm
4 changes: 2 additions & 2 deletions src/android/hack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ namespace jni_util {
// Workaround bugs on some devices.
void hack_init();

}
}
} // namespace jni_util
} // namespace realm
#endif // REALM_JNI_UTIL_HACK_HPP
41 changes: 20 additions & 21 deletions src/android/io_realm_react_RealmReactModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
using namespace realm::rpc;
using namespace realm::jni_util;

static RPCServer *s_rpc_server;
static RPCServer* s_rpc_server;
extern bool realmContextInjected;
jclass ssl_helper_class;

namespace realm {
// set the AssetManager used to access bundled files within the APK
void set_asset_manager(AAssetManager* assetManager);
}
namespace realm {
// set the AssetManager used to access bundled files within the APK
void set_asset_manager(AAssetManager* assetManager);
} // namespace realm

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*)
{
Expand Down Expand Up @@ -70,13 +70,14 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void*)
}
}

JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_setDefaultRealmFileDirectory
(JNIEnv *env, jclass, jstring fileDir, jobject javaAssetManager)
JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_setDefaultRealmFileDirectory(JNIEnv* env, jclass,
jstring fileDir,
jobject javaAssetManager)
{
__android_log_print(ANDROID_LOG_VERBOSE, "JSRealm", "setDefaultRealmFileDirectory");

// Get the assetManager in case we want to copy files from the APK (assets)
AAssetManager *assetManager = AAssetManager_fromJava(env, javaAssetManager);
AAssetManager* assetManager = AAssetManager_fromJava(env, javaAssetManager);
if (assetManager == NULL) {
__android_log_print(ANDROID_LOG_ERROR, "JSRealm", "Error loading the AssetManager");
}
Expand All @@ -87,11 +88,11 @@ JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_setDefaultRealmFileD
realm::set_default_realm_file_directory(strFileDir);
env->ReleaseStringUTFChars(fileDir, strFileDir);

__android_log_print(ANDROID_LOG_DEBUG, "JSRealm", "Absolute path: %s", realm::default_realm_file_directory().c_str());
__android_log_print(ANDROID_LOG_DEBUG, "JSRealm", "Absolute path: %s",
realm::default_realm_file_directory().c_str());
}

JNIEXPORT jlong JNICALL Java_io_realm_react_RealmReactModule_setupChromeDebugModeRealmJsContext
(JNIEnv *, jclass)
JNIEXPORT jlong JNICALL Java_io_realm_react_RealmReactModule_setupChromeDebugModeRealmJsContext(JNIEnv*, jclass)
{
__android_log_print(ANDROID_LOG_VERBOSE, "JSRealm", "setupChromeDebugModeRealmJsContext");
if (s_rpc_server) {
Expand All @@ -101,8 +102,9 @@ JNIEXPORT jlong JNICALL Java_io_realm_react_RealmReactModule_setupChromeDebugMod
return (jlong)s_rpc_server;
}

JNIEXPORT jstring JNICALL Java_io_realm_react_RealmReactModule_processChromeDebugCommand
(JNIEnv *env, jclass, jstring chrome_cmd, jstring chrome_args)
JNIEXPORT jstring JNICALL Java_io_realm_react_RealmReactModule_processChromeDebugCommand(JNIEnv* env, jclass,
jstring chrome_cmd,
jstring chrome_args)
{
const char* cmd = env->GetStringUTFChars(chrome_cmd, NULL);
const char* args = env->GetStringUTFChars(chrome_args, NULL);
Expand All @@ -112,21 +114,18 @@ JNIEXPORT jstring JNICALL Java_io_realm_react_RealmReactModule_processChromeDebu
return env->NewStringUTF(response.c_str());
}

JNIEXPORT jboolean JNICALL Java_io_realm_react_RealmReactModule_tryRunTask
(JNIEnv *env, jclass)
JNIEXPORT jboolean JNICALL Java_io_realm_react_RealmReactModule_tryRunTask(JNIEnv* env, jclass)
{
jboolean result = s_rpc_server->try_run_task();
return result;
jboolean result = s_rpc_server->try_run_task();
return result;
}

JNIEXPORT jboolean JNICALL Java_io_realm_react_RealmReactModule_isContextInjected
(JNIEnv *env, jclass)
JNIEXPORT jboolean JNICALL Java_io_realm_react_RealmReactModule_isContextInjected(JNIEnv* env, jclass)
{
return realmContextInjected;
}

JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_clearContextInjectedFlag
(JNIEnv *env, jclass)
JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_clearContextInjectedFlag(JNIEnv* env, jclass)
{
realmContextInjected = false;
}
6 changes: 2 additions & 4 deletions src/android/jni_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ namespace jni_util {
// Util functions for JNI.
class JniUtils {
public:
~JniUtils()
{
}
~JniUtils() {}

// Call this only once in JNI_OnLoad.
static void initialize(JavaVM* vm, jint vm_version) noexcept;
Expand All @@ -53,7 +51,7 @@ class JniUtils {
jint m_vm_version;
};

} // namespace realm
} // namespace jni_util
} // namespace realm

#endif // REALM_JNI_UTIL_JNI_UTILS_HPP
Loading