8000 Issue #15422: get rid of PyCFunction_New macro · python/cpython@3ba3a3e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ba3a3e

Browse files
committed
Issue #15422: get rid of PyCFunction_New macro
1 parent 914ab84 commit 3ba3a3e

File tree

9 files changed

+20
-23
lines changed

9 files changed

+20
-23
lines changed

Include/methodobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct PyMethodDef {
4646
};
4747
typedef struct PyMethodDef PyMethodDef;
4848

49-
#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
49+
PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);
5050
PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
5151
PyObject *);
5252

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #15422: Get rid of PyCFunction_New macro. Use PyCFunction_NewEx
14+
function (PyCFunction_New func is still present for backward compatibility).
15+
1316
- Issue #16672: Improve performance tracing performance
1417

1518
- Issue #14470: Remove w9xpopen support per PEP 11.

Modules/_threadmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
741741
wr = PyWeakref_NewRef((PyObject *) self, NULL);
742742
if (wr == NULL)
743743
goto err;
744-
self->wr_callback = PyCFunction_New(&wr_callback_def, wr);
744+
self->wr_callback = PyCFunction_NewEx(&wr_callback_def, wr, NULL);
745745
Py_DECREF(wr);
746746
if (self->wr_callback == NULL)
747747
goto err;

Objects/descrobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
115115
((PyTypeObject *)type)->tp_name);
116116
return NULL;
117117
}
118-
return PyCFunction_New(descr->d_method, type);
118+
return PyCFunction_NewEx(descr->d_method, type, NULL);
119119
}
120120

121121
static PyObject *
@@ -125,7 +125,7 @@ method_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
125125

126126
if (descr_check((PyDescrObject *)descr, obj, &res))
127127
return res;
128-
return PyCFunction_New(descr->d_method, obj);
128+
return PyCFunction_NewEx(descr->d_method, obj, NULL);
129129
}
130130

131131
static PyObject *
@@ -239,7 +239,7 @@ methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds)
239239
return NULL;
240240
}
241241

242-
func = PyCFunction_New(descr->d_method, self);
242+
func = PyCFunction_NewEx(descr->d_method, self, NULL);
243243
if (func == NULL)
244244
return NULL;
245245
args = PyTuple_GetSlice(args, 1, argc);
@@ -292,7 +292,7 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
292292
return NULL;
293293
}
294294

295-
func = PyCFunction_New(descr->d_method, self);
295+
func = PyCFunction_NewEx(descr->d_method, self, NULL);
296296
if (func == NULL)
297297
return NULL;
298298
args = PyTuple_GetSlice(args, 1, argc);

Objects/methodobject.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ static int numfree = 0;
1313
#define PyCFunction_MAXFREELIST 256
1414
#endif
1515

16+
PyObject *
17+
PyCFunction_New(PyMethodDef *ml, PyObject *self)
18+
{
19+
return PyCFunction_NewEx(ml, self, NULL);
20+
}
21+
1622
PyObject *
1723
PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
1824
{
@@ -346,17 +352,3 @@ _PyCFunction_DebugMallocStats(FILE *out)
346352
"free PyCFunction",
347353
numfree, sizeof(PyCFunction));
348354
}
349-
350-
/* PyCFunction_New() is now just a macro that calls PyCFunction_NewEx(),
351-
but it's part of the API so we need to keep a function around that
352-
existing C extensions can call.
353-
*/
354-
355-
#undef PyCFunction_New
356-
PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);
357-
358-
PyObject *
359-
PyCFunction_New(PyMethodDef *ml, PyObject *self)
360-
{
361-
return PyCFunction_NewEx(ml, self, NULL);
362-
}

Objects/typeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3811,7 +3811,7 @@ add_methods(PyTypeObject *type, PyMethodDef *meth)
38113811
descr = PyDescr_NewClassMethod(type, meth);
38123812
}
38133813
else if (meth->ml_flags & METH_STATIC) {
3814-
PyObject *cfunc = PyCFunction_New(meth, (PyObject*)type);
3814+
PyObject *cfunc = PyCFunction_NewEx(meth, (PyObject*)type, NULL);
38153815
if (cfunc == NULL)
38163816
return -1;
38173817
descr = PyStaticMethod_New(cfunc);
@@ -4879,7 +4879,7 @@ add_tp_new_wrapper(PyTypeObject *type)
48794879

48804880
if (_PyDict_GetItemId(type->tp_dict, &PyId___new__) != NULL)
48814881
return 0;
4882-
func = PyCFunction_New(tp_new_methoddef, (PyObject *)type);
4882+
func = PyCFunction_NewEx(tp_new_methoddef, (PyObject *)type, NULL);
48834883
if (func == NULL)
48844884
return -1;
48854885
if (_PyDict_SetItemId(type->tp_dict, &PyId___new__, func)) {

PC/python3.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ EXPORTS
3838
PyCFunction_GetFlags=python34.PyCFunction_GetFlags
3939
PyCFunction_GetFunction=python34.PyCFunction_GetFunction
4040
PyCFunction_GetSelf=python34.PyCFunction_GetSelf
41+
PyCFunction_New=python34.PyCFunction_New
4142
PyCFunction_NewEx=python34.PyCFunction_NewEx
4243
PyCFunction_Type=python34.PyCFunction_Type DATA
4344
PyCallIter_New=python34.PyCallIter_New

PC/python34stub.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ PyCFunction_ClearFreeList
3737
PyCFunction_GetFlags
3838
PyCFunction_GetFunction
3939
PyCFunction_GetSelf
40+
PyCFunction_New
4041
PyCFunction_NewEx
4142
PyCFunction_Type
4243
PyCallIter_New

Python/codecs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ static int _PyCodecRegistry_Init(void)
10261026

10271027
if (interp->codec_error_registry) {
10281028
for (i = 0; i < Py_ARRAY_LENGTH(methods); ++i) {
1029-
PyObject *func = PyCFunction_New(&methods[i].def, NULL);
1029+
PyObject *func = PyCFunction_NewEx(&methods[i].def, NULL, NULL);
10301030
int res;
10311031
if (!func)
10321032
Py_FatalError("can't initialize codec error registry");

0 commit comments

Comments
 (0)
0