transmission/libtransmission
Charles Kerr fa2ef23bdc
refactor: fix uninit var warnings in blocklist.cc (#2087)
2021-11-02 22:55:43 -05:00
..
.clang-tidy refactor: fix uninit var warnings in blocklist.cc (#2087) 2021-11-02 22:55:43 -05:00
CMakeLists.txt Add CommonCrypto-based crypto utils implementation (#2032) 2021-10-24 21:19:57 +03:00
ConvertUTF.c
ConvertUTF.h
README.md
announcer-common.h perf: intern the announcer module's URL strings (#2085) 2021-11-02 18:00:01 -05:00
announcer-http.cc perf: intern the announcer module's URL strings (#2085) 2021-11-02 18:00:01 -05:00
announcer-udp.cc perf: intern the announcer module's URL strings (#2085) 2021-11-02 18:00:01 -05:00
announcer.cc perf: intern the announcer module's URL strings (#2085) 2021-11-02 18:00:01 -05:00
announcer.h perf: intern the announcer module's URL strings (#2085) 2021-11-02 18:00:01 -05:00
bandwidth.cc refactor: cppcoreguidelines-init-variables pt. 11 (#2012) 2021-10-23 10:43:15 -05:00
bandwidth.h
bitfield.cc refactor: cppcoreguidelines-init-variables pt. 13 (#2043) 2021-10-26 13:02:07 -05:00
bitfield.h fix: Bitfield.getRaw() regression (#2023) 2021-10-24 15:43:36 -05:00
blocklist.cc refactor: fix uninit var warnings in blocklist.cc (#2087) 2021-11-02 22:55:43 -05:00
blocklist.h
cache.cc refactor: remove outvar args from tr_torGetFooBlockRange() functions (#2041) 2021-10-24 22:39:19 -05:00
cache.h
clients.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
clients.h fixup! refactor: add tr_peer_id_t (#2004) (#2016) 2021-10-22 15:24:30 -05:00
completion.cc refactor: remove tr_piece struct (#2059) 2021-10-29 13:24:30 -05:00
completion.h fix: Bitfield.getRaw() regression (#2023) 2021-10-24 15:43:36 -05:00
crypto-utils-ccrypto.cc refactor: cppcoreguidelines-init-variables pt. 14 (#2049) 2021-10-26 19:16:56 -05:00
crypto-utils-cyassl.cc refactor: cppcoreguidelines-init-variables pt. 14 (#2049) 2021-10-26 19:16:56 -05:00
crypto-utils-fallback.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
crypto-utils-openssl.cc refactor: cppcoreguidelines-init-variables pt. 14 (#2049) 2021-10-26 19:16:56 -05:00
crypto-utils-polarssl.cc refactor: cppcoreguidelines-init-variables pt. 14 (#2049) 2021-10-26 19:16:56 -05:00
crypto-utils.cc refactor: cppcoreguidelines-init-variables pt. 14 (#2049) 2021-10-26 19:16:56 -05:00
crypto-utils.h
crypto.cc refactor: cppcoreguidelines-init-variables pt. 14 (#2049) 2021-10-26 19:16:56 -05:00
crypto.h
error-types.h Adjust uncrustify config, reformat all but Mac client 2017-04-20 10:01:22 +03:00
error.cc C++ modernization: Replace NULLs with typesafe nullptrs (#1799) 2021-09-14 19:18:09 -05:00
error.h
fdlimit.cc perf: add tr_buildBuf() (#2068) 2021-10-31 11:38:10 -05:00
fdlimit.h perf: add tr_buildBuf() (#2068) 2021-10-31 11:38:10 -05:00
file-posix.cc refactor: cppcoreguidelines-init-variables pt. 15 (#2055) 2021-10-29 17:43:25 -05:00
file-win32.cc Update file-win32.cc (#2066) 2021-10-31 02:15:07 -05:00
file.cc refactor: cppcoreguidelines-init-variables pt. 11 (#2012) 2021-10-23 10:43:15 -05:00
file.h
handshake.cc refactor: add TR_PRIsv and TR_PRIsv_ARG (#2080) 2021-11-01 17:14:17 -05:00
handshake.h refactor: add tr_peer_id_t (#2004) 2021-10-21 21:40:55 -05:00
history.h
inout.cc refactor: remove tr_piece struct (#2059) 2021-10-29 13:24:30 -05:00
inout.h
jsonsl.c
jsonsl.h
libt.dox
log.cc refactor: cppcoreguidelines-init-variables pt. 11 (#2012) 2021-10-23 10:43:15 -05:00
log.h
magnet.cc refactor: cppcoreguidelines-init-variables pt. 6 (#1979) 2021-10-18 07:51:02 -05:00
magnet.h
makemeta.cc refactor: cppcoreguidelines-init-variables pt. 12 (#2022) 2021-10-24 12:40:15 -05:00
makemeta.h Add support for creating torrents with a source flag (#443) 2021-10-18 18:05:39 -05:00
metainfo.cc refactor: tr_urlIsValid*() now takes a std::string_view (#2078) 2021-11-01 15:36:14 -05:00
metainfo.h
mime-types.h
mime-types.js
natpmp.cc refactor: cppcoreguidelines-init-variables pt. 13 (#2043) 2021-10-26 13:02:07 -05:00
natpmp_local.h
net.cc refactor: cppcoreguidelines-init-variables pt. 12 (#2022) 2021-10-24 12:40:15 -05:00
net.h
peer-common.h fix: Bitfield.getRaw() regression (#2023) 2021-10-24 15:43:36 -05:00
peer-io.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
peer-io.h refactor: add tr_peer_id_t (#2004) 2021-10-21 21:40:55 -05:00
peer-mgr.cc feat: add tr_quark_get_string_view() (#2083) 2021-11-01 20:01:27 -05:00
peer-mgr.h
peer-msgs.cc feat: add tr_quark_get_string_view() (#2083) 2021-11-01 20:01:27 -05:00
peer-msgs.h
peer-socket.h
platform-quota.cc refactor: cppcoreguidelines-init-variables pt. 15 (#2055) 2021-10-29 17:43:25 -05:00
platform-quota.h Add total disk space to free-space RPC request (#1682) 2021-10-14 12:07:16 -05:00
platform.cc refactor: cppcoreguidelines-init-variables pt. 11 (#2012) 2021-10-23 10:43:15 -05:00
platform.h
port-forwarding.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
port-forwarding.h
ptrarray.cc refactor: cppcoreguidelines-init-variables pt. 13 (#2043) 2021-10-26 13:02:07 -05:00
ptrarray.h
quark.cc feat: add tr_quark_get_string_view() (#2083) 2021-11-01 20:01:27 -05:00
quark.h feat: add tr_quark_get_string_view() (#2083) 2021-11-01 20:01:27 -05:00
resume.cc fixup! refactor: remove tr_piece struct (#2059) (#2086) 2021-11-02 21:55:33 -05:00
resume.h
rpc-server.cc feat: add tr_quark_get_string_view() (#2083) 2021-11-01 20:01:27 -05:00
rpc-server.h
rpcimpl.cc refactor: tr_torrentFindFromHashString() takes a std::string_view (#2082) 2021-11-01 19:18:09 -05:00
rpcimpl.h refactor: tr_rpc_parse_list_str() takes a std::string_view (#1966) 2021-10-15 18:34:22 -05:00
session-id.cc refactor: cppcoreguidelines-init-variables pt. 11 (#2012) 2021-10-23 10:43:15 -05:00
session-id.h
session.cc perf: add tr_buildBuf() (#2068) 2021-10-31 11:38:10 -05:00
session.h refactor: tr_torrentFindFromHashString() takes a std::string_view (#2082) 2021-11-01 19:18:09 -05:00
stats.cc refactor: cppcoreguidelines-init-variables pt. 11 (#2012) 2021-10-23 10:43:15 -05:00
stats.h
subprocess-posix.cc refactor: cppcoreguidelines-init-variables pt. 15 (#2055) 2021-10-29 17:43:25 -05:00
subprocess-win32.cc
subprocess.h
torrent-ctor.cc refactor: cppcoreguidelines-init-variables pt. 10 (#2006) 2021-10-22 08:51:36 -05:00
torrent-magnet.cc refactor: cppcoreguidelines-init-variables pt. 9 (#1997) 2021-10-21 12:40:36 -05:00
torrent-magnet.h
torrent.cc fixup! refactor: remove tr_piece struct (#2059) (#2086) 2021-11-02 21:55:33 -05:00
torrent.h fixup! refactor: remove tr_piece struct (#2059) (#2086) 2021-11-02 21:55:33 -05:00
tr-assert.cc refactor: clang-tidy --fix modernize-deprecated-headers (#1980) 2021-10-17 15:17:18 -05:00
tr-assert.h Modernize bitfield.cc: Storage changes and refactor (#1927) 2021-10-16 09:04:19 -05:00
tr-dht.cc refactor: cppcoreguidelines-init-variables pt. 14 (#2049) 2021-10-26 19:16:56 -05:00
tr-dht.h
tr-getopt.cc refactor: cppcoreguidelines-init-variables pt. 9 (#1997) 2021-10-21 12:40:36 -05:00
tr-getopt.h
tr-lpd.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
tr-lpd.h
tr-macros.h refactor: add TR_PRIsv and TR_PRIsv_ARG (#2080) 2021-11-01 17:14:17 -05:00
tr-udp.cc fix: apply optional peer socket TOS to UDP sockets (#1043) 2021-10-26 20:59:31 -05:00
tr-udp.h fix: apply optional peer socket TOS to UDP sockets (#1043) 2021-10-26 20:59:31 -05:00
tr-utp.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
tr-utp.h
transmission.h perf: intern the announcer module's URL strings (#2085) 2021-11-02 18:00:01 -05:00
trevent.cc refactor: cppcoreguidelines-init-variables pt. 11 (#2012) 2021-10-23 10:43:15 -05:00
trevent.h
upnp.cc refactor: cppcoreguidelines-init-variables pt. 11 (#2012) 2021-10-23 10:43:15 -05:00
upnp.h
utils.cc perf: intern the announcer module's URL strings (#2085) 2021-11-02 18:00:01 -05:00
utils.h perf: intern the announcer module's URL strings (#2085) 2021-11-02 18:00:01 -05:00
variant-benc.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
variant-common.h
variant-json.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
variant.cc feat: add tr_quark_get_string_view() (#2083) 2021-11-01 20:01:27 -05:00
variant.h feat: new function tr_variantGetStrView() (#2079) 2021-11-01 16:30:18 -05:00
verify.cc refactor: remove tr_piece struct (#2059) 2021-10-29 13:24:30 -05:00
verify.h
version.h.in
watchdir-common.h
watchdir-generic.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
watchdir-inotify.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
watchdir-kqueue.cc Remove C-style STD headers in watchdir-kqueue.cc (#2037) 2021-10-24 17:30:31 -05:00
watchdir-win32.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
watchdir.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
watchdir.h
web.cc refactor: only use [[maybe_unused]] if arg might be used (#2033) 2021-10-24 11:41:54 -05:00
web.h refactor: tr_torrentInfoGetMagnetLink now takes a std::string_view (#1968) 2021-10-16 08:20:04 -05:00
webseed.cc fix: Bitfield.getRaw() regression (#2023) 2021-10-24 15:43:36 -05:00
webseed.h
wildmat.c

README.md

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).