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
Use C99 Variable-length array if possible #88215
Comments
I had a chance to read Python/suggestion.c and I can notice that we use the static declared size of the array. Since we live in the C99 era and the CPython codebase already uses C99(struct initialization is a good example), how about using the C99 feature if possible. We should care about stack overflow from the big input but with the expected very small input size it will be okay to use. - static size_t buffer[MAX_STRING_SIZE];
-
// Both strings are the same (by identity)
if (a == b) {
return 0;
@@ -68,6 +66,8 @@ levenshtein_distance(const char *a, size_t a_size,
size_t t_size = a_size; a_size = b_size; b_size = t_size;
} + size_t buffer[a_size];
+
// quick fail when a match is impossible.
if ((b_size - a_size) * MOVE_COST > max_cost) {
return max_cost + 1 |
Thanks for the suggestion! Unfortunately I am not very convinced since we already have the self imposed limitation for the maximum size of the string (this is to limit the execution time and memory) so there is no point of allowing bigger buffers. Also consider that this may happen on threads where the stack is much much smaller, so we cannot allow arbitrary length arrays. Also, on a minor note, we use a restricted set of c99 supported by all compilers so we would need to check if this is supported in all of them. |
Ah, I notice that msvc does not support VLA (Sorry, I am not using Windows machine for 5 years +) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: