Skip to content

Commit a22e8bd

Browse files
committed
Added all PyTypeObjects to the appropriate header files.
Before the patch a lot of internal types weren't available in the header files. The patch exposes the new iterators, views and some other types to all C modules. I've also renamed some of the types and tp_names.
1 parent 513b2ac commit a22e8bd

17 files changed

+56
-44
lines changed

Include/bytesobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef struct {
2929

3030
/* Type object */
3131
PyAPI_DATA(PyTypeObject) PyBytes_Type;
32+
PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
3233

3334
/* Type check macros */
3435
#define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type)

Include/descrobject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ typedef struct {
6767
void *d_wrapped; /* This can be any function pointer */
6868
} PyWrapperDescrObject;
6969

70+
PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type;
71+
PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
72+
PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
73+
PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
7074
PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
75+
PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
7176

7277
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
7378
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);

Include/dictobject.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,23 @@ struct _dictobject {
8989
};
9090

9191
PyAPI_DATA(PyTypeObject) PyDict_Type;
92+
PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;
93+
PyAPI_DATA(PyTypeObject) PyDictIterValue_Type;
94+
PyAPI_DATA(PyTypeObject) PyDictIterItem_Type;
95+
PyAPI_DATA(PyTypeObject) PyDictKeys_Type;
96+
PyAPI_DATA(PyTypeObject) PyDictItems_Type;
97+
PyAPI_DATA(PyTypeObject) PyDictValues_Type;
9298

9399
#define PyDict_Check(op) \
94100
PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_DICT_SUBCLASS)
95101
#define PyDict_CheckExact(op) (Py_Type(op) == &PyDict_Type)
102+
#define PyDictKeys_Check(op) (Py_Type(op) == &PyDictKeys_Type)
103+
#define PyDictItems_Check(op) (Py_Type(op) == &PyDictItems_Type)
104+
#define PyDictValues_Check(op) (Py_Type(op) == &PyDictValues_Type)
105+
/* This excludes Values, since they are not sets. */
106+
# define PyDictViewSet_Check(op) \
107+
(PyDictKeys_Check(op) || PyDictItems_Check(op))
108+
96109

97110
PyAPI_FUNC(PyObject *) PyDict_New(void);
98111
PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);

Include/iterobject.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ extern "C" {
66
#endif
77

88
PyAPI_DATA(PyTypeObject) PySeqIter_Type;
9+
PyAPI_DATA(PyTypeObject) PyCallIter_Type;
10+
PyAPI_DATA(PyTypeObject) PyZipIter_Type;
11+
PyAPI_DATA(PyTypeObject) PyCmpWrapper_Type;
912

1013
#define PySeqIter_Check(op) (Py_Type(op) == &PySeqIter_Type)
1114

1215
PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *);
1316

14-
PyAPI_DATA(PyTypeObject) PyCallIter_Type;
1517

1618
#define PyCallIter_Check(op) (Py_Type(op) == &PyCallIter_Type)
1719

Include/listobject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ typedef struct {
3939
} PyListObject;
4040

4141
PyAPI_DATA(PyTypeObject) PyList_Type;
42+
PyAPI_DATA(PyTypeObject) PyListIter_Type;
43+
PyAPI_DATA(PyTypeObject) PyListRevIter_Type;
44+
PyAPI_DATA(PyTypeObject) PySortWrapper_Type;
4245

4346
#define PyList_Check(op) \
4447
PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_LIST_SUBCLASS)

Include/rangeobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ they are represented by a start, stop, and step datamembers.
1616
*/
1717

1818
PyAPI_DATA(PyTypeObject) PyRange_Type;
19+
PyAPI_DATA(PyTypeObject) PyRangeIter_Type;
20+
PyAPI_DATA(PyTypeObject) PyLongRangeIter_Type;
1921

2022
#define PyRange_Check(op) (Py_Type(op) == &PyRange_Type)
2123

Include/setobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct _setobject {
5858

5959
PyAPI_DATA(PyTypeObject) PySet_Type;
6060
PyAPI_DATA(PyTypeObject) PyFrozenSet_Type;
61+
PyAPI_DATA(PyTypeObject) PySetIter_Type;
6162

6263
/* Invariants for frozensets:
6364
* data is immutable.

Include/stringobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef struct {
4040
} PyStringObject;
4141

4242
PyAPI_DATA(PyTypeObject) PyString_Type;
43+
PyAPI_DATA(PyTypeObject) PyStringIter_Type;
4344

4445
#define PyString_Check(op) \
4546
PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_STRING_SUBCLASS)

Include/tupleobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef struct {
3232
} PyTupleObject;
3333

3434
PyAPI_DATA(PyTypeObject) PyTuple_Type;
35+
PyAPI_DATA(PyTypeObject) PyTupleIter_Type;
3536

3637
#define PyTuple_Check(op) \
3738
PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_TUPLE_SUBCLASS)

Include/unicodeobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ typedef struct {
417417
} PyUnicodeObject;
418418

419419
PyAPI_DATA(PyTypeObject) PyUnicode_Type;
420+
PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type;
420421

421422
#define SSTATE_NOT_INTERNED 0
422423
#define SSTATE_INTERNED_MORTAL 1

Objects/descrobject.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ descr_traverse(PyObject *self, visitproc visit, void *arg)
383383
return 0;
384384
}
385385

386-
static PyTypeObject PyMethodDescr_Type = {
386+
PyTypeObject PyMethodDescr_Type = {
387387
PyVarObject_HEAD_INIT(&PyType_Type, 0)
388388
"method_descriptor",
389389
sizeof(PyMethodDescrObject),
@@ -421,7 +421,7 @@ static PyTypeObject PyMethodDescr_Type = {
421421
};
422422

423423
/* This is for METH_CLASS in C, not for "f = classmethod(f)" in Python! */
424-
static PyTypeObject PyClassMethodDescr_Type = {
424+
PyTypeObject PyClassMethodDescr_Type = {
425425
PyVarObject_HEAD_INIT(&PyType_Type, 0)
426426
"classmethod_descriptor",
427427
sizeof(PyMethodDescrObject),
@@ -458,7 +458,7 @@ static PyTypeObject PyClassMethodDescr_Type = {
458458
0, /* tp_descr_set */
459459
};
460460

461-
static PyTypeObject PyMemberDescr_Type = {
461+
PyTypeObject PyMemberDescr_Type = {
462462
PyVarObject_HEAD_INIT(&PyType_Type, 0)
463463
"member_descriptor",
464464
sizeof(PyMemberDescrObject),
@@ -495,7 +495,7 @@ static PyTypeObject PyMemberDescr_Type = {
495495
(descrsetfunc)member_set, /* tp_descr_set */
496496
};
497497

498-
static PyTypeObject PyGetSetDescr_Type = {
498+
PyTypeObject PyGetSetDescr_Type = {
499499
PyVarObject_HEAD_INIT(&PyType_Type, 0)
500500
"getset_descriptor",
501501
sizeof(PyGetSetDescrObject),
@@ -786,7 +786,7 @@ proxy_richcompare(proxyobject *v, PyObject *w, int op)
786786
return PyObject_RichCompare(v->dict, w, op);
787787
}
788788

789-
static PyTypeObject proxytype = {
789+
PyTypeObject PyDictProxy_Type = {
790790
PyVarObject_HEAD_INIT(&PyType_Type, 0)
791791
"dictproxy", /* tp_name */
792792
sizeof(proxyobject), /* tp_basicsize */
@@ -829,7 +829,7 @@ PyDictProxy_New(PyObject *dict)
829829
{
830830
proxyobject *pp;
831831

832-
pp = PyObject_GC_New(proxyobject, &proxytype);
832+
pp = PyObject_GC_New(proxyobject, &PyDictProxy_Type);
833833
if (pp != NULL) {
834834
Py_INCREF(dict);
835835
pp->dict = dict;

Objects/dictobject.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,13 +1798,8 @@ dict_tp_clear(PyObject *op)
17981798
return 0;
17991799
}
18001800

1801-
1802-
extern PyTypeObject PyDictIterKey_Type; /* Forward */
1803-
extern PyTypeObject PyDictIterValue_Type; /* Forward */
1804-
extern PyTypeObject PyDictIterItem_Type; /* Forward */
18051801
static PyObject *dictiter_new(PyDictObject *, PyTypeObject *);
18061802

1807-
18081803
PyDoc_STRVAR(contains__doc__,
18091804
"D.__contains__(k) -> True if D has a key k, else False");
18101805

@@ -2401,19 +2396,6 @@ dictview_new(PyObject *dict, PyTypeObject *type)
24012396
- if public then they should probably be in builtins
24022397
*/
24032398

2404-
/* Forward */
2405-
PyTypeObject PyDictKeys_Type;
2406-
PyTypeObject PyDictItems_Type;
2407-
PyTypeObject PyDictValues_Type;
2408-
2409-
#define PyDictKeys_Check(obj) ((obj)->ob_type == &PyDictKeys_Type)
2410-
#define PyDictItems_Check(obj) ((obj)->ob_type == &PyDictItems_Type)
2411-
#define PyDictValues_Check(obj) ((obj)->ob_type == &PyDictValues_Type)
2412-
2413-
/* This excludes Values, since they are not sets. */
2414-
# define PyDictViewSet_Check(obj) \
2415-
(PyDictKeys_Check(obj) || PyDictItems_Check(obj))
2416-
24172399
/* Return 1 if self is a subset of other, iterating over self;
24182400
0 if not; -1 if an error occurred. */
24192401
static int

Objects/iterobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ calliter_iternext(calliterobject *it)
199199

200200
PyTypeObject PyCallIter_Type = {
201201
PyVarObject_HEAD_INIT(&PyType_Type, 0)
202-
"callable-iterator", /* tp_name */
202+
"callable_iterator", /* tp_name */
203203
sizeof(calliterobject), /* tp_basicsize */
204204
0, /* tp_itemsize */
205205
/* methods */
@@ -240,7 +240,7 @@ typedef struct zipiterobject_t {
240240
PyTupleObject *result; /* Reusable tuple for optimization */
241241
} zipiterobject;
242242

243-
static PyTypeObject PyZipIter_Type; /* Forward */
243+
/* Forward */
244244

245245
PyObject *
246246
_PyZip_CreateIter(PyObject* args)
@@ -367,7 +367,7 @@ zipiter_next(zipiterobject *zit)
367367
return result;
368368
}
369369

370-
static PyTypeObject PyZipIter_Type = {
370+
PyTypeObject PyZipIter_Type = {
371371
PyVarObject_HEAD_INIT(0, 0)
372372
"zip_iterator", /* tp_name */
373373
sizeof(zipiterobject), /* tp_basicsize */

Objects/listobject.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ sortwrapper_richcompare(sortwrapperobject *, sortwrapperobject *, int);
17901790
static void
17911791
sortwrapper_dealloc(sortwrapperobject *);
17921792

1793-
static PyTypeObject sortwrapper_type = {
1793+
PyTypeObject PySortWrapper_Type = {
17941794
PyVarObject_HEAD_INIT(&PyType_Type, 0)
17951795
"sortwrapper", /* tp_name */
17961796
sizeof(sortwrapperobject), /* tp_basicsize */
@@ -1822,7 +1822,7 @@ static PyTypeObject sortwrapper_type = {
18221822
static PyObject *
18231823
sortwrapper_richcompare(sortwrapperobject *a, sortwrapperobject *b, int op)
18241824
{
1825-
if (!PyObject_TypeCheck(b, &sortwrapper_type)) {
1825+
if (!PyObject_TypeCheck(b, &PySortWrapper_Type)) {
18261826
PyErr_SetString(PyExc_TypeError,
18271827
"expected a sortwrapperobject");
18281828
return NULL;
@@ -1846,7 +1846,7 @@ build_sortwrapper(PyObject *key, PyObject *value)
18461846
{
18471847
sortwrapperobject *so;
18481848

1849-
so = PyObject_New(sortwrapperobject, &sortwrapper_type);
1849+
so = PyObject_New(sortwrapperobject, &PySortWrapper_Type);
18501850
if (so == NULL)
18511851
return NULL;
18521852
so->key = key;
@@ -1860,7 +1860,7 @@ sortwrapper_getvalue(PyObject *so)
18601860
{
18611861
PyObject *value;
18621862

1863-
if (!PyObject_TypeCheck(so, &sortwrapper_type)) {
1863+
if (!PyObject_TypeCheck(so, &PySortWrapper_Type)) {
18641864
PyErr_SetString(PyExc_TypeError,
18651865
"expected a sortwrapperobject");
18661866
return NULL;
@@ -1893,8 +1893,8 @@ cmpwrapper_call(cmpwrapperobject *co, PyObject *args, PyObject *kwds)
18931893

18941894
if (!PyArg_UnpackTuple(args, "", 2, 2, &x, &y))
18951895
return NULL;
1896-
if (!PyObject_TypeCheck(x, &sortwrapper_type) ||
1897-
!PyObject_TypeCheck(y, &sortwrapper_type)) {
1896+
if (!PyObject_TypeCheck(x, &PySortWrapper_Type) ||
1897+
!PyObject_TypeCheck(y, &PySortWrapper_Type)) {
18981898
PyErr_SetString(PyExc_TypeError,
18991899
"expected a sortwrapperobject");
19001900
return NULL;
@@ -1906,7 +1906,7 @@ cmpwrapper_call(cmpwrapperobject *co, PyObject *args, PyObject *kwds)
19061906

19071907
PyDoc_STRVAR(cmpwrapper_doc, "cmp() wrapper for sort with custom keys.");
19081908

1909-
static PyTypeObject cmpwrapper_type = {
1909+
PyTypeObject PyCmpWrapper_Type = {
19101910
PyVarObject_HEAD_INIT(&PyType_Type, 0)
19111911
"cmpwrapper", /* tp_name */
19121912
sizeof(cmpwrapperobject), /* tp_basicsize */
@@ -1936,7 +1936,7 @@ build_cmpwrapper(PyObject *cmpfunc)
19361936
{
19371937
cmpwrapperobject *co;
19381938

1939-
co = PyObject_New(cmpwrapperobject, &cmpwrapper_type);
1939+
co = PyObject_New(cmpwrapperobject, &PyCmpWrapper_Type);
19401940
if (co == NULL)
19411941
return NULL;
19421942
Py_INCREF(cmpfunc);

Objects/rangeobject.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static PyMethodDef rangeiter_methods[] = {
367367
{NULL, NULL} /* sentinel */
368368
};
369369

370-
PyTypeObject Pyrangeiter_Type = {
370+
PyTypeObject PyRangeIter_Type = {
371371
PyVarObject_HEAD_INIT(&PyType_Type, 0)
372372
"range_iterator", /* tp_name */
373373
sizeof(rangeiterobject), /* tp_basicsize */
@@ -441,7 +441,7 @@ get_len_of_range(long lo, long hi, long step)
441441
static PyObject *
442442
int_range_iter(long start, long stop, long step)
443443
{
444-
rangeiterobject *it = PyObject_New(rangeiterobject, &Pyrangeiter_Type);
444+
rangeiterobject *it = PyObject_New(rangeiterobject, &PyRangeIter_Type);
445445
if (it == NULL)
446446
return NULL;
447447
it->start = start;
@@ -519,9 +519,9 @@ longrangeiter_next(longrangeiterobject *r)
519519
return result;
520520
}
521521

522-
static PyTypeObject Pylongrangeiter_Type = {
522+
PyTypeObject PyLongRangeIter_Type = {
523523
PyVarObject_HEAD_INIT(&PyType_Type, 0)
524-
"rangeiterator", /* tp_name */
524+
"longrange_iterator", /* tp_name */
525525
sizeof(longrangeiterobject), /* tp_basicsize */
526526
0, /* tp_itemsize */
527527
/* methods */
@@ -567,7 +567,7 @@ range_iter(PyObject *seq)
567567
PyLong_AsLong(r->stop),
568568
PyLong_AsLong(r->step));
569569

570-
it = PyObject_New(longrangeiterobject, &Pylongrangeiter_Type);
570+
it = PyObject_New(longrangeiterobject, &PyLongRangeIter_Type);
571571
if (it == NULL)
572572
return NULL;
573573

@@ -627,7 +627,7 @@ range_reverse(PyObject *seq)
627627
return int_range_iter(new_start, new_stop, -step);
628628
}
629629

630-
it = PyObject_New(longrangeiterobject, &Pylongrangeiter_Type);
630+
it = PyObject_New(longrangeiterobject, &PyLongRangeIter_Type);
631631
if (it == NULL)
632632
return NULL;
633633

Objects/setobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ static PyObject *setiter_iternext(setiterobject *si)
849849
return NULL;
850850
}
851851

852-
static PyTypeObject PySetIter_Type = {
852+
PyTypeObject PySetIter_Type = {
853853
PyVarObject_HEAD_INIT(&PyType_Type, 0)
854854
"set_iterator", /* tp_name */
855855
sizeof(setiterobject), /* tp_basicsize */

Objects/tupleobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ static PyMethodDef tupleiter_methods[] = {
840840

841841
PyTypeObject PyTupleIter_Type = {
842842
PyVarObject_HEAD_INIT(&PyType_Type, 0)
843-
"tupleiterator", /* tp_name */
843+
"tuple_iterator", /* tp_name */
844844
sizeof(tupleiterobject), /* tp_basicsize */
845845
0, /* tp_itemsize */
846846
/* methods */

0 commit comments

Comments
 (0)