Get rid of defined and tp_defined -- there's no need to · python/cpython@687ae00 (original) (raw)

`@@ -44,7 +44,7 @@ type_module(PyTypeObject *type, void *context)

`

44

44

` (int)(s - type->tp_name));

`

45

45

`if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE))

`

46

46

`return PyString_FromString("builtin");

`

47

``

`-

mod = PyDict_GetItemString(type->tp_defined, "module");

`

``

47

`+

mod = PyDict_GetItemString(type->tp_dict, "module");

`

48

48

`if (mod != NULL && PyString_Check(mod)) {

`

49

49

`Py_INCREF(mod);

`

50

50

`return mod;

`

`@@ -80,21 +80,10 @@ type_dict(PyTypeObject *type, void *context)

`

80

80

`return PyDictProxy_New(type->tp_dict);

`

81

81

`}

`

82

82

``

83

``

`-

static PyObject *

`

84

``

`-

type_defined(PyTypeObject *type, void *context)

`

85

``

`-

{

`

86

``

`-

if (type->tp_defined == NULL) {

`

87

``

`-

Py_INCREF(Py_None);

`

88

``

`-

return Py_None;

`

89

``

`-

}

`

90

``

`-

return PyDictProxy_New(type->tp_defined);

`

91

``

`-

}

`

92

``

-

93

83

`PyGetSetDef type_getsets[] = {

`

94

84

` {"name", (getter)type_name, NULL, NULL},

`

95

85

` {"module", (getter)type_module, (setter)type_set_module, NULL},

`

96

86

` {"dict", (getter)type_dict, NULL, NULL},

`

97

``

`-

{"defined", (getter)type_defined, NULL, NULL},

`

98

87

` {0}

`

99

88

`};

`

100

89

``

`@@ -838,8 +827,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)

`

838

827

`Py_INCREF(base);

`

839

828

`type->tp_base = base;

`

840

829

``

841

``

`-

/* Initialize tp_defined from passed-in dict */

`

842

``

`-

type->tp_defined = dict = PyDict_Copy(dict);

`

``

830

`+

/* Initialize tp_dict from passed-in dict */

`

``

831

`+

type->tp_dict = dict = PyDict_Copy(dict);

`

843

832

`if (dict == NULL) {

`

844

833

`Py_DECREF(type);

`

845

834

`return NULL;

`

`@@ -973,14 +962,14 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)

`

973

962

`int i, n;

`

974

963

`PyObject *mro, *res, *dict;

`

975

964

``

976

``

`-

/* Look in tp_defined of types in MRO */

`

``

965

`+

/* Look in tp_dict of types in MRO */

`

977

966

`mro = type->tp_mro;

`

978

967

`assert(PyTuple_Check(mro));

`

979

968

`n = PyTuple_GET_SIZE(mro);

`

980

969

`for (i = 0; i < n; i++) {

`

981

970

`type = (PyTypeObject *) PyTuple_GET_ITEM(mro, i);

`

982

971

`assert(PyType_Check(type));

`

983

``

`-

dict = type->tp_defined;

`

``

972

`+

dict = type->tp_dict;

`

984

973

`assert(dict && PyDict_Check(dict));

`

985

974

`res = PyDict_GetItem(dict, name);

`

986

975

`if (res != NULL)

`

`@@ -1014,7 +1003,7 @@ type_getattro(PyTypeObject *type, PyObject *name)

`

1014

1003

` (PyObject *)type, (PyObject *)metatype);

`

1015

1004

` }

`

1016

1005

``

1017

``

`-

/* Look in tp_defined of this type and its bases */

`

``

1006

`+

/* Look in tp_dict of this type and its bases */

`

1018

1007

`res = _PyType_Lookup(type, name);

`

1019

1008

`if (res != NULL) {

`

1020

1009

`f = res->ob_type->tp_descr_get;

`

`@@ -1070,7 +1059,7 @@ type_dealloc(PyTypeObject *type)

`

1070

1059

`Py_XDECREF(type->tp_dict);

`

1071

1060

`Py_XDECREF(type->tp_bases);

`

1072

1061

`Py_XDECREF(type->tp_mro);

`

1073

``

`-

Py_XDECREF(type->tp_defined);

`

``

1062

`+

Py_XDECREF(type->tp_cache);

`

1074

1063

`Py_XDECREF(type->tp_subclasses);

`

1075

1064

`Py_XDECREF(et->name);

`

1076

1065

`Py_XDECREF(et->slots);

`

`@@ -1136,7 +1125,7 @@ type_traverse(PyTypeObject *type, visitproc visit, void *arg)

`

1136

1125

` }

`

1137

1126

``

1138

1127

`VISIT(type->tp_dict);

`

1139

``

`-

VISIT(type->tp_defined);

`

``

1128

`+

VISIT(type->tp_cache);

`

1140

1129

`VISIT(type->tp_mro);

`

1141

1130

`VISIT(type->tp_bases);

`

1142

1131

`VISIT(type->tp_base);

`

`@@ -1167,7 +1156,7 @@ type_clear(PyTypeObject *type)

`

1167

1156

` }

`

1168

1157

``

1169

1158

`CLEAR(type->tp_dict);

`

1170

``

`-

CLEAR(type->tp_defined);

`

``

1159

`+

CLEAR(type->tp_cache);

`

1171

1160

`CLEAR(type->tp_mro);

`

1172

1161

`CLEAR(type->tp_bases);

`

1173

1162

`CLEAR(type->tp_base);

`

`@@ -1455,7 +1444,7 @@ PyTypeObject PyBaseObject_Type = {

`

1455

1444

`static int

`

1456

1445

`add_methods(PyTypeObject *type, PyMethodDef *meth)

`

1457

1446

`{

`

1458

``

`-

PyObject *dict = type->tp_defined;

`

``

1447

`+

PyObject *dict = type->tp_dict;

`

1459

1448

``

1460

1449

`for (; meth->ml_name != NULL; meth++) {

`

1461

1450

`PyObject *descr;

`

`@@ -1474,7 +1463,7 @@ add_methods(PyTypeObject *type, PyMethodDef *meth)

`

1474

1463

`static int

`

1475

1464

`add_members(PyTypeObject *type, PyMemberDef *memb)

`

1476

1465

`{

`

1477

``

`-

PyObject *dict = type->tp_defined;

`

``

1466

`+

PyObject *dict = type->tp_dict;

`

1478

1467

``

1479

1468

`for (; memb->name != NULL; memb++) {

`

1480

1469

`PyObject *descr;

`

`@@ -1493,7 +1482,7 @@ add_members(PyTypeObject *type, PyMemberDef *memb)

`

1493

1482

`static int

`

1494

1483

`add_getset(PyTypeObject *type, PyGetSetDef *gsp)

`

1495

1484

`{

`

1496

``

`-

PyObject *dict = type->tp_defined;

`

``

1485

`+

PyObject *dict = type->tp_dict;

`

1497

1486

``

1498

1487

`for (; gsp->name != NULL; gsp++) {

`

1499

1488

`PyObject *descr;

`

`@@ -1746,7 +1735,6 @@ PyType_Ready(PyTypeObject *type)

`

1746

1735

`return 0;

`

1747

1736

` }

`

1748

1737

`assert((type->tp_flags & Py_TPFLAGS_READYING) == 0);

`

1749

``

`-

assert(type->tp_dict == NULL);

`

1750

1738

``

1751

1739

`type->tp_flags |= Py_TPFLAGS_READYING;

`

1752

1740

``

`@@ -1773,16 +1761,16 @@ PyType_Ready(PyTypeObject *type)

`

1773

1761

` goto error;

`

1774

1762

` }

`

1775

1763

``

1776

``

`-

/* Initialize tp_defined */

`

1777

``

`-

dict = type->tp_defined;

`

``

1764

`+

/* Initialize tp_dict */

`

``

1765

`+

dict = type->tp_dict;

`

1778

1766

`if (dict == NULL) {

`

1779

1767

`dict = PyDict_New();

`

1780

1768

`if (dict == NULL)

`

1781

1769

` goto error;

`

1782

``

`-

type->tp_defined = dict;

`

``

1770

`+

type->tp_dict = dict;

`

1783

1771

` }

`

1784

1772

``

1785

``

`-

/* Add type-specific descriptors to tp_defined */

`

``

1773

`+

/* Add type-specific descriptors to tp_dict */

`

1786

1774

`if (add_operators(type) < 0)

`

1787

1775

` goto error;

`

1788

1776

`if (type->tp_methods != NULL) {

`

`@@ -1798,12 +1786,6 @@ PyType_Ready(PyTypeObject *type)

`

1798

1786

` goto error;

`

1799

1787

` }

`

1800

1788

``

1801

``

`-

/* Temporarily make tp_dict the same object as tp_defined.

`

1802

``

`-

(This is needed to call mro(), and can stay this way for

`

1803

``

`-

dynamic types). */

`

1804

``

`-

Py_INCREF(type->tp_defined);

`

1805

``

`-

type->tp_dict = type->tp_defined;

`

1806

``

-

1807

1789

`/* Calculate method resolution order */

`

1808

1790

`if (mro_internal(type) < 0) {

`

1809

1791

` goto error;

`

`@@ -2676,18 +2658,18 @@ add_tp_new_wrapper(PyTypeObject *type)

`

2676

2658

`{

`

2677

2659

`PyObject *func;

`

2678

2660

``

2679

``

`-

if (PyDict_GetItemString(type->tp_defined, "new") != NULL)

`

``

2661

`+

if (PyDict_GetItemString(type->tp_dict, "new") != NULL)

`

2680

2662

`return 0;

`

2681

2663

`func = PyCFunction_New(tp_new_methoddef, (PyObject *)type);

`

2682

2664

`if (func == NULL)

`

2683

2665

`return -1;

`

2684

``

`-

return PyDict_SetItemString(type->tp_defined, "new", func);

`

``

2666

`+

return PyDict_SetItemString(type->tp_dict, "new", func);

`

2685

2667

`}

`

2686

2668

``

2687

2669

`static int

`

2688

2670

`add_wrappers(PyTypeObject *type, struct wrapperbase *wraps, void *wrapped)

`

2689

2671

`{

`

2690

``

`-

PyObject *dict = type->tp_defined;

`

``

2672

`+

PyObject *dict = type->tp_dict;

`

2691

2673

``

2692

2674

`for (; wraps->name != NULL; wraps++) {

`

2693

2675

`PyObject *descr;

`

`@@ -2706,14 +2688,14 @@ add_wrappers(PyTypeObject *type, struct wrapperbase *wraps, void *wrapped)

`

2706

2688

`/* This function is called by PyType_Ready() to populate the type's

`

2707

2689

` dictionary with method descriptors for function slots. For each

`

2708

2690

` function slot (like tp_repr) that's defined in the type, one or

`

2709

``

`-

more corresponding descriptors are added in the type's tp_defined

`

``

2691

`+

more corresponding descriptors are added in the type's tp_dict

`

2710

2692

` dictionary under the appropriate name (like repr). Some

`

2711

2693

` function slots cause more than one descriptor to be added (for

`

2712

2694

` example, the nb_add slot adds both add and radd

`

2713

2695

` descriptors) and some function slots compete for the same

`

2714

2696

` descriptor (for example both sq_item and mp_subscript generate a

`

2715

2697

` getitem descriptor). This only adds new descriptors and

`

2716

``

`-

doesn't overwrite entries in tp_defined that were previously

`

``

2698

`+

doesn't overwrite entries in tp_dict that were previously

`

2717

2699

` defined. The descriptors contain a reference to the C function

`

2718

2700

` they must call, so that it's safe if they are copied into a

`

2719

2701

` subtype's dict and the subtype has a different C function in

`

`@@ -3942,7 +3924,7 @@ fixup_slot_dispatchers(PyTypeObject *type)

`

3942

3924

`base = (PyTypeObject *)PyTuple_GET_ITEM(mro, i);

`

3943

3925

`assert(PyType_Check(base));

`

3944

3926

`descr = PyDict_GetItem(

`

3945

``

`-

base->tp_defined, p->name_strobj);

`

``

3927

`+

base->tp_dict, p->name_strobj);

`

3946

3928

`if (descr != NULL)

`

3947

3929

`break;

`

3948

3930

` }

`

`@@ -4055,7 +4037,7 @@ super_getattro(PyObject *self, PyObject *name)

`

4055

4037

`tmp = PyTuple_GET_ITEM(mro, i);

`

4056

4038

`assert(PyType_Check(tmp));

`

4057

4039

`res = PyDict_GetItem(

`

4058

``

`-

((PyTypeObject *)tmp)->tp_defined, name);

`

``

4040

`+

((PyTypeObject *)tmp)->tp_dict, name);

`

4059

4041

`if (res != NULL) {

`

4060

4042

`Py_INCREF(res);

`

4061

4043

`f = res->ob_type->tp_descr_get;

`