-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-128394: Parse int for lltrace #128395
gh-128394: Parse int for lltrace #128395
Conversation
WolframAlph
commented
Jan 1, 2025
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: Parse int for lltrace #128394
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.
Thanks for doing this. atoi()
is quite broken and we definitely shouldn't use it here (for example, inputting something outside the number range is UB). You probably want something like PyOS_strtol
instead.
|
You can probably just fatal error if it fails. |
@ZeroIntensity since static inline int get_lltrace(const char* env_var) {
int lltrace = 0;
char* value = Py_GETENV(env_var);
if (value != NULL) {
long result = PyOS_strtol(value, NULL, 10);
if (errno == ERANGE || result < 0 || result > INT_MAX) {
char buff[100];
PyOS_snprintf(buff, sizeof(buff), "Ivalid value for: %s", env_var);
Py_FatalError(buff);
}
lltrace = (int)result;
}
return lltrace;
} WDYT? The only question is where to put it |
Sure, that works. Anywhere in the file is fine (prefereably near the lltrace code). |
I'm of the opinion that the added complexity to parse it isn't worth it. IIRC that comment was added by Guido, but I've never found a use for actually parsing an int? We never use any levels above 5 anyways. So it would only matter if we were to use two digit numerals (10 and onwards), which I don't see us using anytime soon. I'd rather we just remove the comment. If we need to parse ints in the future, we can just do it then rather than preparing for something which might never happen. |
@Fidget-Spinner what about defining this logic somewhere else? #128395 (comment). This piece of logic is used across multiple files and copied over every time someone needs it. Might be handy and cleaner IMO |
That would be nice. Thanks. |
I'm sorry, this does not deserve to be fixed. For an explanation see the issue. |