@@ -202,6 +202,11 @@ typedef long (*hashfunc)(PyObject *);
202
202
typedef PyObject * (* richcmpfunc ) (PyObject * , PyObject * , int );
203
203
typedef PyObject * (* getiterfunc ) (PyObject * );
204
204
typedef PyObject * (* iternextfunc ) (PyObject * );
205
+ typedef PyObject * (* descrgetfunc ) (PyObject * , PyObject * , PyObject * );
206
+ typedef int (* descrsetfunc ) (PyObject * , PyObject * , PyObject * );
207
+ typedef int (* initproc )(PyObject * , PyObject * , PyObject * );
208
+ typedef PyObject * (* newfunc )(struct _typeobject * , PyObject * , PyObject * );
209
+ typedef PyObject * (* allocfunc )(struct _typeobject * , int );
205
210
206
211
typedef struct _typeobject {
207
212
PyObject_VAR_HEAD
@@ -255,18 +260,48 @@ typedef struct _typeobject {
255
260
getiterfunc tp_iter ;
256
261
iternextfunc tp_iternext ;
257
262
263
+ /* Attribute descriptor and subclassing stuff */
264
+ struct PyMethodDef * tp_methods ;
265
+ struct memberlist * tp_members ;
266
+ struct getsetlist * tp_getset ;
267
+ struct _typeobject * tp_base ;
268
+ PyObject * tp_dict ;
269
+ descrgetfunc tp_descr_get ;
270
+ descrsetfunc tp_descr_set ;
271
+ long tp_dictoffset ;
272
+ initproc tp_init ;
273
+ allocfunc tp_alloc ;
274
+ newfunc tp_new ;
275
+ destructor tp_free ; /* Low-level free-memory routine */
276
+ PyObject * tp_bases ;
277
+ PyObject * tp_mro ; /* method resolution order */
278
+ PyObject * tp_defined ;
279
+
258
280
#ifdef COUNT_ALLOCS
259
281
/* these must be last and never explicitly initialized */
260
- int tp_alloc ;
261
- int tp_free ;
282
+ int tp_allocs ;
283
+ int tp_frees ;
262
284
int tp_maxalloc ;
263
285
struct _typeobject * tp_next ;
264
286
#endif
265
287
} PyTypeObject ;
266
288
267
- extern DL_IMPORT (PyTypeObject ) PyType_Type ; /* The type of type objects */
268
289
269
- #define PyType_Check (op ) ((op)->ob_type == &PyType_Type)
290
+ /* Generic type check */
291
+ extern DL_IMPORT (int ) PyType_IsSubtype (PyTypeObject * , PyTypeObject * );
292
+ #define PyObject_TypeCheck (ob , tp ) \
293
+ ((ob)->ob_type == (tp) || PyType_IsSubtype((ob)->ob_type, (tp)))
294
+
295
+ extern DL_IMPORT (PyTypeObject ) PyType_Type ; /* Metatype */
296
+ extern DL_IMPORT (PyTypeObject ) PyBaseObject_Type ; /* Most base object type */
297
+
298
+ #define PyType_Check (op ) PyObject_TypeCheck(op, &PyType_Type)
299
+
300
+ extern DL_IMPORT (int ) PyType_InitDict (PyTypeObject * );
301
+ extern DL_IMPORT (PyObject * ) PyType_GenericAlloc (PyTypeObject * , int );
302
+ extern DL_IMPORT (PyObject * ) PyType_GenericNew (PyTypeObject * ,
303
+ PyObject * , PyObject * );
304
+ extern DL_IMPORT (PyObject * ) _PyType_Lookup (PyTypeObject * , PyObject * );
270
305
271
306
/* Generic operations on objects */
272
307
extern DL_IMPORT (int ) PyObject_Print (PyObject * , FILE * , int );
@@ -283,6 +318,10 @@ extern DL_IMPORT(int) PyObject_HasAttrString(PyObject *, char *);
283
318
extern DL_IMPORT (PyObject * ) PyObject_GetAttr (PyObject * , PyObject * );
284
319
extern DL_IMPORT (int ) PyObject_SetAttr (PyObject * , PyObject * , PyObject * );
285
320
extern DL_IMPORT (int ) PyObject_HasAttr (PyObject * , PyObject * );
321
+ extern DL_IMPORT (PyObject * * ) _PyObject_GetDictPtr (PyObject * );
322
+ extern DL_IMPORT (PyObject * ) PyObject_GenericGetAttr (PyObject * , PyObject * );
323
+ extern DL_IMPORT (int ) PyObject_GenericSetAttr (PyObject * ,
324
+ PyObject * , PyObject * );
286
325
extern DL_IMPORT (long ) PyObject_Hash (PyObject * );
287
326
extern DL_IMPORT (int ) PyObject_IsTrue (PyObject * );
288
327
extern DL_IMPORT (int ) PyObject_Not (PyObject * );
@@ -357,13 +396,26 @@ given type object has a specified feature.
357
396
/* tp_iter is defined */
358
397
#define Py_TPFLAGS_HAVE_ITER (1L<<7)
359
398
399
+ /* Experimental stuff for healing the type/class split */
400
+ #define Py_TPFLAGS_HAVE_CLASS (1L<<8)
401
+
402
+ /* Set if the type object is dynamically allocated */
403
+ #define Py_TPFLAGS_HEAPTYPE (1L<<9)
404
+
405
+ /* Set if the type allows subclassing */
406
+ #define Py_TPFLAGS_BASETYPE (1L<<10)
407
+
408
+ /* Set if the type's __dict__ may change */
409
+ #define Py_TPFLAGS_DYNAMICTYPE (1L<<11)
410
+
360
411
#define Py_TPFLAGS_DEFAULT ( \
361
412
Py_TPFLAGS_HAVE_GETCHARBUFFER | \
362
413
Py_TPFLAGS_HAVE_SEQUENCE_IN | \
363
414
Py_TPFLAGS_HAVE_INPLACEOPS | \
364
415
Py_TPFLAGS_HAVE_RICHCOMPARE | \
365
416
Py_TPFLAGS_HAVE_WEAKREFS | \
366
417
Py_TPFLAGS_HAVE_ITER | \
418
+ Py_TPFLAGS_HAVE_CLASS | \
367
419
0)
368
420
369
421
#define PyType_HasFeature (t ,f ) (((t)->tp_flags & (f)) != 0)
@@ -412,8 +464,8 @@ extern DL_IMPORT(void) _Py_ResetReferences(void);
412
464
413
465
#ifndef Py_TRACE_REFS
414
466
#ifdef COUNT_ALLOCS
415
- #define _Py_Dealloc (op ) ((op)->ob_type->tp_free ++, (*(op)->ob_type->tp_dealloc)((PyObject *)(op)))
416
- #define _Py_ForgetReference (op ) ((op)->ob_type->tp_free ++)
467
+ #define _Py_Dealloc (op ) ((op)->ob_type->tp_frees ++, (*(op)->ob_type->tp_dealloc)((PyObject *)(op)))
468
+ #define _Py_ForgetReference (op ) ((op)->ob_type->tp_frees ++)
417
469
#else /* !COUNT_ALLOCS */
418
470
#define _Py_Dealloc (op ) (*(op)->ob_type->tp_dealloc)((PyObject *)(op))
419
471
#define _Py_ForgetReference (op ) /*empty*/
0 commit comments