[Python-checkins] cpython: Rename _PyIter_GetBuiltin to _PyObject_GetBuiltin, and do not include it in the

antoine.pitrou python-checkins at python.org
Thu Apr 5 00:11:58 CEST 2012


http://hg.python.org/cpython/rev/fb907ee4fdfa
changeset:   76105:fb907ee4fdfa
parent:      76103:68ef2fc47da6
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Thu Apr 05 00:04:20 2012 +0200
summary:
  Rename _PyIter_GetBuiltin to _PyObject_GetBuiltin, and do not include it in the stable ABI.

files:
  Include/iterobject.h      |   2 --
  Include/object.h          |   5 +++++
  Modules/arraymodule.c     |   2 +-
  Objects/bytearrayobject.c |   4 ++--
  Objects/bytesobject.c     |   4 ++--
  Objects/dictobject.c      |   2 +-
  Objects/iterobject.c      |  21 ++++-----------------
  Objects/listobject.c      |   6 +++---
  Objects/object.c          |  13 +++++++++++++
  Objects/rangeobject.c     |   4 ++--
  Objects/setobject.c       |   2 +-
  Objects/tupleobject.c     |   4 ++--
  Objects/unicodeobject.c   |   4 ++--
  13 files changed, 38 insertions(+), 35 deletions(-)


diff --git a/Include/iterobject.h b/Include/iterobject.h
--- a/Include/iterobject.h
+++ b/Include/iterobject.h
@@ -18,8 +18,6 @@
 
 PyAPI_FUNC(PyObject *) PyCallIter_New(PyObject *, PyObject *);
 
-PyAPI_FUNC(PyObject *) _PyIter_GetBuiltin(const char *iter);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/Include/object.h b/Include/object.h
--- a/Include/object.h
+++ b/Include/object.h
@@ -535,6 +535,11 @@
 _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
                                  PyObject *, PyObject *);
 
+/* Helper to look up a builtin object */
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(PyObject *)
+_PyObject_GetBuiltin(const char *name);
+#endif
 
 /* PyObject_Dir(obj) acts like Python builtins.dir(obj), returning a
    list of strings.  PyObject_Dir(NULL) is like builtins.dir(),
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -2756,7 +2756,7 @@
 static PyObject *
 arrayiter_reduce(arrayiterobject *it)
 {
-    return Py_BuildValue("N(O)n", _PyIter_GetBuiltin("iter"),
+    return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"),
                          it->ao, it->index);
 }
 
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -3018,13 +3018,13 @@
 bytearrayiter_reduce(bytesiterobject *it)
 {
     if (it->it_seq != NULL) {
-        return Py_BuildValue("N(O)n", _PyIter_GetBuiltin("iter"),
+        return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"),
                              it->it_seq, it->it_index);
     } else {
         PyObject *u = PyUnicode_FromUnicode(NULL, 0);
         if (u == NULL)
             return NULL;
-        return Py_BuildValue("N(N)", _PyIter_GetBuiltin("iter"), u);
+        return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), u);
     }
 }
 
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -3078,13 +3078,13 @@
 striter_reduce(striterobject *it)
 {
     if (it->it_seq != NULL) {
-        return Py_BuildValue("N(O)n", _PyIter_GetBuiltin("iter"),
+        return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"),
                              it->it_seq, it->it_index);
     } else {
         PyObject *u = PyUnicode_FromUnicode(NULL, 0);
         if (u == NULL)
             return NULL;
-        return Py_BuildValue("N(N)", _PyIter_GetBuiltin("iter"), u);
+        return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), u);
     }
 }
 
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2610,7 +2610,7 @@
         Py_DECREF(list);
         return NULL;
     }
-    return Py_BuildValue("N(N)", _PyIter_GetBuiltin("iter"), list);
+    return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), list);
 }
 
 /***********************************************/
diff --git a/Objects/iterobject.c b/Objects/iterobject.c
--- a/Objects/iterobject.c
+++ b/Objects/iterobject.c
@@ -2,19 +2,6 @@
 
 #include "Python.h"
 
-/* Convenience function to get builtins.iter or builtins.reversed */
-PyObject *
-_PyIter_GetBuiltin(const char *iter)
-{
-    PyObject *mod, *attr;
-    mod = PyImport_ImportModule("builtins");
-    if (mod ==  NULL)
-        return NULL;
-    attr = PyObject_GetAttrString(mod, iter);
-    Py_DECREF(mod);
-    return attr;
-}
-
 typedef struct {
     PyObject_HEAD
     long      it_index;
@@ -105,10 +92,10 @@
 iter_reduce(seqiterobject *it)
 {
     if (it->it_seq != NULL)
-        return Py_BuildValue("N(O)n", _PyIter_GetBuiltin("iter"),
+        return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"),
                              it->it_seq, it->it_index);
     else
-        return Py_BuildValue("N(())", _PyIter_GetBuiltin("iter"));
+        return Py_BuildValue("N(())", _PyObject_GetBuiltin("iter"));
 }
 
 PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
@@ -242,10 +229,10 @@
 calliter_reduce(calliterobject *it)
 {
     if (it->it_callable != NULL && it->it_sentinel != NULL)
-        return Py_BuildValue("N(OO)", _PyIter_GetBuiltin("iter"),
+        return Py_BuildValue("N(OO)", _PyObject_GetBuiltin("iter"),
                              it->it_callable, it->it_sentinel);
     else
-        return Py_BuildValue("N(())", _PyIter_GetBuiltin("iter"));
+        return Py_BuildValue("N(())", _PyObject_GetBuiltin("iter"));
 }
 
 static PyMethodDef calliter_methods[] = {
diff --git a/Objects/listobject.c b/Objects/listobject.c
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2949,17 +2949,17 @@
     if (forward) {
         listiterobject *it = (listiterobject *)_it;
         if (it->it_seq)
-            return Py_BuildValue("N(O)l", _PyIter_GetBuiltin("iter"),
+            return Py_BuildValue("N(O)l", _PyObject_GetBuiltin("iter"),
                                  it->it_seq, it->it_index);
     } else {
         listreviterobject *it = (listreviterobject *)_it;
         if (it->it_seq)
-            return Py_BuildValue("N(O)n", _PyIter_GetBuiltin("reversed"),
+            return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("reversed"),
                                  it->it_seq, it->it_index);
     }
     /* empty iterator, create an empty list */
     list = PyList_New(0);
     if (list == NULL)
         return NULL;
-    return Py_BuildValue("N(N)", _PyIter_GetBuiltin("iter"), list);
+    return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), list);
 }
diff --git a/Objects/object.c b/Objects/object.c
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1026,6 +1026,19 @@
     return obj;
 }
 
+/* Convenience function to get a builtin from its name */
+PyObject *
+_PyObject_GetBuiltin(const char *name)
+{
+    PyObject *mod, *attr;
+    mod = PyImport_ImportModule("builtins");
+    if (mod == NULL)
+        return NULL;
+    attr = PyObject_GetAttrString(mod, name);
+    Py_DECREF(mod);
+    return attr;
+}
+
 /* Helper used when the __next__ method is removed from a type:
    tp_iternext is never NULL and can be safely called without checking
    on every iteration.
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -985,7 +985,7 @@
     if (range == NULL)
         goto err;
     /* return the result */
-    return Py_BuildValue("N(N)i", _PyIter_GetBuiltin("iter"), range, r->index);
+    return Py_BuildValue("N(N)i", _PyObject_GetBuiltin("iter"), range, r->index);
 err:
     Py_XDECREF(start);
     Py_XDECREF(stop);
@@ -1171,7 +1171,7 @@
     }
 
     /* return the result */
-    return Py_BuildValue("N(N)O", _PyIter_GetBuiltin("iter"), range, r->index);
+    return Py_BuildValue("N(N)O", _PyObject_GetBuiltin("iter"), range, r->index);
 }
 
 static PyObject *
diff --git a/Objects/setobject.c b/Objects/setobject.c
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -856,7 +856,7 @@
         Py_DECREF(list);
         return NULL;
     }
-    return Py_BuildValue("N(N)", _PyIter_GetBuiltin("iter"), list);
+    return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), list);
 }
 
 PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -971,10 +971,10 @@
 tupleiter_reduce(tupleiterobject *it)
 {
     if (it->it_seq)
-        return Py_BuildValue("N(O)l", _PyIter_GetBuiltin("iter"),
+        return Py_BuildValue("N(O)l", _PyObject_GetBuiltin("iter"),
                              it->it_seq, it->it_index);
     else
-        return Py_BuildValue("N(())", _PyIter_GetBuiltin("iter"));
+        return Py_BuildValue("N(())", _PyObject_GetBuiltin("iter"));
 }
 
 static PyObject *
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -14386,13 +14386,13 @@
 unicodeiter_reduce(unicodeiterobject *it)
 {
     if (it->it_seq != NULL) {
-        return Py_BuildValue("N(O)n", _PyIter_GetBuiltin("iter"),
+        return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"),
                              it->it_seq, it->it_index);
     } else {
         PyObject *u = PyUnicode_FromUnicode(NULL, 0);
         if (u == NULL)
             return NULL;
-        return Py_BuildValue("N(N)", _PyIter_GetBuiltin("iter"), u);
+        return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), u);
     }
 }
 

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


More information about the Python-checkins mailing list