[Python-checkins] cpython: Issue #15422: get rid of PyCFunction_New macro

andrew.svetlov python-checkins at python.org
Tue Dec 25 12:32:46 CET 2012


http://hg.python.org/cpython/rev/3a86a3f1d89a
changeset:   81031:3a86a3f1d89a
user:        Andrew Svetlov <andrew.svetlov at gmail.com>
date:        Tue Dec 25 13:32:35 2012 +0200
summary:
  Issue #15422: get rid of PyCFunction_New macro

files:
  Include/methodobject.h  |   2 +-
  Misc/NEWS               |   3 +++
  Modules/_threadmodule.c |   2 +-
  Objects/descrobject.c   |   8 ++++----
  Objects/methodobject.c  |  20 ++++++--------------
  Objects/typeobject.c    |   4 ++--
  PC/python3.def          |   1 +
  PC/python34stub.def     |   1 +
  Python/codecs.c         |   2 +-
  9 files changed, 20 insertions(+), 23 deletions(-)


diff --git a/Include/methodobject.h b/Include/methodobject.h
--- a/Include/methodobject.h
+++ b/Include/methodobject.h
@@ -46,7 +46,7 @@
 };
 typedef struct PyMethodDef PyMethodDef;
 
-#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
+PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);
 PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, 
                                          PyObject *);
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #15422: Get rid of PyCFunction_New macro. Use PyCFunction_NewEx
+  function (PyCFunction_New func is still present for backward compatibility).
+
 - Issue #16672: Improve performance tracing performance
 
 - Issue #14470: Remove w9xpopen support per PEP 11.
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -741,7 +741,7 @@
     wr = PyWeakref_NewRef((PyObject *) self, NULL);
     if (wr == NULL)
         goto err;
-    self->wr_callback = PyCFunction_New(&wr_callback_def, wr);
+    self->wr_callback = PyCFunction_NewEx(&wr_callback_def, wr, NULL);
     Py_DECREF(wr);
     if (self->wr_callback == NULL)
         goto err;
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -115,7 +115,7 @@
                      ((PyTypeObject *)type)->tp_name);
         return NULL;
     }
-    return PyCFunction_New(descr->d_method, type);
+    return PyCFunction_NewEx(descr->d_method, type, NULL);
 }
 
 static PyObject *
@@ -125,7 +125,7 @@
 
     if (descr_check((PyDescrObject *)descr, obj, &res))
         return res;
-    return PyCFunction_New(descr->d_method, obj);
+    return PyCFunction_NewEx(descr->d_method, obj, NULL);
 }
 
 static PyObject *
@@ -239,7 +239,7 @@
         return NULL;
     }
 
-    func = PyCFunction_New(descr->d_method, self);
+    func = PyCFunction_NewEx(descr->d_method, self, NULL);
     if (func == NULL)
         return NULL;
     args = PyTuple_GetSlice(args, 1, argc);
@@ -292,7 +292,7 @@
         return NULL;
     }
 
-    func = PyCFunction_New(descr->d_method, self);
+    func = PyCFunction_NewEx(descr->d_method, self, NULL);
     if (func == NULL)
         return NULL;
     args = PyTuple_GetSlice(args, 1, argc);
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -14,6 +14,12 @@
 #endif
 
 PyObject *
+PyCFunction_New(PyMethodDef *ml, PyObject *self)
+{
+    return PyCFunction_NewEx(ml, self, NULL);
+}
+
+PyObject *
 PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
 {
     PyCFunctionObject *op;
@@ -346,17 +352,3 @@
                            "free PyCFunction",
                            numfree, sizeof(PyCFunction));
 }
-
-/* PyCFunction_New() is now just a macro that calls PyCFunction_NewEx(),
-   but it's part of the API so we need to keep a function around that
-   existing C extensions can call.
-*/
-
-#undef PyCFunction_New
-PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);
-
-PyObject *
-PyCFunction_New(PyMethodDef *ml, PyObject *self)
-{
-    return PyCFunction_NewEx(ml, self, NULL);
-}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -3811,7 +3811,7 @@
             descr = PyDescr_NewClassMethod(type, meth);
         }
         else if (meth->ml_flags & METH_STATIC) {
-            PyObject *cfunc = PyCFunction_New(meth, (PyObject*)type);
+          PyObject *cfunc = PyCFunction_NewEx(meth, (PyObject*)type, NULL);
             if (cfunc == NULL)
                 return -1;
             descr = PyStaticMethod_New(cfunc);
@@ -4879,7 +4879,7 @@
 
     if (_PyDict_GetItemId(type->tp_dict, &PyId___new__) != NULL)
         return 0;
-    func = PyCFunction_New(tp_new_methoddef, (PyObject *)type);
+    func = PyCFunction_NewEx(tp_new_methoddef, (PyObject *)type, NULL);
     if (func == NULL)
         return -1;
     if (_PyDict_SetItemId(type->tp_dict, &PyId___new__, func)) {
diff --git a/PC/python3.def b/PC/python3.def
--- a/PC/python3.def
+++ b/PC/python3.def
@@ -38,6 +38,7 @@
   PyCFunction_GetFlags=python34.PyCFunction_GetFlags
   PyCFunction_GetFunction=python34.PyCFunction_GetFunction
   PyCFunction_GetSelf=python34.PyCFunction_GetSelf
+  PyCFunction_New=python34.PyCFunction_New
   PyCFunction_NewEx=python34.PyCFunction_NewEx
   PyCFunction_Type=python34.PyCFunction_Type DATA
   PyCallIter_New=python34.PyCallIter_New
diff --git a/PC/python34stub.def b/PC/python34stub.def
--- a/PC/python34stub.def
+++ b/PC/python34stub.def
@@ -37,6 +37,7 @@
 PyCFunction_GetFlags
 PyCFunction_GetFunction
 PyCFunction_GetSelf
+PyCFunction_New
 PyCFunction_NewEx
 PyCFunction_Type
 PyCallIter_New
diff --git a/Python/codecs.c b/Python/codecs.c
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -1026,7 +1026,7 @@
 
     if (interp->codec_error_registry) {
         for (i = 0; i < Py_ARRAY_LENGTH(methods); ++i) {
-            PyObject *func = PyCFunction_New(&methods[i].def, NULL);
+            PyObject *func = PyCFunction_NewEx(&methods[i].def, NULL, NULL);
             int res;
             if (!func)
                 Py_FatalError("can't initialize codec error registry");

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list