Skip to content

Fix compiler warning in call_readline() #10820

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

Merged
merged 1 commit into from
Nov 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Modules/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ static char *
call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
{
size_t n;
char *p, *q;
char *p;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the declaration of q has been moved?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to move variable declaration closer to where they are used. That's now possible thanks to C99 (required by PEP 7 since Python 3.6). @methane and me are moving all variables one by one :-D But only when we already modify something else in the code.

IMHO the main benefit is to see more easily the scope of a variable. Sometimes, it helps to detect that a subfunction should be created.

int signal;

#ifdef SAVE_LOCALE
Expand Down Expand Up @@ -1297,10 +1297,10 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
}
/* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and
release the original. */
q = p;
char *q = p;
p = PyMem_RawMalloc(n+2);
if (p != NULL) {
strncpy(p, q, n);
memcpy(p, q, n);
p[n] = '\n';
p[n+1] = '\0';
}
Expand Down