1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-22 15:54:57 +00:00
transmission/libtransmission
2022-01-20 12:27:56 -06:00
..
.clang-tidy build: enable more .clang-tidy checks (#2088) 2021-11-03 08:59:39 -05:00
announce-list.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
announce-list.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
announcer-common.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
announcer-http.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
announcer-udp.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
announcer.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
announcer.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
bandwidth.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
bandwidth.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
bitfield.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
bitfield.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
block-info.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
block-info.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
blocklist.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
blocklist.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
cache.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
cache.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
clients.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
clients.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
CMakeLists.txt refactor: use libdeflate instead of zlib's deflate() (#2405) 2022-01-17 10:20:12 -06:00
completion.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
completion.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
crypto-utils-ccrypto.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
crypto-utils-cyassl.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
crypto-utils-fallback.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
crypto-utils-openssl.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
crypto-utils-polarssl.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
crypto-utils.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
crypto-utils.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
crypto.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
crypto.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
error-types.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
error.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
error.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
fdlimit.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
fdlimit.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
file-piece-map.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
file-piece-map.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
file-posix.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
file-win32.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
file.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
file.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
foo refactor: add tr_interned_string (#2332) 2021-12-23 11:16:05 -06:00
handshake.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
handshake.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
history.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
inout.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
inout.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
interned-string.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
jsonsl.c chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
jsonsl.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
libt.dox
log.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
log.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
magnet-metainfo.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
magnet-metainfo.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
makemeta.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
makemeta.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
mime-types.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
mime-types.js chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
natpmp.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
natpmp_local.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
net.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
net.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-common.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-io.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-io.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-mgr-active-requests.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-mgr-active-requests.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-mgr-wishlist.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-mgr-wishlist.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-mgr.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-mgr.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-msgs.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-msgs.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
peer-socket.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
platform-quota.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
platform-quota.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
platform.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
platform.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
port-forwarding.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
port-forwarding.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
ptrarray.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
ptrarray.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
quark.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
quark.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
README.md Suggested modernization steps for each *.CC module (#1801) 2021-10-07 12:18:44 -05:00
resume.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
resume.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
rpc-server.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
rpc-server.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
rpcimpl.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
rpcimpl.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
session-id.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
session-id.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
session.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
session.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
stats.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
stats.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
subprocess-posix.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
subprocess-win32.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
subprocess.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
torrent-ctor.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
torrent-magnet.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
torrent-magnet.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
torrent-metainfo.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
torrent-metainfo.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
torrent.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
torrent.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-assert.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-assert.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-dht.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-dht.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-getopt.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-getopt.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-lpd.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-lpd.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-macros.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-udp.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-udp.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-utp.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
tr-utp.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
transmission.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
trevent.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
trevent.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
upnp.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
upnp.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
utils.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
utils.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
variant-benc.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
variant-common.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
variant-json.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
variant.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
variant.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
verify.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
verify.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
version.h.in Adjust CFBundleVersion format to fix Sparkle update check 2018-04-17 13:25:49 +03:00
watchdir-common.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
watchdir-generic.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
watchdir-inotify.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
watchdir-kqueue.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
watchdir-win32.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
watchdir.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
watchdir.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
web-utils.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
web-utils.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
web.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
web.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
webseed.cc chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
webseed.h chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06: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).