thcrap_update: Use enum class, using rather than typedef, fix throw#311
thcrap_update: Use enum class, using rather than typedef, fix throw#311mikomikotaishi wants to merge 5 commits into
Conversation
|
Two notes:
|
|
Fine, we can remove the C++ casts. Could you explain in more detail what you mean with |
Just the fact that Few other minor things now that I'm reading over the changes again:
|
I remember thinking about using an enum class here when I initially wrote it, and explicitly deciding to use a regular enum because HttpStatus::Status::Something was too silly and verbose. Here, I think the name "status" to represent the HTTP status code is correct. "response" would correspond to the whole response, with the whole header and also the content. This enum is a simplified representation by removing a level of detail we don't really care about. Anyway, the cast at https://github.com/mikomikotaishi/thcrap/blob/9b69f2045b71654b7da17b35e8ddb75255f54cc9/thcrap_update/src/file.cpp#L112 made me notice that the HttpStatus is part of the C API. Instead of making it more C++ by turning it into an enum class, I think we need to make it less C++ by putting it in the global namespace with all caps values, put the C++ parts of the file into a #ifdef __cplusplus, and include it properly instead of redefining it in thcrap/thcrap_wrapper/src/install_modules.c Line 176 in 1a17df9 |
|
Is there any particular reason for those files to be C instead of C++? This feels like something that should be considered an internal API rather than the external C API |
|
There is one place where another component wants to use it: thcrap/thcrap_wrapper/src/install_modules.c Line 211 in 1a17df9 |
I can revert those, I guess that makes sense.
OK, let me address these.
Do you want me to go through with that on this PR? I feel like this would be more of a follow-up task. |
This PR aims to address the following:
enum) rather thanenum class, which is more consistently used in thcrap_update; we could switch to these for type safety.typedefs overusingaliases in C++, andusingstatements are much cleaner.throw new invalid_argument()was used, which is not only an unnecessary heap allocation but even a source of memory leaks, and actually throws a pointer (which gets missed by mostcatchblocks)constreference is safer as it avoids unnecessary copies and avoids object slicing risks entirely.Where possible,We won't use C++ casts.static_cast<T>(x)is safer than using a C-style cast ((T)x).