yuzu/src/core/hle/service
Lioncash 6ac955a0b4 hle/service: Default constructors and destructors in the cpp file where applicable
When a destructor isn't defaulted into a cpp file, it can cause the use
of forward declarations to seemingly fail to compile for non-obvious
reasons. It also allows inlining of the construction/destruction logic
all over the place where a constructor or destructor is invoked, which
can lead to code bloat. This isn't so much a worry here, given the
services won't be created and destroyed frequently.

The cause of the above mentioned non-obvious errors can be demonstrated
as follows:

------- Demonstrative example, if you know how the described error happens, skip forwards -------

Assume we have the following in the header, which we'll call "thing.h":

\#include <memory>

// Forward declaration. For example purposes, assume the definition
// of Object is in some header named "object.h"
class Object;

class Thing {
public:
    // assume no constructors or destructors are specified here,
    // or the constructors/destructors are defined as:
    //
    // Thing() = default;
    // ~Thing() = default;
    //

    // ... Some interface member functions would be defined here

private:
    std::shared_ptr<Object> obj;
};

If this header is included in a cpp file, (which we'll call "main.cpp"),
this will result in a compilation error, because even though no
destructor is specified, the destructor will still need to be generated by
the compiler because std::shared_ptr's destructor is *not* trivial (in
other words, it does something other than nothing), as std::shared_ptr's
destructor needs to do two things:

1. Decrement the shared reference count of the object being pointed to,
   and if the reference count decrements to zero,

2. Free the Object instance's memory (aka deallocate the memory it's
   pointing to).

And so the compiler generates the code for the destructor doing this inside main.cpp.

Now, keep in mind, the Object forward declaration is not a complete type. All it
does is tell the compiler "a type named Object exists" and allows us to
use the name in certain situations to avoid a header dependency. So the
compiler needs to generate destruction code for Object, but the compiler
doesn't know *how* to destruct it. A forward declaration doesn't tell
the compiler anything about Object's constructor or destructor. So, the
compiler will issue an error in this case because it's undefined
behavior to try and deallocate (or construct) an incomplete type and
std::shared_ptr and std::unique_ptr make sure this isn't the case
internally.

Now, if we had defaulted the destructor in "thing.cpp", where we also
include "object.h", this would never be an issue, as the destructor
would only have its code generated in one place, and it would be in a
place where the full class definition of Object would be visible to the
compiler.

---------------------- End example ----------------------------

Given these service classes are more than certainly going to change in
the future, this defaults the constructors and destructors into the
relevant cpp files to make the construction and destruction of all of
the services consistent and unlikely to run into cases where forward
declarations are indirectly causing compilation errors. It also has the
plus of avoiding the need to rebuild several services if destruction
logic changes, since it would only be necessary to recompile the single
cpp file.
2018-09-10 23:55:31 -04:00
..
acc hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
am hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
aoc hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
apm hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
arp service: Add arp services 2018-08-04 18:01:12 -04:00
audio hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
bcat hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
bpc service: Add bpc and pcv services 2018-08-01 16:13:04 -04:00
btdrv service: Add the btdrv service 2018-07-26 18:06:17 -04:00
btm service/btm: Add basic implementation of GetCoreImpl() 2018-07-28 21:09:07 -04:00
caps service: Add capture services 2018-08-01 16:45:51 -04:00
erpt service: Add the erpt services 2018-07-25 22:13:39 -04:00
es service: Add the es service 2018-07-25 15:36:55 -04:00
eupld service: Add eupld services 2018-07-25 22:13:43 -04:00
fatal hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
fgm service: Add fgm services 2018-07-31 08:01:19 -04:00
filesystem hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
friend hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
grc service: Add the grc:c service 2018-07-26 09:53:58 -04:00
hid hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
lbl service/lbl: Implement EnableVrMode, DisableVrMode and GetVrMode 2018-07-27 14:20:42 -04:00
ldn service: Add ldn services 2018-07-26 01:48:06 -04:00
ldr service: Add ldr services 2018-07-25 23:11:03 -04:00
lm lm: Use LOG_DEBUG for printing out trace logs 2018-08-15 01:07:41 -04:00
mig service: Add migration services 2018-08-02 10:09:45 -04:00
mii service: Add mii services 2018-07-27 16:01:29 -04:00
mm mm_u: Forward all old variants of functions to the new ones 2018-08-13 18:59:10 -04:00
ncm service: Add ncm services 2018-07-27 17:38:30 -04:00
nfc service/nfc: Implement Create[x]Interface functions 2018-07-27 15:12:08 -04:00
nfp hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
nifm kernel: Eliminate kernel global state 2018-08-28 22:31:51 -04:00
nim service: Add the nim services 2018-07-26 02:47:06 -04:00
ns hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
nvdrv hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
nvflinger hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
pcie service: Add the pcie service 2018-07-31 06:40:21 -04:00
pctl hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
pcv service: Add bpc and pcv services 2018-08-01 16:13:04 -04:00
pm Added GetBootMode (#1107) 2018-08-23 18:31:45 -04:00
prepo service/prepo: Add missing header guard 2018-07-18 19:43:28 -04:00
psc service: Add psc services 2018-08-01 23:31:27 -04:00
set hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
sm core/core: Remove unnecessary sm/controller include 2018-09-06 14:38:39 -04:00
sockets hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
spl hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
ssl ssl: Move SSL class to cpp file 2018-09-02 11:45:26 -04:00
time hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
usb service: Add usb services 2018-08-07 03:14:03 -04:00
vi hle/service: Default constructors and destructors in the cpp file where applicable 2018-09-10 23:55:31 -04:00
wlan service: Add wlan services 2018-07-28 21:54:55 -04:00
service.cpp service: Remove unused g_kernel_named_ports variable 2018-09-09 22:10:54 -04:00
service.h service: Migrate global named port map to the KernelCore class 2018-09-02 12:35:30 -04:00