1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00
transmission/libtransmission
2021-10-14 09:22:28 -05:00
..
.clang-tidy build: add clang-tidy check modernize-pass-by-value (#1946) 2021-10-13 19:14:27 -05:00
announcer-common.h refactor: use nullptr instead of NULL (#1884) 2021-10-06 11:32:17 -05:00
announcer-http.cc fix: uninitialized variables in announcer (#1936) 2021-10-14 09:22:28 -05:00
announcer-udp.cc fix: uninitialized variables in announcer (#1936) 2021-10-14 09:22:28 -05:00
announcer.cc fix: uninitialized variables in announcer (#1936) 2021-10-14 09:22:28 -05:00
announcer.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
bandwidth.cc refactor: run clang-tidy on bandwidth.h, .cc (#1930) 2021-10-12 01:04:22 -05:00
bandwidth.h refactor: run clang-tidy on bandwidth.h, .cc (#1930) 2021-10-12 01:04:22 -05:00
bitfield.cc Modernize/bitfield.cc: Make into C++ (#1917) 2021-10-11 12:29:14 -05:00
bitfield.h Modernize/bitfield.cc: Make into C++ (#1917) 2021-10-11 12:29:14 -05:00
blocklist.cc C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
blocklist.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
cache.cc C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
cache.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
clients.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
clients.h refactor: remove TR_BEGIN_DECLS, TR_END_DECLS (#1837) 2021-09-25 11:07:22 -05:00
CMakeLists.txt refactor: use C++ inheritance for tr_peer, tr_peerMsgs, and tr_webseed (#1877) 2021-10-07 08:33:55 -05:00
completion.cc Modernize/bitfield.cc: Make into C++ (#1917) 2021-10-11 12:29:14 -05:00
completion.h Modernize/bitfield.cc: Make into C++ (#1917) 2021-10-11 12:29:14 -05:00
ConvertUTF.c refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
ConvertUTF.h
crypto-utils-cyassl.cc fix runtime with wolfSSL and fastmath (#1950) 2021-10-13 22:48:04 -05:00
crypto-utils-fallback.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
crypto-utils-openssl.cc refactor: prefer constexpr functions over static inline ones (#1887) 2021-10-06 17:24:04 -05:00
crypto-utils-polarssl.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
crypto-utils.cc C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
crypto-utils.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
crypto.cc C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
crypto.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
error-types.h
error.cc C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
error.h refactor: use nullptr instead of NULL (#1884) 2021-10-06 11:32:17 -05:00
fdlimit.cc refactor: prefer constexpr functions over static inline ones (#1887) 2021-10-06 17:24:04 -05:00
fdlimit.h Switch to clang-format for code formatting, include Mac client 2021-08-16 00:38:29 +03:00
file-posix.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
file-win32.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
file.cc C++ modernize: Replace MIN/MAX with type safe std::min/std::max (#1806) 2021-09-19 15:41:35 -05:00
file.h refactor: use nullptr instead of NULL (#1884) 2021-10-06 11:32:17 -05:00
handshake.cc refactor: make tr_peerIo a class (#1928) 2021-10-11 16:54:16 -05:00
handshake.h refactor: make tr_peerIo a class (#1928) 2021-10-11 16:54:16 -05:00
history.h refactor: use C++ inheritance for tr_peer, tr_peerMsgs, and tr_webseed (#1877) 2021-10-07 08:33:55 -05:00
inout.cc C++ modernize: Replace MIN/MAX with type safe std::min/std::max (#1806) 2021-09-19 15:41:35 -05:00
inout.h Switch to clang-format for code formatting, include Mac client 2021-08-16 00:38:29 +03:00
jsonsl.c
jsonsl.h C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
libt.dox
log.cc C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
log.h refactor: use nullptr instead of NULL (#1884) 2021-10-06 11:32:17 -05:00
magnet.cc refactor: prefer constexpr functions over static inline ones (#1887) 2021-10-06 17:24:04 -05:00
magnet.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
makemeta.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
makemeta.h refactor: use nullptr instead of NULL (#1884) 2021-10-06 11:32:17 -05:00
metainfo.cc refactor: prefer constexpr functions over static inline ones (#1887) 2021-10-06 17:24:04 -05:00
metainfo.h refactor: remove TR_BEGIN_DECLS, TR_END_DECLS (#1837) 2021-09-25 11:07:22 -05:00
mime-types.h refactor: make mime-type array inline constexpr (#1872) 2021-10-01 17:55:19 -05:00
mime-types.js refactor: make mime-type array inline constexpr (#1872) 2021-10-01 17:55:19 -05:00
natpmp.cc refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
natpmp_local.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
net.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
net.h refactor: prefer constexpr functions over static inline ones (#1887) 2021-10-06 17:24:04 -05:00
peer-common.h Modernize/bitfield.cc: Make into C++ (#1917) 2021-10-11 12:29:14 -05:00
peer-io.cc refactor: run clang-tidy on bandwidth.h, .cc (#1930) 2021-10-12 01:04:22 -05:00
peer-io.h refactor: run clang-tidy on bandwidth.h, .cc (#1930) 2021-10-12 01:04:22 -05:00
peer-mgr.cc fix: uninitialized variables pt 1: peer-mgr.cc (#1932) 2021-10-13 10:08:37 -05:00
peer-mgr.h refactor: make tr_peerIo a class (#1928) 2021-10-11 16:54:16 -05:00
peer-msgs.cc build: add clang-tidy check modernize-pass-by-value (#1946) 2021-10-13 19:14:27 -05:00
peer-msgs.h refactor: make tr_peerIo a class (#1928) 2021-10-11 16:54:16 -05:00
peer-socket.h refactor: remove TR_BEGIN_DECLS, TR_END_DECLS (#1837) 2021-09-25 11:07:22 -05:00
platform-quota.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
platform-quota.h
platform.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
platform.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
port-forwarding.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
port-forwarding.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
ptrarray.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
ptrarray.h refactor: prefer constexpr functions over static inline ones (#1887) 2021-10-06 17:24:04 -05:00
quark.cc feat: add rpc-version-semver to RPC's session-get (#1935) 2021-10-12 22:03:28 -05:00
quark.h feat: add rpc-version-semver to RPC's session-get (#1935) 2021-10-12 22:03:28 -05:00
README.md Suggested modernization steps for each *.CC module (#1801) 2021-10-07 12:18:44 -05:00
resume.cc Modernize/bitfield.cc: Make into C++ (#1917) 2021-10-11 12:29:14 -05:00
resume.h refactor: remove TR_BEGIN_DECLS, TR_END_DECLS (#1837) 2021-09-25 11:07:22 -05:00
rpc-server.cc Replace NULL back with nullptr (mistake after auto-rebase) (#1933) 2021-10-12 14:45:18 -05:00
rpc-server.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
rpcimpl.cc refactor: add an enumeration of the script types (#1934) 2021-10-12 22:46:12 -05:00
rpcimpl.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
session-id.cc C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
session-id.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
session.cc build: have clang-tidy check for NULL in libtransmission (#1945) 2021-10-13 18:12:51 -05:00
session.h refactor: add an enumeration of the script types (#1934) 2021-10-12 22:46:12 -05:00
stats.cc C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
stats.h refactor: port libtransmission to C++ (#1787) 2021-09-12 12:41:49 -05:00
subprocess-posix.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
subprocess-win32.cc C++ modernize: Replace MIN/MAX with type safe std::min/std::max (#1806) 2021-09-19 15:41:35 -05:00
subprocess.h refactor: remove TR_BEGIN_DECLS, TR_END_DECLS (#1837) 2021-09-25 11:07:22 -05:00
torrent-ctor.cc C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
torrent-magnet.cc C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
torrent-magnet.h fix: 'enumerated and non-enumerated type' warnings (#1810) 2021-09-16 11:22:33 -05:00
torrent.cc refactor: add an enumeration of the script types (#1934) 2021-10-12 22:46:12 -05:00
torrent.h Bandwidth.cc bring naming closer to C++ style of code in qt/ (#1914) 2021-10-09 20:12:03 -05:00
tr-assert.cc refactor: port libtransmission to C++ (#1787) 2021-09-12 12:41:49 -05:00
tr-assert.h
tr-dht.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
tr-dht.h
tr-getopt.cc fix: sonarcloud getopt warnings (#1871) 2021-10-01 12:47:23 -05:00
tr-getopt.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
tr-lpd.cc build: have clang-tidy check for NULL in libtransmission (#1945) 2021-10-13 18:12:51 -05:00
tr-lpd.h chore: fix compiler warnings (#1412) 2020-08-27 18:41:26 -05:00
tr-macros.h refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
tr-udp.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
tr-udp.h
tr-utp.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
tr-utp.h
transmission.h refactor: add an enumeration of the script types (#1934) 2021-10-12 22:46:12 -05:00
trevent.cc refactor: add [[fallthrough]] annotation (#1886) 2021-10-06 12:24:02 -05:00
trevent.h refactor: remove TR_BEGIN_DECLS, TR_END_DECLS (#1837) 2021-09-25 11:07:22 -05:00
upnp.cc refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
upnp.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
utils.cc refactor: use nullptr instead of NULL (#1884) 2021-10-06 11:32:17 -05:00
utils.h refactor: prefer constexpr functions over static inline ones (#1887) 2021-10-06 17:24:04 -05:00
variant-benc.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
variant-common.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
variant-json.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
variant.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
variant.h refactor: prefer constexpr functions over static inline ones (#1887) 2021-10-06 17:24:04 -05:00
verify.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
verify.h
version.h.in
watchdir-common.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
watchdir-generic.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
watchdir-inotify.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
watchdir-kqueue.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
watchdir-win32.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
watchdir.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
watchdir.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
web.cc refactor: use maybe unused attribute (#1918) 2021-10-10 11:52:26 -05:00
web.h refactor: prefer "using" over "typedef" (#1883) 2021-10-06 09:26:07 -05:00
webseed.cc refactor: run clang-tidy on bandwidth.h, .cc (#1930) 2021-10-12 01:04:22 -05:00
webseed.h refactor: use C++ inheritance for tr_peer, tr_peerMsgs, and tr_webseed (#1877) 2021-10-07 08:33:55 -05:00
wildmat.c refactor: tr_parseNumberRange returns std::vector. (#1838) 2021-09-25 14:37:28 -05:00

Notes on the C-to-C++ Conversion

  • libtransmission was written in C for fifteen years, so eliminating all Cisms is nearly impossible. Modernization patches are welcomed but it won't all happen overnight. tr_strdup() and constexpr wil exist side-by-side in the codebase for the forseeable future.

  • It's so tempting to refactor all the things! Please keep modernization patches reasonably focused so that they will be easy to review.

  • Prefer std:: tools over bespoke ones. For example, use std::vector instead of tr_ptrArray. Redundant bespoke code should be removed.

  • Consider ripple effects before adding C++ into public headers. Will it break C code that #includes that header? If you think it might, consult with downstream projects to see if this is a problem for them.

Checklist for modernization of a module

NOTE:
The version in libtransmission/CMakeLists.txt is C++17.
See https://github.com/AnthonyCalandra/modern-cpp-features

This can be done in multiple smaller passes:

  1. Satisfy clang-tidy. libtransmission/.clang-tidy's list of rules should eventually be expanded to a list similar to the one in qt/.clang-tidy.
  2. Group member functions and their parent structs
    • Use namespace libtransmission
    • Split large modules into smaller groups of files in a libtransmission/<name> subdirectories, with own sub-namespace.
  3. Enums replaced with new enum class syntax. Numeric #define constants replaced with C++ const/constexpr.
  4. Memory - promote init and free functions to C++ ctors and dtors, and ensure it is only managed with new/delete
  5. Owned memory - promote simple pointer fields owning their data to smart pointers (unique_ptr, shared_ptr, vector, string)

Detailed Steps

  1. Satisfy clang-tidy warnings

    • Change C includes to C++ wraps, example: <string.h> becomes and update calls to standard library to use std:: namespace prefix. This clearly delineates the border between std library and transmission. Headers must be sorted alphabetically.
    • Headers which are used conditionally based on some #ifdef in the code, should also have same #ifdef in the include section.
    • Revisit type warnings, int vs unsigned int. Sizes and counts should use size_t type where this does not break external API declarations. Ideally change that too.
  2. Move and group code together.

    • Move member functions into structs. To minimize code churn, create function forward declarations inside structs, and give struct_name:: prefixes to the functions.
      typedef struct {
          int field;
      } foo;
      int foo_blep(struct foo *f) {
          return f->field;
      }
      
      becomes:
      struct foo {
          int field;
          void blep(); 
      };
      int foo::blep() {
          return this->field; 
      }
      
    • For functions taking const pointer, add const after the function prototype: int blep() const like so.
    • For structs used by other modules, struct definitions should relocate to internal *-common.h header files.
    • Split large files into sub-modules sharing own separate sub-namespace and sitting in a subdirectory under libtransmission/.
    • Some externally invoked functions must either not move OR have extern "C" adapter functions.
  3. Enums promoted to enum class and given a type:

    enum { A, B, C };
    

    becomes

    enum: int { A, B, C };        // unscoped, use A, B, C
    enum MyEnum: int { A, B, C }; // unscoped, use A, B, C
    // OR wrap into a scope -
    enum struct MyEnum: int { A, B, C }; // scoped, use MyEnum::A
    enum class MyEnum: int { A, B, C };  // scoped, use MyEnum::A
    

    this will make all values of enum to have that numeric type.

  4. Numeric/bool #define constants should be replaced with C++ const/constexpr.

  5. Memory management:

    • Prefer constructors and destructors vs manual construction and destruction. But when doing so must ensure that the struct is never constructed using C malloc/free, but must use C++ new/delete.
    • Avoid using std::memset on a new struct. It is allowed in C, and C++ struct but will destroy virtual table on a C++ class. Use field initializers in C++.
  6. Owned memory:

    • If destructor deletes something, it means it was owned. Promote that field to owning type (vector, unique_ptr, shared_ptr or string).