Skip to content
Merged
Show file tree
Hide file tree
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
32 changes: 31 additions & 1 deletion Objects/clinic/exceptions.c.h

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

17 changes: 16 additions & 1 deletion Objects/clinic/frameobject.c.h

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

44 changes: 19 additions & 25 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,46 +161,40 @@ BaseException_traverse(PyObject *op, visitproc visit, void *arg)
return 0;
}

/*[clinic input]
@critical_section
BaseException.__str__
[clinic start generated code]*/

static PyObject *
BaseException_str(PyObject *op)
BaseException_str_impl(PyBaseExceptionObject *self)
/*[clinic end generated code: output=f9cf63c6d14a73fe input=cd946062d6786776]*/
{
PyBaseExceptionObject *self = PyBaseExceptionObject_CAST(op);

PyObject *res;
Py_BEGIN_CRITICAL_SECTION(self);
switch (PyTuple_GET_SIZE(self->args)) {
case 0:
res = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
break;
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
case 1:
res = PyObject_Str(PyTuple_GET_ITEM(self->args, 0));
break;
return PyObject_Str(PyTuple_GET_ITEM(self->args, 0));
default:
res = PyObject_Str(self->args);
break;
return PyObject_Str(self->args);
}
Py_END_CRITICAL_SECTION();
return res;
}

/*[clinic input]
@critical_section
BaseException.__repr__
[clinic start generated code]*/

static PyObject *
BaseException_repr(PyObject *op)
BaseException_repr_impl(PyBaseExceptionObject *self)
/*[clinic end generated code: output=c885549a153a6007 input=20941168ad0ab577]*/
{

PyBaseExceptionObject *self = PyBaseExceptionObject_CAST(op);

PyObject *res;
Py_BEGIN_CRITICAL_SECTION(self);
const char *name = _PyType_Name(Py_TYPE(self));
if (PyTuple_GET_SIZE(self->args) == 1) {
res = PyUnicode_FromFormat("%s(%R)", name,
return PyUnicode_FromFormat("%s(%R)", name,
PyTuple_GET_ITEM(self->args, 0));
}
else {
res = PyUnicode_FromFormat("%s%R", name, self->args);
}
Py_END_CRITICAL_SECTION();
return res;
return PyUnicode_FromFormat("%s%R", name, self->args);
}

/* Pickling support */
Expand Down
21 changes: 11 additions & 10 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2121,19 +2121,20 @@ frame___sizeof___impl(PyFrameObject *self)
return PyLong_FromSsize_t(res);
}

/*[clinic input]
@critical_section
frame.__repr__
[clinic start generated code]*/

static PyObject *
frame_repr(PyObject *op)
frame_repr_impl(PyFrameObject *self)
/*[clinic end generated code: output=6dc361d24ba61076 input=cea0fd14e4749a55]*/
{
PyFrameObject *f = PyFrameObject_CAST(op);
PyObject *result;
Py_BEGIN_CRITICAL_SECTION(f);
int lineno = PyFrame_GetLineNumber(f);
PyCodeObject *code = _PyFrame_GetCode(f->f_frame);
result = PyUnicode_FromFormat(
int lineno = PyFrame_GetLineNumber(self);
PyCodeObject *code = _PyFrame_GetCode(self->f_frame);
return PyUnicode_FromFormat(
"<frame at %p, file %R, line %d, code %S>",
f, code->co_filename, lineno, code->co_name);
Py_END_CRITICAL_SECTION();
return result;
self, code->co_filename, lineno, code->co_name);
}

static PyMethodDef frame_methods[] = {
Expand Down
1 change: 0 additions & 1 deletion Tools/clinic/libclinic/dsl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
__rtruediv__
__rxor__
__setattr__
__str__
__sub__
__truediv__
__xor__
Expand Down
1 change: 1 addition & 0 deletions Tools/clinic/libclinic/slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ def make_return_converter(self) -> CReturnConverter:
'__next__': SlotSpec(return_converter='object'),
'__repr__': SlotSpec(return_converter='object'),
'__setitem__': SlotSpec(return_converter='int'),
'__str__': SlotSpec(return_converter='object'),
}
Loading