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 7 commits into
enum class, using rather than typedef, fix throw#311Conversation
|
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. |
|
OK, I went ahead and restored the |
|
I have to ask... Are you an AI or a human delegating all your work to one? Human programmers tend to at least test whether their changes compile before committing them, and ideally test it as well - especially on a PR. Humans do make mistake, I did push code that our CI failed to build a few times, but looking at our CI history, 4 builds on this PR failed and only 2 succeeded. |
|
That doesn't make any sense to me; none of my changes introduce logical changes to the code. I typed every change I made here, and none of the changes I made really need an AI to complete. |
|
So you never downloaded the source code and built it with Visual Studio in order to make sure it at least builds properly? You didn't run the program and make sure the downloader's progress bar was still working properly after the SendMessageW -> SendMessage change? |
|
I made my edits from Linux and currently do not have access to a Windows device let alone Visual Studio, and I did not believe the changes would logically alter the program enough to cause regression, which is why I hadn't tested building. I apologise, but now that the changes do indeed build I do wish to stand by my expectations of no foreseeable regressions. |
enum class, using rather than typedef, fix throw
|
@brliron Hi, is there still anything left on this PR that is objectionable? The CI builds fine, and aside from the |
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).