Skip to content

Commit 98e5d83

Browse files
committed
Fix various stuff in the VM
1 parent fa4b531 commit 98e5d83

File tree

10 files changed

+59
-52
lines changed

10 files changed

+59
-52
lines changed

Include/internal/pycore_interpolation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern "C" {
1313

1414
extern PyTypeObject _PyInterpolation_Type;
1515

16-
PyAPI_FUNC(PyObject *) _PyInterpolation_FromStackRefSteal(_PyStackRef *values);
16+
PyAPI_FUNC(PyObject *) _PyInterpolation_FromStackRefStealOnSuccess(_PyStackRef *values);
1717

1818
extern PyStatus _PyInterpolation_InitTypes(PyInterpreterState *interp);
1919
extern PyObject *_PyInterpolation_GetValue(PyObject *interpolation);

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_template.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern PyTypeObject _PyTemplateIter_Type;
1717
extern PyObject *_PyTemplate_Concat(PyObject *self, PyObject *other);
1818

1919
PyAPI_FUNC(PyObject *) _PyTemplate_FromValues(PyObject **values, Py_ssize_t n);
20-
PyAPI_FUNC(PyObject *) _PyTemplate_FromListStackRef(_PyStackRef ref);
20+
PyAPI_FUNC(PyObject *) _PyTemplate_FromList(PyObject *list);
2121

2222
#ifdef __cplusplus
2323
}

Include/internal/pycore_uop_metadata.h

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

Objects/interpolationobject.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -225,37 +225,29 @@ _PyInterpolation_InitTypes(PyInterpreterState *interp)
225225
}
226226

227227
PyObject *
228-
_PyInterpolation_FromStackRefSteal(_PyStackRef *values)
228+
_PyInterpolation_FromStackRefStealOnSuccess(_PyStackRef *values)
229229
{
230-
PyObject *args = PyTuple_New(4);
231-
if (!args) {
232-
PyStackRef_CLOSE(values[0]);
233-
PyStackRef_CLOSE(values[1]);
234-
PyStackRef_XCLOSE(values[2]);
235-
PyStackRef_XCLOSE(values[3]);
230+
interpolationobject *interpolation = (interpolationobject *) _PyInterpolation_Type.tp_alloc(&_PyInterpolation_Type, 0);
231+
if (!interpolation) {
236232
return NULL;
237233
}
238234

239-
PyTuple_SET_ITEM(args, 0, PyStackRef_AsPyObjectSteal(values[0]));
240-
PyTuple_SET_ITEM(args, 1, PyStackRef_AsPyObjectSteal(values[1]));
235+
interpolation->value = PyStackRef_AsPyObjectSteal(values[0]);
236+
interpolation->expression = PyStackRef_AsPyObjectSteal(values[1]);
241237

242238
if (PyStackRef_IsNull(values[2])) {
243-
PyTuple_SET_ITEM(args, 2, Py_NewRef(Py_None));
239+
interpolation->conversion = Py_NewRef(Py_None);
244240
} else {
245-
PyObject *conversion = PyStackRef_AsPyObjectSteal(values[2]);
246-
PyTuple_SET_ITEM(args, 2, conversion);
241+
interpolation->conversion = PyStackRef_AsPyObjectSteal(values[2]);
247242
}
248243

249244
if (PyStackRef_IsNull(values[3])) {
250-
PyTuple_SET_ITEM(args, 3, &_Py_STR(empty));
245+
interpolation->format_spec = Py_NewRef(&_Py_STR(empty));
251246
} else {
252-
PyObject *format_spec = PyStackRef_AsPyObjectSteal(values[3]);
253-
PyTuple_SET_ITEM(args, 3, format_spec);
247+
interpolation->format_spec = PyStackRef_AsPyObjectSteal(values[3]);
254248
}
255249

256-
PyObject *interpolation = PyObject_CallObject((PyObject *) &_PyInterpolation_Type, args);
257-
Py_DECREF(args);
258-
return interpolation;
250+
return (PyObject *) interpolation;
259251
}
260252

261253
PyObject *

Objects/templateobject.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,23 +484,20 @@ _PyTemplate_FromValues(PyObject **values, Py_ssize_t oparg)
484484
PyTuple_SET_ITEM(tuple, i, Py_NewRef(values[i]));
485485
}
486486

487-
PyObject *template = PyObject_CallObject((PyObject *) &_PyTemplate_Type, tuple);
487+
PyObject *template = (PyObject *) template_new(&_PyTemplate_Type, tuple, NULL);
488488
Py_DECREF(tuple);
489489
return template;
490490
}
491491

492492
PyObject *
493-
_PyTemplate_FromListStackRef(_PyStackRef ref)
493+
_PyTemplate_FromList(PyObject *list)
494494
{
495-
PyObject *list = PyStackRef_AsPyObjectSteal(ref);
496-
497-
PyObject *tuple = PySequence_Tuple(list);
495+
PyObject *tuple = PyList_AsTuple(list);
498496
if (!tuple) {
499-
PyStackRef_CLOSE(ref);
500497
return NULL;
501498
}
502499

503-
PyObject *template = PyObject_CallObject((PyObject *) &_PyTemplate_Type, tuple);
500+
PyObject *template = (PyObject *) template_new(&_PyTemplate_Type, tuple, NULL);
504501
Py_DECREF(tuple);
505502
return template;
506503
}

Python/bytecodes.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,9 +1872,11 @@ dummy_func(
18721872
}
18731873

18741874
inst(BUILD_INTERPOLATION, (values[4] -- interpolation)) {
1875-
PyObject *interpolation_o = _PyInterpolation_FromStackRefSteal(values);
1875+
PyObject *interpolation_o = _PyInterpolation_FromStackRefStealOnSuccess(values);
1876+
if (interpolation_o == NULL) {
1877+
ERROR_NO_POP();
1878+
}
18761879
INPUTS_DEAD();
1877-
ERROR_IF(interpolation_o == NULL, error);
18781880
interpolation = PyStackRef_FromPyObjectSteal(interpolation_o);
18791881
}
18801882

@@ -1892,8 +1894,9 @@ dummy_func(
18921894
}
18931895

18941896
inst(BUILD_TEMPLATE_LIST, (list -- template)) {
1895-
PyObject *template_o = _PyTemplate_FromListStackRef(list);
1896-
INPUTS_DEAD();
1897+
PyObject *list_o = PyStackRef_AsPyObjectBorrow(list);
1898+
PyObject *template_o = _PyTemplate_FromList(list_o);
1899+
PyStackRef_CLOSE(list);
18971900
ERROR_IF(template_o == NULL, error);
18981901
template = PyStackRef_FromPyObjectSteal(template_o);
18991902
}

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

Tools/cases_generator/analyzer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ def has_error_without_pop(op: parser.CodeDef) -> bool:
630630
"_PyFrame_StackPush",
631631
"_PyFunction_SetVersion",
632632
"_PyGen_GetGeneratorFromFrame",
633-
"_PyInterpolation_FromStackRefSteal",
633+
"_PyInterpolation_FromStackRefStealOnSuccess",
634634
"_PyInterpreterState_GET",
635635
"_PyList_AppendTakeRef",
636636
"_PyList_ITEMS",
@@ -649,8 +649,7 @@ def has_error_without_pop(op: parser.CodeDef) -> bool:
649649
"_PyObject_InlineValues",
650650
"_PyObject_IsUniquelyReferenced",
651651
"_PyObject_ManagedDictPointer",
652-
"_PyTemplate_FromValues",
653-
"_PyTemplate_FromListStackRef",
652+
"_PyTemplate_FromList",
654653
"_PyThreadState_HasStackSpace",
655654
"_PyTuple_FromStackRefStealOnSuccess",
656655
"_PyTuple_ITEMS",

0 commit comments

Comments
 (0)