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

core: Add coding style enforcement and update selected code areas #8595

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
121 changes: 121 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# copied from: https://github.com/torvalds/linux/blob/master/.clang-format
#
# SPDX-License-Identifier: GPL-2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we include with GPL-2.0 license?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - we need dual license or one usable with BSD., such as MIT.

#
# clang-format configuration file. Intended for clang-format >= 11.
#
# For more information, see:
#
# Documentation/process/clang-format.rst
# https://clang.llvm.org/docs/ClangFormat.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
#
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false

IncludeBlocks: Preserve
IncludeCategories:
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: 8
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 8
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true

# Taken from git's rules
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 60

PointerAlignment: Right
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp03
TabWidth: 8
UseTab: Always
...
17 changes: 17 additions & 0 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: clang-format Check
on: [push, pull_request]
jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
strategy:
matrix:
path:
- 'include'
steps:
- uses: actions/checkout@v3
- name: Run clang-format style check for C/C++/Protobuf programs.
uses: jidicula/clang-format-action@v4.10.2
with:
clang-format-version: '14'
check-path: ${{ matrix.path }}
4 changes: 2 additions & 2 deletions include/fasthash.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ extern "C" {
* @len: data size
* @seed: the seed
*/
uint32_t fasthash32(const void *buf, size_t len, uint32_t seed);
uint32_t fasthash32(const void *buf, size_t len, uint32_t seed);

/**
* fasthash64 - 64-bit implementation of fasthash
* @buf: data buffer
* @len: data size
* @seed: the seed
*/
uint64_t fasthash64(const void *buf, size_t len, uint64_t seed);
uint64_t fasthash64(const void *buf, size_t len, uint64_t seed);

#ifdef __cplusplus
}
Expand Down
95 changes: 47 additions & 48 deletions include/freebsd/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@
#define bswap_64 bswap64

#define ENODATA ENOMSG
#define HOST_NAME_MAX 128
#define HOST_NAME_MAX 128
#define SOL_TCP IPPROTO_TCP

typedef cpuset_t cpu_set_t;

static inline int ofi_shm_remap(struct util_shm *shm, size_t newsize, void **mapped)
static inline int ofi_shm_remap(struct util_shm *shm, size_t newsize,
void **mapped)
{
return -1;
}
Expand All @@ -71,22 +72,18 @@ static inline size_t ofi_ifaddr_get_speed(struct ifaddrs *ifa)
return 0;
}

static inline ssize_t ofi_process_vm_readv(pid_t pid,
const struct iovec *local_iov,
unsigned long liovcnt,
const struct iovec *remote_iov,
unsigned long riovcnt,
unsigned long flags)
static inline ssize_t
ofi_process_vm_readv(pid_t pid, const struct iovec *local_iov,
unsigned long liovcnt, const struct iovec *remote_iov,
unsigned long riovcnt, unsigned long flags)
{
return -FI_ENOSYS;
}

static inline size_t ofi_process_vm_writev(pid_t pid,
const struct iovec *local_iov,
unsigned long liovcnt,
const struct iovec *remote_iov,
unsigned long riovcnt,
unsigned long flags)
static inline size_t
ofi_process_vm_writev(pid_t pid, const struct iovec *local_iov,
unsigned long liovcnt, const struct iovec *remote_iov,
unsigned long riovcnt, unsigned long flags)
{
return -FI_ENOSYS;
}
Expand All @@ -107,8 +104,9 @@ static inline ssize_t ofi_recv_socket(SOCKET fd, void *buf, size_t count,
return recv(fd, buf, count, flags);
}

static inline ssize_t ofi_recvfrom_socket(SOCKET fd, void *buf, size_t count, int flags,
struct sockaddr *from, socklen_t *fromlen)
static inline ssize_t ofi_recvfrom_socket(SOCKET fd, void *buf, size_t count,
int flags, struct sockaddr *from,
socklen_t *fromlen)
{
return recvfrom(fd, buf, count, flags, from, fromlen);
}
Expand All @@ -119,66 +117,67 @@ static inline ssize_t ofi_send_socket(SOCKET fd, const void *buf, size_t count,
return send(fd, buf, count, flags);
}

static inline ssize_t ofi_sendto_socket(SOCKET fd, const void *buf, size_t count, int flags,
const struct sockaddr *to, socklen_t tolen)
static inline ssize_t ofi_sendto_socket(SOCKET fd, const void *buf,
size_t count, int flags,
const struct sockaddr *to,
socklen_t tolen)
{
return sendto(fd, buf, count, flags, to, tolen);
}

static inline ssize_t ofi_writev_socket(SOCKET fd, struct iovec *iov, size_t iov_cnt)
static inline ssize_t ofi_writev_socket(SOCKET fd, struct iovec *iov,
size_t iov_cnt)
{
return writev(fd, iov, iov_cnt);
}

static inline ssize_t ofi_readv_socket(SOCKET fd, struct iovec *iov, int iov_cnt)
static inline ssize_t ofi_readv_socket(SOCKET fd, struct iovec *iov,
int iov_cnt)
{
return readv(fd, iov, iov_cnt);
}

static inline ssize_t
ofi_sendmsg_tcp(SOCKET fd, const struct msghdr *msg, int flags)
static inline ssize_t ofi_sendmsg_tcp(SOCKET fd, const struct msghdr *msg,
int flags)
{
return sendmsg(fd, msg, flags);
}

static inline ssize_t
ofi_recvmsg_tcp(SOCKET fd, struct msghdr *msg, int flags)
static inline ssize_t ofi_recvmsg_tcp(SOCKET fd, struct msghdr *msg, int flags)
{
return recvmsg(fd, msg, flags);
}

static inline ssize_t
ofi_sendv_socket(SOCKET fd, const struct iovec *iov, size_t cnt, int flags)
static inline ssize_t ofi_sendv_socket(SOCKET fd, const struct iovec *iov,
size_t cnt, int flags)
{
struct msghdr msg;
struct msghdr msg;

msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = (struct iovec *) iov;
msg.msg_iovlen = cnt;
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = (struct iovec *)iov;
msg.msg_iovlen = cnt;

return ofi_sendmsg_tcp(fd, &msg, flags);
return ofi_sendmsg_tcp(fd, &msg, flags);
}

static inline ssize_t
ofi_recvv_socket(SOCKET fd, const struct iovec *iov, size_t cnt, int flags)
static inline ssize_t ofi_recvv_socket(SOCKET fd, const struct iovec *iov,
size_t cnt, int flags)
{
struct msghdr msg;
struct msghdr msg;

msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = (struct iovec *) iov;
msg.msg_iovlen = cnt;
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = (struct iovec *)iov;
msg.msg_iovlen = cnt;

return ofi_recvmsg_tcp(fd, &msg, flags);
return ofi_recvmsg_tcp(fd, &msg, flags);
}

#endif /* _FREEBSD_OSD_H_ */