1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 18:18:10 +00:00
transmission/libtransmission
2021-12-09 20:54:44 -06:00
..
.clang-tidy build: enable more .clang-tidy checks (#2088) 2021-11-03 08:59:39 -05:00
announcer-common.h refactor: web_utils (#2121) 2021-11-08 21:30:03 -06:00
announcer-http.cc fix: sonarcloud (#2227) 2021-11-25 16:39:19 -06:00
announcer-udp.cc refactor: increase use of tr sha1 digest t (#2091) 2021-11-03 19:55:04 -05:00
announcer.cc fixup! refactor: add tr_torrentTrackers() (#2282) (#2294) 2021-12-09 20:03:26 -06:00
announcer.h fixup! refactor: add tr_torrentTrackers() (#2282) (#2294) 2021-12-09 20:03:26 -06:00
bandwidth.cc fix: unused variable warning when building in release mode 2021-11-28 08:05:44 -06:00
bandwidth.h refactor: make Bandwidth.children a std::vector (#2197) 2021-11-20 10:58:47 -06:00
bitfield.cc test: improve tr_bitfield and tr_block_info coverage (#2226) 2021-11-25 14:30:13 -06:00
bitfield.h refactor: tr_completion (#2220) 2021-11-25 12:26:51 -06:00
block-info.cc test: improve tr_bitfield and tr_block_info coverage (#2226) 2021-11-25 14:30:13 -06:00
block-info.h fix: new warnings (#2270) 2021-12-05 21:12:21 -06: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: tr_completion (#2220) 2021-11-25 12:26:51 -06:00
cache.h
clients.cc refactor: swarm (#2103) 2021-11-19 12:37:38 -06:00
clients.h
CMakeLists.txt refactor: use cpputf for utf8 validation and conversion (#2251) 2021-11-30 15:13:56 -06:00
completion.cc fixup! refactor: tr_completion (#2220) 2021-11-28 22:11:30 -06:00
completion.h refactor: add file-piece-map (#2246) 2021-11-28 19:12:54 -06:00
crypto-utils-ccrypto.cc refactor: swarm (#2103) 2021-11-19 12:37:38 -06:00
crypto-utils-cyassl.cc refactor: use std mutex/lock intead of bespoke (#2194) 2021-11-20 15:20:45 -06:00
crypto-utils-fallback.cc
crypto-utils-openssl.cc refactor: swarm (#2103) 2021-11-19 12:37:38 -06:00
crypto-utils-polarssl.cc refactor: use std mutex/lock intead of bespoke (#2194) 2021-11-20 15:20:45 -06:00
crypto-utils.cc fixup! refactor: rpc-server.cc (#2152) (#2164) 2021-11-14 21:54:48 -06:00
crypto-utils.h fixup! refactor: rpc-server.cc (#2152) (#2164) 2021-11-14 21:54:48 -06:00
crypto.cc refactor: increase use of tr sha1 digest t (#2091) 2021-11-03 19:55:04 -05:00
crypto.h refactor: web_utils (#2121) 2021-11-08 21:30:03 -06:00
error-types.h
error.cc
error.h
fdlimit.cc refactor: use std mutex/lock intead of bespoke (#2194) 2021-11-20 15:20:45 -06:00
fdlimit.h
file-piece-map.cc refactor: add tr_torrentTrackers() (#2282) 2021-12-08 10:55:52 -06:00
file-piece-map.h fix: sonarcloud warnings (#2260) 2021-12-01 17:11:57 -06:00
file-posix.cc refactor: tr_sys_path_dirname(), tr_sys_path_basename() now take std::string_view parameters (#2177) 2021-11-15 18:50:14 -06:00
file-win32.cc Squash consecutive path separators on Windows (#2268) 2021-12-05 16:32:39 +03:00
file.cc
file.h refactor: tr_sys_path_dirname(), tr_sys_path_basename() now take std::string_view parameters (#2177) 2021-11-15 18:50:14 -06:00
handshake.cc fix: sonarcloud (#2227) 2021-11-25 16:39:19 -06:00
handshake.h
history.h
inout.cc refactor: add tr_torrent::file() (#2274) 2021-12-06 22:18:17 -06:00
inout.h
jsonsl.c
jsonsl.h
libt.dox
log.cc refactor: use std mutex/lock intead of bespoke (#2194) 2021-11-20 15:20:45 -06:00
log.h refactor: web_utils (#2121) 2021-11-08 21:30:03 -06:00
magnet-metainfo.cc fix: sonarcloud (#2227) 2021-11-25 16:39:19 -06:00
magnet-metainfo.h fix: some sonarcloud warnings (#2189) 2021-11-17 18:17:09 -06:00
makemeta.cc refactor: use std mutex/lock intead of bespoke (#2194) 2021-11-20 15:20:45 -06:00
makemeta.h
metainfo.cc refactor: remove assigned-but-unused tr_info.originalName (#2276) 2021-12-07 00:37:34 -06:00
metainfo.h refactor: add tr_buildTorrentFilename() (#2196) 2021-11-19 18:36:25 -06:00
mime-types.h
mime-types.js
natpmp.cc
natpmp_local.h
net.cc refactor: tr_address_from_string is now std::string_view-friendly (#2176) 2021-11-15 17:03:55 -06:00
net.h refactor: tr_address_from_string is now std::string_view-friendly (#2176) 2021-11-15 17:03:55 -06:00
peer-common.h refactor: swarm (#2103) 2021-11-19 12:37:38 -06:00
peer-io.cc fix: sonarcloud warnings / code smells (#2242) 2021-11-27 19:58:35 -06:00
peer-io.h refactor: tr_strv*() util functions (#2123) 2021-11-09 18:13:47 -06:00
peer-mgr-active-requests.cc fix: sonarcloud (#2227) 2021-11-25 16:39:19 -06:00
peer-mgr-active-requests.h refactor: swarm (#2103) 2021-11-19 12:37:38 -06:00
peer-mgr-wishlist.cc fix: sonarcloud warnings / code smells (#2242) 2021-11-27 19:58:35 -06:00
peer-mgr-wishlist.h fix: sonarcloud warnings / code smells (#2242) 2021-11-27 19:58:35 -06:00
peer-mgr.cc refactor: add tr_torrentWebseed(), tr_torrentWebseedCount() (#2277) 2021-12-07 12:11:28 -06:00
peer-mgr.h refactor: add tr_torrentWebseed(), tr_torrentWebseedCount() (#2277) 2021-12-07 12:11:28 -06:00
peer-msgs.cc Reject cancels when fast extension enabled (#2275) 2021-12-07 16:18:56 -06:00
peer-msgs.h
peer-socket.h
platform-quota.cc Fix building for XFS (#2192) 2021-11-18 11:07:42 -06:00
platform-quota.h refactor: tr_dirSpace() (#2143) 2021-11-13 12:09:14 -06:00
platform.cc refactor: use std mutex/lock intead of bespoke (#2194) 2021-11-20 15:20:45 -06:00
platform.h refactor: use std mutex/lock intead of bespoke (#2194) 2021-11-20 15:20:45 -06:00
port-forwarding.cc
port-forwarding.h
ptrarray.cc refactor: web_utils (#2121) 2021-11-08 21:30:03 -06:00
ptrarray.h refactor: web_utils (#2121) 2021-11-08 21:30:03 -06:00
quark.cc fix: sonarcloud warnings (#2260) 2021-12-01 17:11:57 -06:00
quark.h feat: add tr_quark_get_string_view() (#2083) 2021-11-01 20:01:27 -05:00
README.md
resume.cc fix: memleak regressions (#2293) 2021-12-09 18:49:30 -06:00
resume.h
rpc-server.cc refactor: make tr_variantFromBuf() public (#2187) 2021-11-17 23:37:35 -06:00
rpc-server.h fix: some sonarcloud warnings (#2189) 2021-11-17 18:17:09 -06:00
rpcimpl.cc refactor: add tr_torrentTrackers() (#2282) 2021-12-08 10:55:52 -06:00
rpcimpl.h refactor: web_utils (#2121) 2021-11-08 21:30:03 -06:00
session-id.cc feat: add tr_strvPath() (#2134) 2021-11-12 18:10:04 -06:00
session-id.h
session.cc refactor: use std mutex/lock intead of bespoke (#2194) 2021-11-20 15:20:45 -06:00
session.h fix: sonarcloud warnings (#2260) 2021-12-01 17:11:57 -06:00
stats.cc refactor: make tr_variantFromBuf() public (#2187) 2021-11-17 23:37:35 -06:00
stats.h
subprocess-posix.cc fix: env var leak in tr_spawn_async() (#2212) 2021-11-24 13:25:23 -06:00
subprocess-win32.cc fix: env var leak in tr_spawn_async() (#2212) 2021-11-24 13:25:23 -06:00
subprocess.h fix: env var leak in tr_spawn_async() (#2212) 2021-11-24 13:25:23 -06:00
torrent-ctor.cc refactor: add tr_saveFile() (#2267) 2021-12-04 19:32:35 -06:00
torrent-magnet.cc refactor: tr_completion (#2220) 2021-11-25 12:26:51 -06:00
torrent-magnet.h
torrent.cc refactor: remove unused tr_torrent.dnd_pieces_ (#2296) 2021-12-09 20:54:44 -06:00
torrent.h refactor: remove unused tr_torrent.dnd_pieces_ (#2296) 2021-12-09 20:54:44 -06:00
tr-assert.cc
tr-assert.h
tr-dht.cc fix: sonarcloud warnings / code smells (#2242) 2021-11-27 19:58:35 -06:00
tr-dht.h
tr-getopt.cc
tr-getopt.h
tr-lpd.cc
tr-lpd.h
tr-macros.h feat: add tr_strvPath() (#2134) 2021-11-12 18:10:04 -06:00
tr-udp.cc refactor: tr_session.congestion (#2151) 2021-11-14 00:41:44 -06:00
tr-udp.h
tr-utp.cc fix: new warnings (#2270) 2021-12-05 21:12:21 -06:00
tr-utp.h
transmission.h refactor: add tr_torrentTrackers() (#2282) 2021-12-08 10:55:52 -06:00
trevent.cc fixup! refactor: use std mutex/lock intead of bespoke (#2194) (#2211) 2021-11-24 10:39:09 -06:00
trevent.h
upnp.cc
upnp.h
utils.cc fix: new warnings (#2270) 2021-12-05 21:12:21 -06:00
utils.h refactor: add tr_saveFile() (#2267) 2021-12-04 19:32:35 -06:00
variant-benc.cc fix: sonarcloud warnings / code smells (#2242) 2021-11-27 19:58:35 -06:00
variant-common.h refactor: make tr_variantFromBuf() public (#2187) 2021-11-17 23:37:35 -06:00
variant-json.cc fix: sonarcloud warnings (#2260) 2021-12-01 17:11:57 -06:00
variant.cc fix: memleak regressions (#2293) 2021-12-09 18:49:30 -06:00
variant.h refactor: make tr_variantFromBuf() public (#2187) 2021-11-17 23:37:35 -06:00
verify.cc refactor: add tr_torrent::file() (#2274) 2021-12-06 22:18:17 -06:00
verify.h
version.h.in
watchdir-common.h
watchdir-generic.cc
watchdir-inotify.cc
watchdir-kqueue.cc
watchdir-win32.cc
watchdir.cc refactor: remove tr_variantDictFindStr() from transmission-daemon (#2165) 2021-11-14 22:49:56 -06:00
watchdir.h refactor: remove tr_variantDictFindStr() from transmission-daemon (#2165) 2021-11-14 22:49:56 -06:00
web-utils.cc refactor: magnet metainfo (#2124) 2021-11-09 20:42:18 -06:00
web-utils.h refactor: magnet metainfo (#2124) 2021-11-09 20:42:18 -06:00
web.cc fix: coverity warnings (#2229) 2021-11-25 18:14:25 -06:00
web.h refactor: tr_web's callback now uses std::string_view (#2172) 2021-11-15 12:10:18 -06:00
webseed.cc fix: memleak regressions (#2293) 2021-12-09 18:49:30 -06:00
webseed.h refactor: add tr_torrentWebseed(), tr_torrentWebseedCount() (#2277) 2021-12-07 12:11:28 -06:00
wildmat.c

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