Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50e9fb9

Browse files
committed
Completely get rid of PyClass and PyInstance.
(classobject.[ch] aren't empty yet because they also define PyMethod.) This breaks lots of stuff, notably cPickle. But it's a step in the right direction. I'll clean it up later. (Also a few unrelated changes, e.g. T_NONE to define a "struct member" that is always None, and simplification of __hash__ -- these are unfinished.)
1 parent d033ddf commit 50e9fb9

22 files changed

+325
-2543
lines changed

Include/Python.h

-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77
#include "patchlevel.h"
88
#include "pyconfig.h"
99

10-
/* Cyclic gc is always enabled, starting with release 2.3a1. Supply the
11-
* old symbol for the benefit of extension modules written before then
12-
* that may be conditionalizing on it. The core doesn't use it anymore.
13-
*/
14-
#ifndef WITH_CYCLE_GC
15-
#define WITH_CYCLE_GC 1
16-
#endif
17-
1810
#include <limits.h>
1911

2012
#ifndef UCHAR_MAX

Include/classobject.h

+2-42
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
/* Class object interface */
1+
/* Former class object interface -- now only (un)bound methods are here */
32

43
/* Revealing some structures (not for general use) */
54

@@ -9,24 +8,6 @@
98
extern "C" {
109
#endif
1110

12-
typedef struct {
13-
PyObject_HEAD
14-
PyObject *cl_bases; /* A tuple of class objects */
15-
PyObject *cl_dict; /* A dictionary */
16-
PyObject *cl_name; /* A string */
17-
/* The following three are functions or NULL */
18-
PyObject *cl_getattr;
19-
PyObject *cl_setattr;
20-
PyObject *cl_delattr;
21-
} PyClassObject;
22-
23-
typedef struct {
24-
PyObject_HEAD
25-
PyClassObject *in_class; /* The class object */
26-
PyObject *in_dict; /* A dictionary */
27-
PyObject *in_weakreflist; /* List of weak references */
28-
} PyInstanceObject;
29-
3011
typedef struct {
3112
PyObject_HEAD
3213
PyObject *im_func; /* The callable object implementing the method */
@@ -35,34 +16,16 @@ typedef struct {
3516
PyObject *im_weakreflist; /* List of weak references */
3617
} PyMethodObject;
3718

38-
PyAPI_DATA(PyTypeObject) PyClass_Type, PyInstance_Type, PyMethod_Type;
19+
PyAPI_DATA(PyTypeObject) PyMethod_Type;
3920

40-
#define PyClass_Check(op) ((op)->ob_type == &PyClass_Type)
41-
#define PyInstance_Check(op) ((op)->ob_type == &PyInstance_Type)
4221
#define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type)
4322

44-
PyAPI_FUNC(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *);
45-
PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *,
46-
PyObject *);
47-
PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);
4823
PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
4924

5025
PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);
5126
PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
5227
PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *);
5328

54-
/* Look up attribute with name (a string) on instance object pinst, using
55-
* only the instance and base class dicts. If a descriptor is found in
56-
* a class dict, the descriptor is returned without calling it.
57-
* Returns NULL if nothing found, else a borrowed reference to the
58-
* value associated with name in the dict in which name was found.
59-
* The point of this routine is that it never calls arbitrary Python
60-
* code, so is always "safe": all it does is dict lookups. The function
61-
* can't fail, never sets an exception, and NULL is not an error (it just
62-
* means "not found").
63-
*/
64-
PyAPI_FUNC(PyObject *) _PyInstance_Lookup(PyObject *pinst, PyObject *name);
65-
6629
/* Macros for direct access to these values. Type checks are *not*
6730
done, so use with care. */
6831
#define PyMethod_GET_FUNCTION(meth) \
@@ -72,9 +35,6 @@ PyAPI_FUNC(PyObject *) _PyInstance_Lookup(PyObject *pinst, PyObject *name);
7235
#define PyMethod_GET_CLASS(meth) \
7336
(((PyMethodObject *)meth) -> im_class)
7437

75-
PyAPI_FUNC(int) PyClass_IsSubclass(PyObject *, PyObject *);
76-
77-
7838
#ifdef __cplusplus
7939
}
8040
#endif

Include/methodobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
6363
#define METH_CLASS 0x0010
6464
#define METH_STATIC 0x0020
6565

66-
/* METH_COEXIST allows a method to be entered eventhough a slot has
66+
/* METH_COEXIST allows a method to be entered even though a slot has
6767
already filled the entry. When defined, the flag allows a separate
6868
method, "__contains__" for example, to coexist with a defined
6969
slot like sq_contains. */

Include/object.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ typedef int (*visitproc)(PyObject *, void *);
147147
typedef int (*traverseproc)(PyObject *, visitproc, void *);
148148

149149
typedef struct {
150-
/* Number implementations should check *both*
150+
/* Number implementations must check *both*
151151
arguments for proper type and implement the necessary conversions
152152
in the slot functions themselves. */
153153

@@ -173,7 +173,7 @@ typedef struct {
173173
unaryfunc nb_float;
174174
unaryfunc nb_oct;
175175
unaryfunc nb_hex;
176-
/* Added in release 2.0 */
176+
177177
binaryfunc nb_inplace_add;
178178
binaryfunc nb_inplace_subtract;
179179
binaryfunc nb_inplace_multiply;
@@ -185,13 +185,11 @@ typedef struct {
185185
binaryfunc nb_inplace_xor;
186186
binaryfunc nb_inplace_or;
187187

188-
/* Added in release 2.2 */
189188
binaryfunc nb_floor_divide;
190189
binaryfunc nb_true_divide;
191190
binaryfunc nb_inplace_floor_divide;
192191
binaryfunc nb_inplace_true_divide;
193192

194-
/* Added in release 2.5 */
195193
lenfunc nb_index;
196194
} PyNumberMethods;
197195

@@ -204,7 +202,7 @@ typedef struct {
204202
ssizeobjargproc sq_ass_item;
205203
ssizessizeobjargproc sq_ass_slice;
206204
objobjproc sq_contains;
207-
/* Added in release 2.0 */
205+
208206
binaryfunc sq_inplace_concat;
209207
ssizeargfunc sq_inplace_repeat;
210208
} PySequenceMethods;
@@ -292,7 +290,6 @@ typedef struct _typeobject {
292290
/* weak reference enabler */
293291
Py_ssize_t tp_weaklistoffset;
294292

295-
/* Added in release 2.2 */
296293
/* Iterators */
297294
getiterfunc tp_iter;
298295
iternextfunc tp_iternext;

Include/structmember.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ typedef struct PyMemberDef {
6767
converting to None. */
6868
#ifdef HAVE_LONG_LONG
6969
#define T_LONGLONG 17
70-
#define T_ULONGLONG 18
70+
#define T_ULONGLONG 18
7171
#endif /* HAVE_LONG_LONG */
7272

73+
#define T_NONE 19 /* Value is always None */
74+
7375
/* Flags */
7476
#define READONLY 1
7577
#define RO READONLY /* Shorthand */

Modules/_sre.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -3363,19 +3363,19 @@ static PyMethodDef _functions[] = {
33633363
{NULL, NULL}
33643364
};
33653365

3366-
#if PY_VERSION_HEX < 0x02030000
3367-
DL_EXPORT(void) init_sre(void)
3368-
#else
33693366
PyMODINIT_FUNC init_sre(void)
3370-
#endif
33713367
{
33723368
PyObject* m;
33733369
PyObject* d;
33743370
PyObject* x;
33753371

3376-
/* Patch object types */
3377-
Pattern_Type.ob_type = Match_Type.ob_type =
3378-
Scanner_Type.ob_type = &PyType_Type;
3372+
/* Initialize object types */
3373+
if (PyType_Ready(&Pattern_Type) < 0)
3374+
return;
3375+
if (PyType_Ready(&Match_Type) < 0)
3376+
return;
3377+
if (PyType_Ready(&Scanner_Type) < 0)
3378+
return;
33793379

33803380
m = Py_InitModule("_" SRE_MODULE, _functions);
33813381
if (m == NULL)

Modules/arraymodule.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,8 @@ initarray(void)
21122112
{
21132113
PyObject *m;
21142114

2115-
Arraytype.ob_type = &PyType_Type;
2115+
if (PyType_Ready(&Arraytype) < 0)
2116+
return;
21162117
PyArrayIter_Type.ob_type = &PyType_Type;
21172118
m = Py_InitModule3("array", a_methods, module_doc);
21182119
if (m == NULL)

0 commit comments

Comments
 (0)