Skip to content

Commit df5d78c

Browse files
committed
Modernize FORMAT_VALUE
1 parent 22f8a0e commit df5d78c

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

Python/bytecodes.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,18 +3038,10 @@ dummy_func(
30383038
ERROR_IF(slice == NULL, error);
30393039
}
30403040

3041-
// error: FORMAT_VALUE has irregular stack effect
3042-
inst(FORMAT_VALUE) {
3041+
inst(FORMAT_VALUE, (value, fmt_spec if ((oparg & FVS_MASK) == FVS_HAVE_SPEC) -- result)) {
30433042
/* Handles f-string value formatting. */
3044-
PyObject *result;
3045-
PyObject *fmt_spec;
3046-
PyObject *value;
30473043
PyObject *(*conv_fn)(PyObject *);
30483044
int which_conversion = oparg & FVC_MASK;
3049-
int have_fmt_spec = (oparg & FVS_MASK) == FVS_HAVE_SPEC;
3050-
3051-
fmt_spec = have_fmt_spec ? POP() : NULL;
3052-
value = POP();
30533045

30543046
/* See if any conversion is specified. */
30553047
switch (which_conversion) {
@@ -3090,12 +3082,8 @@ dummy_func(
30903082
result = PyObject_Format(value, fmt_spec);
30913083
Py_DECREF(value);
30923084
Py_XDECREF(fmt_spec);
3093-
if (result == NULL) {
3094-
goto error;
3095-
}
3085+
ERROR_IF(result == NULL, error);
30963086
}
3097-
3098-
PUSH(result);
30993087
}
31003088

31013089
inst(COPY, (bottom, unused[oparg-1] -- bottom, unused[oparg-1], top)) {

Python/generated_cases.c.h

Lines changed: 6 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
331331
case BUILD_SLICE:
332332
return ((oparg == 3) ? 1 : 0) + 2;
333333
case FORMAT_VALUE:
334-
return -1;
334+
return (((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0) + 1;
335335
case COPY:
336336
return (oparg-1) + 1;
337337
case BINARY_OP:
@@ -677,7 +677,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
677677
case BUILD_SLICE:
678678
return 1;
679679
case FORMAT_VALUE:
680-
return -1;
680+
return 1;
681681
case COPY:
682682
return (oparg-1) + 2;
683683
case BINARY_OP:

0 commit comments

Comments
 (0)