Skip to content

Commit 575b810

Browse files
committed
Modernize FORMAT_VALUE
1 parent 43beb67 commit 575b810

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

Python/bytecodes.c

+2-14
Original file line numberDiff line numberDiff line change
@@ -3052,18 +3052,10 @@ dummy_func(
30523052
ERROR_IF(slice == NULL, error);
30533053
}
30543054

3055-
// error: FORMAT_VALUE has irregular stack effect
3056-
inst(FORMAT_VALUE) {
3055+
inst(FORMAT_VALUE, (value, fmt_spec if ((oparg & FVS_MASK) == FVS_HAVE_SPEC) -- result)) {
30573056
/* Handles f-string value formatting. */
3058-
PyObject *result;
3059-
PyObject *fmt_spec;
3060-
PyObject *value;
30613057
PyObject *(*conv_fn)(PyObject *);
30623058
int which_conversion = oparg & FVC_MASK;
3063-
int have_fmt_spec = (oparg & FVS_MASK) == FVS_HAVE_SPEC;
3064-
3065-
fmt_spec = have_fmt_spec ? POP() : NULL;
3066-
value = POP();
30673059

30683060
/* See if any conversion is specified. */
30693061
switch (which_conversion) {
@@ -3104,12 +3096,8 @@ dummy_func(
31043096
result = PyObject_Format(value, fmt_spec);
31053097
Py_DECREF(value);
31063098
Py_XDECREF(fmt_spec);
3107-
if (result == NULL) {
3108-
goto error;
3109-
}
3099+
ERROR_IF(result == NULL, error);
31103100
}
3111-
3112-
PUSH(result);
31133101
}
31143102

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

Python/generated_cases.c.h

+6-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_metadata.h

+2-2
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)