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

Reformat source with clang-format #364

Closed
ivmai opened this issue Aug 13, 2021 · 0 comments
Closed

Reformat source with clang-format #364

ivmai opened this issue Aug 13, 2021 · 0 comments

Comments

@ivmai
Copy link
Owner

ivmai commented Aug 13, 2021

It would be good to establish source auto-formatting

  • add clang-format config file with rules which would lead to minimal reformat of existing code base
  • apply clang-format to all c, cc, h files
  • add test on travis-ci to verify further patches are clang-formatted
ivmai added a commit that referenced this issue Sep 24, 2024
Issue #364 (bdwgc).

All comments are now placed either in front of the documented entity
or stay on the same line.

* allchblk.c: Move comments that follow the entity up to precede it;
reformat comments.
* alloc.c: Likewise.
* backgraph.c: Likewise.
* blacklst.c: Likewise.
* checksums.c: Likewise.
* cord/cordbscs.c: Likewise.
* cord/cordprnt.c: Likewise.
* cord/cordxtra.c: Likewise.
* cord/tests/de.c: Likewise.
* cord/tests/de_cmds.h: Likewise.
* cord/tests/de_win.c: Likewise.
* cord/tests/de_win.h: Likewise.
* darwin_stop_world.c: Likewise.
* dbg_mlc.c: Likewise.
* dyn_load.c: Likewise.
* extra/msvc_dbg.c: Likewise.
* extra/real_malloc.c: Likewise.
* extra/symbian.cpp: Likewise.
* finalize.c: Likewise.
* fnlz_mlc.c: Likewise.
* gc_dlopen.c: Likewise.
* gcj_mlc.c: Likewise.
* headers.c: Likewise.
* include/gc/cord_pos.h: Likewise.
* include/gc/gc.h: Likewise.
* include/gc/gc_cpp.h: Likewise.
* include/gc/gc_gcj.h: Likewise.
* include/gc/gc_inline.h: Likewise.
* include/gc/gc_mark.h: Likewise.
* include/gc/gc_typed.h: Likewise.
* include/private/dbg_mlc.h: Likewise.
* include/private/gc_hdrs.h: Likewise.
* include/private/gc_locks.h: Likewise.
* include/private/gc_pmark.h: Likewise.
* include/private/gc_priv.h: Likewise.
* include/private/gcconfig.h: Likewise.
* include/private/pthread_support.h: Likewise.
* include/private/specific.h: Likewise.
* include/private/thread_local_alloc.h: Likewise.
* mach_dep.c: Likewise.
* malloc.c: Likewise.
* mallocx.c: Likewise.
* mark.c: Likewise.
* mark_rts.c: Likewise.
* misc.c: Likewise.
* new_hblk.c: Likewise.
* obj_map.c: Likewise.
* os_dep.c: Likewise.
* pthread_start.c: Likewise.
* pthread_stop_world.c: Likewise.
* pthread_support.c: Likewise.
* ptr_chck.c: Likewise.
* reclaim.c: Likewise.
* specific.c: Likewise.
* tests/cpp.cc: Likewise.
* tests/disclaim.c: Likewise.
* tests/gctest.c: Likewise.
* tests/initfromthread.c: Likewise.
* tests/leak.c: Likewise.
* tests/middle.c: Likewise.
* tests/staticroots.c: Likewise.
* tests/subthreadcreate.c: Likewise.
* tests/threadkey.c: Likewise.
* tests/threadleak.c: Likewise.
* tests/weakmap.c: Likewise.
* thread_local_alloc.c: Likewise.
* tools/if_not_there.c: Likewise.
* typd_mlc.c: Likewise.
* win32_threads.c: Likewise.
* extra/AmigaOS.c: Delete multiple "*" sequences (star-lines) in
comments.
* gc_cpp.cc: Likewise.
* include/gc/gc_cpp.h: Likewise.
* include/private/gc_priv.h: Likewise.
* include/gc/gc_cpp.h: Change "clean-up" to "cleanup" in comments.
* tests/cpp.cc: Likewise.
* include/gc/gc_cpp.h: Convert C-style comments to C++ ones.
* tests/cpp.cc: Likewise.
ivmai added a commit that referenced this issue Oct 2, 2024
Issue #364 (bdwgc).

This is needed to prevent clang-format to change the order of included
header files where the order is important.

* cord/tests/de.c [WIN32]: Move include de_win.h down to be in
a separate include group (from that of windows.h).
* extra/AmigaOS.c: Place a blank line after include gc_priv.h.
* include/private/gc_priv.h [ANY_MSWIN]: Place a blank line between
include windows.h and winbase.h (and add a comment).
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD]: Place a blank line
between include sys/time.h and javaxfc.h; reformat comment.
* tests/gctest.c: Place a blank line between include gc.h and
javaxfc.h.
* tests/weakmap.c [GC_PTHREADS]: Move include errno.h and pthread.h
upper (to be in a separate include group).
ivmai added a commit that referenced this issue Oct 2, 2024
Issue #364 (bdwgc).

Remove comments after e.g. ifdef preprocessor directives whose have
formatted differently by different clang-format versions (e.g. v11
vs v14).

* alloc.c [!USE_MUNMAP] (IF_USE_MUNMAP, COMMA_IF_USE_MUNMAP): Remove
comment.
* dbg_mlc.c [SHORT_DBG_HDRS] (IFNOT_SHORTDBG_HDRS,
COMMA_IFNOT_SHORTDBG_HDRS): Likewise.
* alloc.c (GC_try_to_collect_general): Replace IF_USE_MUNMAP() to
ifdef USE_MUNMAP.
* alloc.c [!SMALL_CONFIG && CPP_WORDSZ>=32] (GC_collect_or_expand):
Insert a blank line after define.
* finalize.c [!GC_MOVE_DISAPPEARING_LINK_NOT_NEEDED]: Remove comment
in endif.
* gc_cpp.cc [GC_OPERATOR_NEW_ARRAY]: Likewise.
* include/gc/cord.h [GC_DLL] (CORD_API): Likewise.
* include/gc/gc_cpp.h: Likewise.
* include/private/gc_locks.h (UNCOND_UNLOCK, EXIT_GC): Likewise.
* include/private/gc_pmark.h [!USE_MARK_BYTES]
(SET_MARK_BIT_EXIT_IF_SET): Likewise.
* include/private/gc_priv.h (ABORT, RT_SIZE, OK_DISCLAIM_INITZ,
GC_inner_pthread_create): Likewise.
* include/private/gcconfig.h [!__cplusplus] (EXTERN_C_BEGIN,
EXTERN_C_END): Likewise.
* mach_dep.c [MACOS] (PushMacRegisters): Likewise.
* mach_dep.c [!HAVE_PUSH_REGS && UNIX_LIKE]: Likewise.
* mach_dep.c [!HAVE_PUSH_REGS] (GC_with_callee_saves_pushed): Likewise.
* mark.c [!USE_MARK_BYTES && !MARK_BIT_PER_OBJ && !SMALL_CONFIG]:
Likewise.
* os_dep.c [!HAVE_GET_STACK_BASE] (GC_get_stack_base): Likewise.
* os_dep.c [USE_WINALLOC || CYGWIN32] (GC_win32_get_mem): Likewise.
* os_dep.c [!NO_MANUAL_VDB || MPROTECT_VDB]: Likewise.
* os_dep.c [!DARWIN] (GC_old_segv_handler_used_si): Likewise.
* os_dep.c [MPROTECT_VDB && !DARWIN](GC_write_fault_handler): Likewise.
* os_dep.c [CAN_HANDLE_FORK && DARWIN && THREADS
|| COUNT_PROTECTED_REGIONS] (GC_unprotect_all_heap): Likewise.
* os_dep.c [MPROTECT_VDB && DARWIN] (catch_exception_raise): Likewise.
* pthread_stop_world.c [DEBUG_THREADS] (NSIG): Likewise.
* pthread_support.c [GC_PTHREADS] (pthread_exit): Likewise.
* pthread_support.c [THREAD_LOCAL_ALLOC] (GC_check_tls_for): Likewise.
* thread_local_alloc.c (GC_check_tls_for): Likewise.
* include/gc/gc_allocator.h (gc_allocator,
gc_allocator_ignore_off_page, traceable_allocator): Insert blank line
before GC_CONSTEXPR.
* include/gc/gc_allocator.h (gc_allocator::gc_allocator,
gc_allocator_ignore_off_page::gc_allocator_ignore_off_page,
traceable_allocator::traceable_allocator): Add comment that the body
is empty.
* include/private/gc_hdrs.h [!COUNT_HDR_CACHE_HITS] (HC_HIT, HC_MISS):
Define as (void)0 instead of a comment.
* os_dep.c [GWW_VDB] (GC_gww_read_dirty): Remove comment inside
"else if".
* pthread_stop_world.c (RETRY_INTERVAL): Place definition (with
a comment) after RESEND_SIGNALS_LIMIT.
* win32_threads.c [!GC_PTHREADS && !MSWINCE]: Remove comment after
include directive.
ivmai added a commit that referenced this issue Oct 2, 2024
(refactoring)

Issue #364 (bdwgc).

* cord/cordxtra.c (refill_cache): Define and use c local variable (to
make the expression shorter).
* dbg_mlc.c (store_debug_info): Define and use lpw_up, lpw_m1 local
variables.
* os_dep.c [SOFT_VDB] (soft_set_grungy_pages): Define and use vlen_p
local variable.
ivmai added a commit that referenced this issue Oct 2, 2024
Issue #364 (bdwgc).

* include/gc/gc.h [WIN64 && !_WIN64 && _MSC_VER] (pragma message):
Shorten the warning message to fit into the line limitation.
ivmai added a commit that referenced this issue Oct 2, 2024
Issue #364 (bdwgc).

* include/gc/gc.h (GC_VDB_NONE, GC_VDB_MANUAL, GC_VDB_DEFAULT,
GC_PROTECTS_POINTER_HEAP, GC_PROTECTS_STATIC_DATA, GC_PROTECTS_STACK,
GC_DUPLICATE, GC_NO_THREADS, GC_UNIMPLEMENTED): Move comment to
precede the entity (instead of being located at the end of line);
refine comment.
* include/private/gc_priv.h [!ANY_MSWIN] (RT_SIZE): Likewise.
* include/private/gcconfig.h [NS32K] (STACKBOTTOM): Likewise.
* include/private/gcconfig.h [(AARCH64 || ARM32) && MSWIN32]: Likewise.
* mach_dep.c [MACOS && __MWERKS__ && !POWERPC] (PushMacRegisters):
Likewise.
* pthread_stop_world.c [LINT2 || THREAD_SANITIZER] (GC_usleep): Likewise.
* include/private/gcconfig.h [MACOS] (DATAEND): Do not define (to
empty) if CPPCHECK.
ivmai added a commit that referenced this issue Oct 2, 2024
(refactoring)

Issue #364 (bdwgc).

* include/private/gc_priv.h (GC_ATTR_NO_SANITIZE_ADDR_MEM_THREAD):
Define macro.
* mark.c (GC_mark_from, GC_push_all_eager): Use
GC_ATTR_NO_SANITIZE_ADDR_MEM_THREAD instead of
GC_ATTR_NO_SANITIZE_ADDR, GC_ATTR_NO_SANITIZE_MEMORY and
GC_ATTR_NO_SANITIZE_THREAD.
* mark.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager):
Likewise.
ivmai added a commit that referenced this issue Oct 2, 2024
(refactoring)

Issue #364 (bdwgc).

Otherwise such else-if construction is formatted differently by
different clang-format versions.

* pthread_support.c [CAN_HANDLE_FORK] (GC_setup_atfork): Always follow
commented out "else" with a block (instead of /* else */ if).
* pthread_support.c [GC_PTHREADS] (GC_register_my_thread): Likewise.
* reclaim.c (GC_reclaim_generic): Likewise.
* pthread_support.c [GC_ASSERTIONS && GC_WIN32_THREADS
&& !USE_PTHREAD_LOCKS] (NUMERIC_THREAD_ID): Add extra parentheses
before 2nd cast.
ivmai added a commit that referenced this issue Oct 2, 2024
(refactoring)

Issue #364 (bdwgc).

This is needed as the direct use of WRAP_[DL]FUNC() macro in a function
declaration confuses clang-format.

* gc_dlopen.c (GC_wrap_dlopen): New macro; undefine it after the
function.
* pthread_support.c (GC_wrap_pthread_sigmask, GC_wrap_pthread_cancel,
GC_wrap_pthread_exit, GC_wrap_pthread_join, GC_wrap_pthread_detach,
GC_wrap_pthread_create): Likewise.
* gc_dlopen.c (WRAP_DLFUNC(dlopen)): Change name to the relevant
GC_wrap_*.
* pthread_support.c (WRAP_FUNC(pthread_sigmask),
WRAP_FUNC(pthread_cancel), WRAP_FUNC(pthread_exit),
WRAP_FUNC(pthread_join), WRAP_FUNC(pthread_detach),
WRAP_FUNC(pthread_create)): Likewise.
ivmai added a commit that referenced this issue Oct 2, 2024
(refactoring)

Issue #364 (bdwgc).

* os_dep.c [OS2] (GC_register_data_segments): Move definition down (to
be near OPENBSD case).
* os_dep.c [!GWW_VDB] (GetWriteWatch_alloc_flag): Do not define unless
ANY_MSWIN is defined.
ivmai added a commit that referenced this issue Oct 2, 2024
Issue #364 (bdwgc).

clang-format v14 is applied to all .c, .cc, .cpp and .h files.
A configuration file for clang-format is added.

* .clang-format: New file.
* README.md (Contribution): Add note that clang-format should be used.
* allchblk.c: Reformat with clang-format.
* alloc.c: Likewise.
* backgraph.c: Likewise.
* blacklst.c: Likewise.
* checksums.c: Likewise.
* cord/cordbscs.c: Likewise.
* cord/cordprnt.c: Likewise.
* cord/cordxtra.c: Likewise.
* cord/tests/cordtest.c: Likewise.
* cord/tests/de.c: Likewise.
* cord/tests/de_cmds.h: Likewise.
* cord/tests/de_win.c: Likewise.
* cord/tests/de_win.h: Likewise.
* darwin_stop_world.c: Likewise.
* dbg_mlc.c: Likewise.
* dyn_load.c: Likewise.
* extra/gc.c: Likewise.
* extra/msvc_dbg.c: Likewise.
* extra/symbian.cpp: Likewise.
* extra/symbian/init_global_static_roots.cpp: Likewise.
* finalize.c: Likewise.
* fnlz_mlc.c: Likewise.
* gc_badalc.cc: Likewise.
* gc_cpp.cc: Likewise.
* gc_dlopen.c: Likewise.
* gcj_mlc.c: Likewise.
* headers.c: Likewise.
* include/gc/cord.h: Likewise.
* include/gc/cord_pos.h: Likewise.
* include/gc/ec.h: Likewise.
* include/gc/gc.h: Likewise.
* include/gc/gc_allocator.h: Likewise.
* include/gc/gc_backptr.h: Likewise.
* include/gc/gc_config_macros.h: Likewise.
* include/gc/gc_cpp.h: Likewise.
* include/gc/gc_disclaim.h: Likewise.
* include/gc/gc_gcj.h: Likewise.
* include/gc/gc_inline.h: Likewise.
* include/gc/gc_mark.h: Likewise.
* include/gc/gc_pthread_redirects.h: Likewise.
* include/gc/gc_tiny_fl.h: Likewise.
* include/gc/gc_typed.h: Likewise.
* include/gc/gc_version.h: Likewise.
* include/gc/javaxfc.h: Likewise.
* include/gc/leak_detector.h: Likewise.
* include/private/darwin_semaphore.h: Likewise.
* include/private/dbg_mlc.h: Likewise.
* include/private/gc_alloc_ptrs.h: Likewise.
* include/private/gc_atomic_ops.h: Likewise.
* include/private/gc_hdrs.h: Likewise.
* include/private/gc_locks.h: Likewise.
* include/private/gc_pmark.h
* include/private/gc_priv.h: Likewise.
* include/private/gcconfig.h: Likewise.
* include/private/pthread_support.h: Likewise.
* include/private/specific.h: Likewise.
* include/private/thread_local_alloc.h: Likewise.
* mach_dep.c: Likewise.
* malloc.c: Likewise.
* mallocx.c: Likewise.
* mark.c: Likewise.
* mark_rts.c: Likewise.
* misc.c: Likewise.
* new_hblk.c: Likewise.
* obj_map.c: Likewise.
* os_dep.c: Likewise.
* pthread_start.c: Likewise.
* pthread_stop_world.c: Likewise.
* pthread_support.c: Likewise.
* ptr_chck.c: Likewise.
* reclaim.c: Likewise.
* specific.c: Likewise.
* tests/atomicops.c: Likewise.
* tests/cpp.cc: Likewise.
* tests/disclaim.c: Likewise.
* tests/disclaim_bench.c: Likewise.
* tests/gctest.c: Likewise.
* tests/huge.c: Likewise.
* tests/initfromthread.c: Likewise.
* tests/leak.c: Likewise.
* tests/middle.c: Likewise.
* tests/realloc.c: Likewise.
* tests/smash.c: Likewise.
* tests/staticroots.c: Likewise.
* tests/staticroots_lib.c: Likewise.
* tests/subthreadcreate.c: Likewise.
* tests/threadkey.c: Likewise.
* tests/threadleak.c: Likewise.
* tests/trace.c: Likewise.
* tests/weakmap.c: Likewise.
* thread_local_alloc.c: Likewise.
* tools/if_mach.c: Likewise.
* tools/if_not_there.c: Likewise.
* tools/setjmp_t.c: Likewise.
* tools/threadlibs.c: Likewise.
* typd_mlc.c: Likewise.
* win32_threads.c: Likewise.
@ivmai ivmai closed this as completed Oct 2, 2024
ivmai added a commit that referenced this issue Oct 3, 2024
(fix of commit 2936975)

Issue #364 (bdwgc).

* pthread_support.c [!GC_PTHREADS] (GC_register_my_thread): Move "{"
out of ifdef GC_PTHREADS.
ivmai added a commit that referenced this issue Oct 3, 2024
Issue #364 (bdwgc).

This is to match the clang-format version existing on GH Actions
server, as of now.

* tests/cpp.cc (A::A, B::B, C::C, D::D): Do not place new-line before
the constructor initializers part; place empty or short block on the
same line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant