Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address some review comments
  • Loading branch information
markshannon committed May 4, 2024
commit 857d152acc589038f46ab727e217d35ddb9579f6
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Lib/test/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def f():
class C:
def m(self):
pass
callables = [ f, C.m, [].__len__ ]
callables = [f, C.m, [].__len__]
for c in callables:
for _ in range(1000):
try:
Expand Down
8 changes: 4 additions & 4 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3213,8 +3213,8 @@ dummy_func(
_PUSH_FRAME;

op(_CHECK_IS_NOT_PY_CALLABLE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) {
DEOPT_IF(PyFunction_Check(callable));
DEOPT_IF(Py_TYPE(callable) == &PyMethod_Type);
EXIT_IF(PyFunction_Check(callable));
EXIT_IF(Py_TYPE(callable) == &PyMethod_Type);
}
Comment on lines +3215 to +3220
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe these are better as exits so we can handle more cases? If we trace through this, it'd be a shame if we couldn't then stitch a function or method into the call site if its polymorphic.

Suggested change
op(_CHECK_IS_NOT_PY_CALLABLE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) {
DEOPT_IF(PyFunction_Check(callable));
DEOPT_IF(Py_TYPE(callable) == &PyMethod_Type);
}
op(_CHECK_IS_NOT_PY_CALLABLE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) {
EXIT_IF(PyFunction_Check(callable));
EXIT_IF(Py_TYPE(callable) == &PyMethod_Type);
}


op(_CALL_NON_PY_GENERAL, (callable, self_or_null, args[oparg] -- res)) {
Expand Down Expand Up @@ -3247,8 +3247,8 @@ dummy_func(
_CHECK_PERIODIC;

op(_CHECK_CALL_BOUND_METHOD_EXACT_ARGS, (callable, null, unused[oparg] -- callable, null, unused[oparg])) {
DEOPT_IF(null != NULL);
DEOPT_IF(Py_TYPE(callable) != &PyMethod_Type);
EXIT_IF(null != NULL);
EXIT_IF(Py_TYPE(callable) != &PyMethod_Type);
}

op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable, unused, unused[oparg] -- func, self, unused[oparg])) {
Expand Down
18 changes: 15 additions & 3 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static void
dump_stack(_PyInterpreterFrame *frame, PyObject **stack_pointer)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are the changes in this function intentional, or left over from debugging?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Left over from debugging, I needed them as dump_stack was too slow for a realistic number (many millions) of instructions for finding bugs.

It might be worth making this change, but that's for another PR.

{
PyObject **stack_base = _PyFrame_Stackbase(frame);
// PyObject *exc = PyErr_GetRaisedException();
PyObject *exc = PyErr_GetRaisedException();
printf(" stack=[");
for (PyObject **ptr = stack_base; ptr < stack_pointer; ptr++) {
if (ptr != stack_base) {
Expand All @@ -117,12 +117,24 @@ dump_stack(_PyInterpreterFrame *frame, PyObject **stack_pointer)
printf("<nil>");
continue;
}
if (
*ptr == Py_None
|| PyBool_Check(*ptr)
|| PyLong_CheckExact(*ptr)
|| PyFloat_CheckExact(*ptr)
|| PyUnicode_CheckExact(*ptr)
) {
if (PyObject_Print(*ptr, stdout, 0) == 0) {
continue;
}
PyErr_Clear();
}
// Don't call __repr__(), it might recurse into the interpreter.
printf("<%s at %p>", Py_TYPE(*ptr)->tp_name, (void *)(*ptr));
}
printf("]\n");
// fflush(stdout);
// PyErr_SetRaisedException(exc);
fflush(stdout);
PyErr_SetRaisedException(exc);
}

static void
Expand Down