mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
Merged revisions 56467-56482 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
r56477 | martin.v.loewis | 2007-07-21 09:04:38 +0200 (Sa, 21 Jul 2007) | 11 lines
Merged revisions 56466-56476 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r56476 | martin.v.loewis | 2007-07-21 08:55:02 +0200 (Sa, 21 Jul 2007) | 4 lines
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and
PyVarObject_HEAD_INIT.
........
................
r56478 | martin.v.loewis | 2007-07-21 09:47:23 +0200 (Sa, 21 Jul 2007) | 2 lines
PEP 3123: Use proper C inheritance for PyObject.
................
r56479 | martin.v.loewis | 2007-07-21 10:06:55 +0200 (Sa, 21 Jul 2007) | 3 lines
Add longintrepr.h to Python.h, so that the compiler can
see that PyFalse is really some kind of PyObject*.
................
r56480 | martin.v.loewis | 2007-07-21 10:47:18 +0200 (Sa, 21 Jul 2007) | 2 lines
Qualify SHIFT, MASK, BASE.
................
r56482 | martin.v.loewis | 2007-07-21 19:10:57 +0200 (Sa, 21 Jul 2007) | 2 lines
Correctly refer to _ob_next.
................
This commit is contained in:
parent
b972a78e17
commit
9f2e346911
134 changed files with 1388 additions and 1577 deletions
|
|
@ -75,14 +75,14 @@ whose size is determined when the object is allocated.
|
|||
#endif
|
||||
|
||||
/* PyObject_HEAD defines the initial segment of every PyObject. */
|
||||
#define PyObject_HEAD \
|
||||
_PyObject_HEAD_EXTRA \
|
||||
Py_ssize_t ob_refcnt; \
|
||||
struct _typeobject *ob_type;
|
||||
#define PyObject_HEAD PyObject ob_base;
|
||||
|
||||
#define PyObject_HEAD_INIT(type) \
|
||||
_PyObject_EXTRA_INIT \
|
||||
1, type,
|
||||
{ _PyObject_EXTRA_INIT \
|
||||
1, type },
|
||||
|
||||
#define PyVarObject_HEAD_INIT(type, size) \
|
||||
{ PyObject_HEAD_INIT(type) size },
|
||||
|
||||
/* PyObject_VAR_HEAD defines the initial segment of all variable-size
|
||||
* container objects. These end with a declaration of an array with 1
|
||||
|
|
@ -90,9 +90,7 @@ whose size is determined when the object is allocated.
|
|||
* has room for ob_size elements. Note that ob_size is an element count,
|
||||
* not necessarily a byte count.
|
||||
*/
|
||||
#define PyObject_VAR_HEAD \
|
||||
PyObject_HEAD \
|
||||
Py_ssize_t ob_size; /* Number of items in variable part */
|
||||
#define PyObject_VAR_HEAD PyVarObject ob_base;
|
||||
#define Py_INVALID_SIZE (Py_ssize_t)-1
|
||||
|
||||
/* Nothing is actually declared to be a PyObject, but every pointer to
|
||||
|
|
@ -101,13 +99,19 @@ whose size is determined when the object is allocated.
|
|||
* in addition, be cast to PyVarObject*.
|
||||
*/
|
||||
typedef struct _object {
|
||||
PyObject_HEAD
|
||||
_PyObject_HEAD_EXTRA
|
||||
Py_ssize_t ob_refcnt;
|
||||
struct _typeobject *ob_type;
|
||||
} PyObject;
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD
|
||||
PyObject ob_base;
|
||||
Py_ssize_t ob_size; /* Number of items in variable part */
|
||||
} PyVarObject;
|
||||
|
||||
#define Py_Refcnt(ob) (((PyObject*)(ob))->ob_refcnt)
|
||||
#define Py_Type(ob) (((PyObject*)(ob))->ob_type)
|
||||
#define Py_Size(ob) (((PyVarObject*)(ob))->ob_size)
|
||||
|
||||
/*
|
||||
Type objects contain a string containing the type name (to help somewhat
|
||||
|
|
@ -346,21 +350,21 @@ typedef struct _heaptypeobject {
|
|||
|
||||
/* access macro to the members which are floating "behind" the object */
|
||||
#define PyHeapType_GET_MEMBERS(etype) \
|
||||
((PyMemberDef *)(((char *)etype) + (etype)->ht_type.ob_type->tp_basicsize))
|
||||
((PyMemberDef *)(((char *)etype) + Py_Type(etype)->tp_basicsize))
|
||||
|
||||
|
||||
/* Generic type check */
|
||||
PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
|
||||
#define PyObject_TypeCheck(ob, tp) \
|
||||
((ob)->ob_type == (tp) || PyType_IsSubtype((ob)->ob_type, (tp)))
|
||||
(Py_Type(ob) == (tp) || PyType_IsSubtype(Py_Type(ob), (tp)))
|
||||
|
||||
PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
|
||||
PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
|
||||
PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
|
||||
|
||||
#define PyType_Check(op) \
|
||||
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_TYPE_SUBCLASS)
|
||||
#define PyType_CheckExact(op) ((op)->ob_type == &PyType_Type)
|
||||
PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_TYPE_SUBCLASS)
|
||||
#define PyType_CheckExact(op) (Py_Type(op) == &PyType_Type)
|
||||
|
||||
PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
|
||||
PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
|
||||
|
|
@ -543,7 +547,7 @@ PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
|
|||
#define _Py_DEC_REFTOTAL _Py_RefTotal--
|
||||
#define _Py_REF_DEBUG_COMMA ,
|
||||
#define _Py_CHECK_REFCNT(OP) \
|
||||
{ if ((OP)->ob_refcnt < 0) \
|
||||
{ if (((PyObject*)OP)->ob_refcnt < 0) \
|
||||
_Py_NegativeRefcount(__FILE__, __LINE__, \
|
||||
(PyObject *)(OP)); \
|
||||
}
|
||||
|
|
@ -557,9 +561,9 @@ PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
|
|||
#ifdef COUNT_ALLOCS
|
||||
PyAPI_FUNC(void) inc_count(PyTypeObject *);
|
||||
PyAPI_FUNC(void) dec_count(PyTypeObject *);
|
||||
#define _Py_INC_TPALLOCS(OP) inc_count((OP)->ob_type)
|
||||
#define _Py_INC_TPFREES(OP) dec_count((OP)->ob_type)
|
||||
#define _Py_DEC_TPFREES(OP) (OP)->ob_type->tp_frees--
|
||||
#define _Py_INC_TPALLOCS(OP) inc_count(Py_Type(OP))
|
||||
#define _Py_INC_TPFREES(OP) dec_count(Py_Type(OP))
|
||||
#define _Py_DEC_TPFREES(OP) Py_Type(OP)->tp_frees--
|
||||
#define _Py_COUNT_ALLOCS_COMMA ,
|
||||
#else
|
||||
#define _Py_INC_TPALLOCS(OP)
|
||||
|
|
@ -584,22 +588,22 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
|
|||
#define _Py_NewReference(op) ( \
|
||||
_Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA \
|
||||
_Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
|
||||
(op)->ob_refcnt = 1)
|
||||
Py_Refcnt(op) = 1)
|
||||
|
||||
#define _Py_ForgetReference(op) _Py_INC_TPFREES(op)
|
||||
|
||||
#define _Py_Dealloc(op) ( \
|
||||
_Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \
|
||||
(*(op)->ob_type->tp_dealloc)((PyObject *)(op)))
|
||||
(*Py_Type(op)->tp_dealloc)((PyObject *)(op)))
|
||||
#endif /* !Py_TRACE_REFS */
|
||||
|
||||
#define Py_INCREF(op) ( \
|
||||
_Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
|
||||
(op)->ob_refcnt++)
|
||||
((PyObject*)(op))->ob_refcnt++)
|
||||
|
||||
#define Py_DECREF(op) \
|
||||
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
|
||||
--(op)->ob_refcnt != 0) \
|
||||
--((PyObject*)(op))->ob_refcnt != 0) \
|
||||
_Py_CHECK_REFCNT(op) \
|
||||
else \
|
||||
_Py_Dealloc((PyObject *)(op))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue