C++20 port 4/14: compile the event loop, UDP relay and programs as C++ (#3068)

* Make the event loop, UDP relay and programs compile as C++

Cast allocator results and void* callback data explicitly, cast string
literals stored in char * variables, replace compound literals in
ss_event.c with zeroing plus member assignment, and give ss-server's
listener array its MAX_REMOTE_NUM bound instead of a VLA.

Where a goto CLEAN_UP jumps over an initialised declaration (C++
rejects that), split the declaration from its initialisation in place.
The variables were already indeterminate at the label in C, and the
cleanup code does not read them. Checked for every MODULE_* variant of
udprelay.c, plus LIB_ONLY for local.c. Still valid C.

* Compile the event loop, UDP relay and programs as C++

Rename utils, ss_event, udprelay, winsock, local, server, tunnel, redir
and manager from .c to .cpp. Inside the moved files only the
\snippet{doc} file references and header comments change; snippet
references in doc/*.md, tests/test_cli_docs.py, the build files and
CONTRIBUTION.md follow the new names.

Also cast the Windows-only string literal returned by
get_default_conf(), found by the zig x86_64-windows-gnu build.

Every module of src/ except the unbuilt android.c and the vendored
blake3 is now compiled as C++20. The new .cpp files join the no-heap
ratchet baseline.

* Add the two casts ss-redir needs as C++

ss-redir only builds on Linux, so the macOS conversion checks never
compiled it: getsockname() wants a struct sockaddr *, and memcpy's
void * result needs a cast.
This commit is contained in:
Max Lv
2026-10-15 09:53:31 +08:00
committed by GitHub
parent a577ae0927
commit d6691b9e33
23 changed files with 560 additions and 500 deletions
+8
View File
@@ -10,9 +10,17 @@ src/crypto.cpp 4
src/ipset.cpp 3
src/jconf.cpp 16
src/json.cpp 2
src/local.cpp 16
src/manager.cpp 14
src/plugin.cpp 3
src/process.cpp 26
src/redir.cpp 15
src/resolv.cpp 6
src/rule.cpp 2
src/server.cpp 17
src/ss_event.cpp 5
src/ssurl.cpp 3
src/stream.cpp 3
src/tunnel.cpp 14
src/udprelay.cpp 7
src/utils.cpp 10