-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Updates / cleanup for utility functions #1066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
{ | ||
return getenv("APPDATA"); | ||
// Windows < Vista: C:\Documents and Settings\Username\StartMenu\Programs\Startup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no way of asking windows for the startup folder, in a version-agnostic way? Seems hard to believe one would need guesswork like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If SHGetSpecialFolderPathA() fails we HAVE to guess (our fallback) or GetSpecialFolderPath() fails ... there is NO environment variable that points to the autostart folder and MS changed the folder in Vista and higher in comparison to i.e. WinXP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer simply giving back an error, instead of guessing and fooling around. I suppose if GetSpecialFolderPath fails something is wrong anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback WAS in before I edited the file, but it would have failed for Vista and higher. If you are fine with the rest of the changes I can remove this, sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to change it as you did. But I'd also be fine with removing the fallback and returning error.
There are places where extensive recovery mechanisms for OS errors are warranted, but this isn't one of them (how likely is requesting a string from the OS to fail?). No need to spend much time on this.
I've done some similar cleanups (only path-handling related) in #1072. |
Last commit reverts to old style of array init via = "", which is allowed and shorter than a memset(). At least now all arrays are initialized :). The only exception is in real_strprintf() where the init could perhaps slow down the GUI / client. |
va_list arg_ptr; | ||
va_start(arg_ptr, pszFormat); | ||
int limit = END(pszBuffer) - pend - 2; | ||
int limit = END(staticBuffer) - pend - 2; | ||
int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr); | ||
va_end(arg_ptr); | ||
if (ret < 0 || ret >= limit) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we couldn't reduce all this wonderfully verbose code to about two lines of C++ string manipulation? :-) (or even better, reuse strprintf
? At least by adding an intermediate function vstrprintf
that takes a va_arg list)
Edit: doesn't necessarily need to be in this patch though, just a comment in general
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every simplyfication is a great step, so I agree ... but I don't want to bloat this pull request :). I would like sipas boost pathm rework merged into master before my util updates get in, as he has a better GetDataDir() version.
Thanks, looking good now. |
Rebasing required. |
pszModule[0] = '\0'; | ||
GetModuleFileNameA(NULL, pszModule, sizeof(pszModule)); | ||
char module[MAX_PATH] = ""; | ||
GetModuleFileNameA(NULL, module, sizeof(module)); | ||
#else | ||
const char* pszModule = "bitcoin"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to rename pszModule, you need to do it here too...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, that went through because I used a Refactoring function, which didn't catch this ;). Thank you for watching.
As I said I would like to get in #1072 before, as I will have to rebase against that :). |
I merged #1072. |
Nice, will rebase later today :). |
Rebased and I'm looking through the code again to verify... |
@@ -196,23 +196,24 @@ inline int OutputDebugStringF(const char* pszFormat, ...) | |||
{ | |||
LOCK(cs_OutputDebugStringF); | |||
static char pszBuffer[50000]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is pszBuffer still used now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That must be a merge misstake I overlooked ... removed :), thanks for your hint!
Rebased one more ;-). I'm only going to fix glitches / errors that are currently in my changes, as I don't want to bloat this. There is of course plenty of room for optimizing our utility functions, but that should go to seperate pull requests. |
Most of this looks like it makes the code more unreadable. IMO, the absolute namespaces are far clearer, and should be encouraged, while the general "using namespace" discouraged. sipa's per-function "using namespace foo = boost::longerfoo" makes sense and doesn't interfere with readability. |
God damn ... everytime I try to harmonize the code someone has an own feeling about things. BUT most of the time I see things in the code + in many places and use these as base. I have no problem to completely discard the global use of "using namespace" if everyone would do it. Function local using namespaces seem much more weird to me. But even if you don't like the style ... there are at least valuable fixes in here, like init buffers that were not before, renaming Bitcoin.lnk to Bitcoin-Qt.lnk and the removal of a fallback for a Windows function that sipa suggested. The whole work on filesystem::path was obsolete as Sipa did that (and yes even better then I could). |
I really don't care about namespaces, and only followed the pattern of the code already there when doing the boost::filesystem::path stuff. As long as there are no namespaces in header files, I don't care. |
56 comments for such trivial changes... I think there are higher priority things we could be spending our time on. This is why I don't like "I'll just clean up the code because I can" changes. I would much prefer to see code cleaned up as it is being improved, so:
Diapolo: we have to weigh the benefits of "cleaner" code against the potential costs of ANY changes to the code. It is incredibly easy to screw up and let one tiny little change through that has a really bad unintended consequence. |
May I suggest for code cleanup pull requests, you make a smaller and simpler pull request for each one such as "make sure all char arrays in util.cpp get initialized to 0 and use sizeof(CharArray) instead of MAX_LEN" |
I like bold code cleanups, such as code de-duplication, eliminating unneeded functions, replacing archaic and dangerous C with modern C++, grouping together similar functionality, isolating different concerns, untangling knots of unrelated include files, and so on. Oh yes and: fixing compiler warnings! Those boatloads of warnings are a shame to the project. On the other hand changing namespace references, or renaming local variables, as you see it causes a lot of bikeshedding discussion for no real good. yes, everyone has their own feeling about such things. It's better to harmonize people than harmonize code in this case, and just leave it be... Combining bug fixes with a little related cleanup (as you did with the QR patch) is great though. It's nice to not be the only person that works on the UI. |
Allright, 2 options for me ... leave this as it is or rework to change no var names and only add the small changes I did code-wise. First vore wins, let's go :D. Edit: @laanwj Thanks, I'm more the GUI lover than console user and it's fun to work together :). |
First vote: rework. |
I'm back and will do this in the next days :) and btw. I like clear orders ^^. |
* fix forking logic so that mining generate size is just set once at the moment of the fork, while keeping the enforced minimum on the EB and datacarrier sizes
0cf9bb0 [Cleanup][Refactor][Performance] Main.cpp code cleanup: * Not used GetInputAgeIX method removed. * AcceptToMemoryPool HasZerocoinSpendInputs code duplication. * Several for loops copying the variable cleaned. (furszy) Pull request description: * Not used GetInputAgeIX method removed. * AcceptToMemoryPool HasZerocoinSpendInputs code duplication. * Several for loops copying variable cleaned. ACKs for top commit: random-zebra: ACK 0cf9bb0 Warrows: ACK 0cf9bb0 Tree-SHA512: fc443266b34e3730ad5d9ed2d698ef101cef4d8565b8070a0da6df9139201c4af5b1f6e992b24f3e8a009c8d56df14e1d14b3a620a05fa17d5ac3f08fa12e3d3
4d7dd0c Add release notes for Omni Core 0.7.1 (dexX7) 92cf8e9 Bump version to 0.7.1 and update tests (dexX7) Pull request description: This pull request updates the version of Omni Core 0.7.1 and adds tests for it. It also updates the release notes of this version. Tree-SHA512: d10edb3ee872caca7a3c307955677ef213e2bd92e22c0a3eae3978c0b1b910f24c0e8e2b2ca9931e6de40aa2434db8e3d99380a926887782bd85f44a04e18d79
Removed GetSpecialFolderPath() fallbacks (as requested), removed several unneeded spaces, renamed MyGetSpecialFolderPath() -> GetSpecialFolderPath() as the first one sounds not very pro ^^, make sure all char arrays in util.cpp get initialized to 0 and use sizeof(CharArray) instead of MAX_LEN, renamed Windows Autostart shortcut to "Bitcoin-Qt.lnk".