-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-144330: Initialize staticmethod/classmethod callables in tp_new #144364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
e97e3ec
a81471a
623d522
fc67291
56f8640
ab784f0
270d183
c2dd91b
0eb94d2
250efa2
11281c0
0a02e4f
d8d92b7
02ad4c9
a09aa1e
2e5794e
1f9b093
b9a7530
4ffc8fe
c5fa3a9
65cee10
c6f9612
9c07998
20535dc
a01abdb
79abde1
487ebdf
baa7fd2
cc363d5
de7cedc
c3b31ea
6f4730c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1555,11 +1555,15 @@ static PyMethodDef cm_methodlist[] = { | |
| {NULL} /* Sentinel */ | ||
| }; | ||
|
|
||
| static PyObject *cm_new(PyTypeObject *type, PyObject *args, PyObject *kwds); | ||
| static PyObject *sm_new(PyTypeObject *type, PyObject *args, PyObject *kwds); | ||
|
|
||
| static PyObject* | ||
| cm_repr(PyObject *self) | ||
| { | ||
| classmethod *cm = _PyClassMethod_CAST(self); | ||
| return PyUnicode_FromFormat("<classmethod(%R)>", cm->cm_callable); | ||
| PyObject *callable = cm->cm_callable != NULL ? cm->cm_callable : Py_None; | ||
| return PyUnicode_FromFormat("<classmethod(%R)>", callable); | ||
| } | ||
|
|
||
| PyDoc_STRVAR(classmethod_doc, | ||
|
|
@@ -1623,7 +1627,7 @@ PyTypeObject PyClassMethod_Type = { | |
| offsetof(classmethod, cm_dict), /* tp_dictoffset */ | ||
| cm_init, /* tp_init */ | ||
| PyType_GenericAlloc, /* tp_alloc */ | ||
| PyType_GenericNew, /* tp_new */ | ||
| cm_new, /* tp_new */ | ||
| PyObject_GC_Del, /* tp_free */ | ||
| }; | ||
|
|
||
|
|
@@ -1638,6 +1642,18 @@ PyClassMethod_New(PyObject *callable) | |
| return (PyObject *)cm; | ||
| } | ||
|
|
||
| static PyObject * | ||
| cm_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | ||
| { | ||
| classmethod *cm = (classmethod *)PyType_GenericAlloc(type, 0); | ||
| if (cm == NULL) { | ||
| return NULL; | ||
| } | ||
| cm->cm_callable = Py_None; | ||
| cm->cm_dict = NULL; | ||
| return (PyObject *)cm; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move cm_new() before PyClassMethod_Type, so you don't need to declare it in advance (remove forward declaration line 1558). |
||
|
|
||
|
|
||
| /* Static method object */ | ||
|
|
||
|
|
@@ -1796,7 +1812,8 @@ static PyObject* | |
| sm_repr(PyObject *self) | ||
| { | ||
| staticmethod *sm = _PyStaticMethod_CAST(self); | ||
| return PyUnicode_FromFormat("<staticmethod(%R)>", sm->sm_callable); | ||
| PyObject *callable = sm->sm_callable != NULL ? sm->sm_callable : Py_None; | ||
| return PyUnicode_FromFormat("<staticmethod(%R)>", callable); | ||
| } | ||
|
|
||
| PyDoc_STRVAR(staticmethod_doc, | ||
|
|
@@ -1858,7 +1875,7 @@ PyTypeObject PyStaticMethod_Type = { | |
| offsetof(staticmethod, sm_dict), /* tp_dictoffset */ | ||
| sm_init, /* tp_init */ | ||
| PyType_GenericAlloc, /* tp_alloc */ | ||
| PyType_GenericNew, /* tp_new */ | ||
| sm_new, /* tp_new */ | ||
| PyObject_GC_Del, /* tp_free */ | ||
| }; | ||
|
|
||
|
|
@@ -1872,3 +1889,14 @@ PyStaticMethod_New(PyObject *callable) | |
| } | ||
| return (PyObject *)sm; | ||
| } | ||
|
|
||
| static PyObject * | ||
| sm_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | ||
| { | ||
| staticmethod *sm = (staticmethod *)PyType_GenericAlloc(type, 0); | ||
| if (sm == NULL) | ||
| return NULL; | ||
| sm->sm_callable = Py_NewRef(Py_None); | ||
| sm->sm_dict = NULL; | ||
| return (PyObject *)sm; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move sm_new() before PyStaticMethod_Type. |
||
Uh oh!
There was an error while loading. Please reload this page.