mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Merge of descr-branch back into trunk.
This commit is contained in:
parent
52d55a3926
commit
6d6c1a35e0
57 changed files with 6923 additions and 1309 deletions
|
@ -89,6 +89,7 @@
|
|||
#include "sliceobject.h"
|
||||
#include "cellobject.h"
|
||||
#include "iterobject.h"
|
||||
#include "descrobject.h"
|
||||
|
||||
#include "codecs.h"
|
||||
#include "pyerrors.h"
|
||||
|
|
|
@ -294,6 +294,17 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
|||
*/
|
||||
|
||||
|
||||
|
||||
DL_IMPORT(PyObject *) PyObject_Call(PyObject *callable_object,
|
||||
PyObject *args, PyObject *kw);
|
||||
|
||||
/*
|
||||
|
||||
Call a callable Python object, callable_object, with
|
||||
arguments and keywords arguments. The 'args' argument can not be
|
||||
NULL, but the 'kw' argument can be NULL.
|
||||
|
||||
*/
|
||||
|
||||
DL_IMPORT(PyObject *) PyObject_CallObject(PyObject *callable_object,
|
||||
PyObject *args);
|
||||
|
|
|
@ -45,6 +45,9 @@ DL_IMPORT(int) Py_MakePendingCalls(void);
|
|||
DL_IMPORT(void) Py_SetRecursionLimit(int);
|
||||
DL_IMPORT(int) Py_GetRecursionLimit(void);
|
||||
|
||||
DL_IMPORT(char *) PyEval_GetFuncName(PyObject *);
|
||||
DL_IMPORT(char *) PyEval_GetFuncDesc(PyObject *);
|
||||
|
||||
/* Interface for threads.
|
||||
|
||||
A module that plans to do a blocking system call (or something else
|
||||
|
|
|
@ -47,10 +47,6 @@ extern DL_IMPORT(PyObject *) PyInstance_New(PyObject *, PyObject *,
|
|||
extern DL_IMPORT(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);
|
||||
extern DL_IMPORT(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
|
||||
|
||||
extern DL_IMPORT(PyObject *) PyMethod_Function(PyObject *);
|
||||
extern DL_IMPORT(PyObject *) PyMethod_Self(PyObject *);
|
||||
extern DL_IMPORT(PyObject *) PyMethod_Class(PyObject *);
|
||||
|
||||
/* Macros for direct access to these values. Type checks are *not*
|
||||
done, so use with care. */
|
||||
#define PyMethod_GET_FUNCTION(meth) \
|
||||
|
|
32
Include/descrobject.h
Normal file
32
Include/descrobject.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* XXX getter, setter, getsetlist and wrapperbase need 'Py'-prefixed names */
|
||||
|
||||
typedef PyObject *(*getter)(PyObject *, void *);
|
||||
typedef int (*setter)(PyObject *, PyObject *, void *);
|
||||
|
||||
struct getsetlist {
|
||||
char *name;
|
||||
getter get;
|
||||
setter set;
|
||||
void *closure;
|
||||
};
|
||||
|
||||
typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
|
||||
void *wrapped);
|
||||
|
||||
struct wrapperbase {
|
||||
char *name;
|
||||
wrapperfunc wrapper;
|
||||
char *doc;
|
||||
};
|
||||
|
||||
extern DL_IMPORT(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
|
||||
extern DL_IMPORT(PyObject *) PyDescr_NewMember(PyTypeObject *,
|
||||
struct memberlist *);
|
||||
extern DL_IMPORT(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
|
||||
struct getsetlist *);
|
||||
extern DL_IMPORT(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
|
||||
struct wrapperbase *, void *);
|
||||
extern DL_IMPORT(int) PyDescr_IsData(PyObject *);
|
||||
|
||||
extern DL_IMPORT(PyObject *) PyDictProxy_New(PyObject *);
|
||||
extern DL_IMPORT(PyObject *) PyWrapper_New(PyObject *, PyObject *);
|
|
@ -7,9 +7,83 @@ extern "C" {
|
|||
|
||||
/* Dictionary object type -- mapping from hashable object to object */
|
||||
|
||||
/*
|
||||
There are three kinds of slots in the table:
|
||||
|
||||
1. Unused. me_key == me_value == NULL
|
||||
Does not hold an active (key, value) pair now and never did. Unused can
|
||||
transition to Active upon key insertion. This is the only case in which
|
||||
me_key is NULL, and is each slot's initial state.
|
||||
|
||||
2. Active. me_key != NULL and me_key != dummy and me_value != NULL
|
||||
Holds an active (key, value) pair. Active can transition to Dummy upon
|
||||
key deletion. This is the only case in which me_value != NULL.
|
||||
|
||||
3. Dummy. me_key == dummy and me_value == NULL
|
||||
Previously held an active (key, value) pair, but that was deleted and an
|
||||
active pair has not yet overwritten the slot. Dummy can transition to
|
||||
Active upon key insertion. Dummy slots cannot be made Unused again
|
||||
(cannot have me_key set to NULL), else the probe sequence in case of
|
||||
collision would have no way to know they were once active.
|
||||
|
||||
Note: .popitem() abuses the me_hash field of an Unused or Dummy slot to
|
||||
hold a search finger. The me_hash field of Unused or Dummy slots has no
|
||||
meaning otherwise.
|
||||
*/
|
||||
|
||||
/* PyDict_MINSIZE is the minimum size of a dictionary. This many slots are
|
||||
* allocated directly in the dict object (in the ma_smalltable member).
|
||||
* It must be a power of 2, and at least 4. 8 allows dicts with no more
|
||||
* than 5 active entries to live in ma_smalltable (and so avoid an
|
||||
* additional malloc); instrumentation suggested this suffices for the
|
||||
* majority of dicts (consisting mostly of usually-small instance dicts and
|
||||
* usually-small dicts created to pass keyword arguments).
|
||||
*/
|
||||
#define PyDict_MINSIZE 8
|
||||
|
||||
typedef struct {
|
||||
long me_hash; /* cached hash code of me_key */
|
||||
PyObject *me_key;
|
||||
PyObject *me_value;
|
||||
#ifdef USE_CACHE_ALIGNED
|
||||
long aligner;
|
||||
#endif
|
||||
} PyDictEntry;
|
||||
|
||||
/*
|
||||
To ensure the lookup algorithm terminates, there must be at least one Unused
|
||||
slot (NULL key) in the table.
|
||||
The value ma_fill is the number of non-NULL keys (sum of Active and Dummy);
|
||||
ma_used is the number of non-NULL, non-dummy keys (== the number of non-NULL
|
||||
values == the number of Active items).
|
||||
To avoid slowing down lookups on a near-full table, we resize the table when
|
||||
it's two-thirds full.
|
||||
*/
|
||||
typedef struct _dictobject PyDictObject;
|
||||
struct _dictobject {
|
||||
PyObject_HEAD
|
||||
int ma_fill; /* # Active + # Dummy */
|
||||
int ma_used; /* # Active */
|
||||
|
||||
/* The table contains ma_mask + 1 slots, and that's a power of 2.
|
||||
* We store the mask instead of the size because the mask is more
|
||||
* frequently needed.
|
||||
*/
|
||||
int ma_mask;
|
||||
|
||||
/* ma_table points to ma_smalltable for small tables, else to
|
||||
* additional malloc'ed memory. ma_table is never NULL! This rule
|
||||
* saves repeated runtime null-tests in the workhorse getitem and
|
||||
* setitem calls.
|
||||
*/
|
||||
PyDictEntry *ma_table;
|
||||
PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash);
|
||||
PyDictEntry ma_smalltable[PyDict_MINSIZE];
|
||||
};
|
||||
|
||||
extern DL_IMPORT(PyTypeObject) PyDict_Type;
|
||||
|
||||
#define PyDict_Check(op) ((op)->ob_type == &PyDict_Type)
|
||||
#define PyDict_Check(op) PyObject_TypeCheck(op, &PyDict_Type)
|
||||
|
||||
extern DL_IMPORT(PyObject *) PyDict_New(void);
|
||||
extern DL_IMPORT(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
|
||||
|
@ -23,6 +97,7 @@ extern DL_IMPORT(PyObject *) PyDict_Values(PyObject *mp);
|
|||
extern DL_IMPORT(PyObject *) PyDict_Items(PyObject *mp);
|
||||
extern DL_IMPORT(int) PyDict_Size(PyObject *mp);
|
||||
extern DL_IMPORT(PyObject *) PyDict_Copy(PyObject *mp);
|
||||
extern DL_IMPORT(int) PyDict_Update(PyObject *mp, PyObject *other);
|
||||
|
||||
|
||||
extern DL_IMPORT(PyObject *) PyDict_GetItemString(PyObject *dp, char *key);
|
||||
|
|
|
@ -9,6 +9,14 @@ extern "C" {
|
|||
|
||||
DL_IMPORT(PyObject *) PyEval_EvalCode(PyCodeObject *, PyObject *, PyObject *);
|
||||
|
||||
DL_IMPORT(PyObject *) PyEval_EvalCodeEx(PyCodeObject *co,
|
||||
PyObject *globals,
|
||||
PyObject *locals,
|
||||
PyObject **args, int argc,
|
||||
PyObject **kwds, int kwdc,
|
||||
PyObject **defs, int defc,
|
||||
PyObject *closure);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -42,6 +42,13 @@ extern DL_IMPORT(int) PyFunction_SetClosure(PyObject *, PyObject *);
|
|||
#define PyFunction_GET_CLOSURE(func) \
|
||||
(((PyFunctionObject *)func) -> func_closure)
|
||||
|
||||
/* The classmethod and staticmethod types lives here, too */
|
||||
extern DL_IMPORT(PyTypeObject) PyClassMethod_Type;
|
||||
extern DL_IMPORT(PyTypeObject) PyStaticMethod_Type;
|
||||
|
||||
extern DL_IMPORT(PyObject *) PyClassMethod_New(PyObject *);
|
||||
extern DL_IMPORT(PyObject *) PyStaticMethod_New(PyObject *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -26,7 +26,7 @@ typedef struct {
|
|||
|
||||
extern DL_IMPORT(PyTypeObject) PyList_Type;
|
||||
|
||||
#define PyList_Check(op) ((op)->ob_type == &PyList_Type)
|
||||
#define PyList_Check(op) PyObject_TypeCheck(op, &PyList_Type)
|
||||
|
||||
extern DL_IMPORT(PyObject *) PyList_New(int size);
|
||||
extern DL_IMPORT(int) PyList_Size(PyObject *);
|
||||
|
|
|
@ -22,8 +22,8 @@ extern DL_IMPORT(int) PyModule_AddObject(PyObject *, char *, PyObject *);
|
|||
extern DL_IMPORT(int) PyModule_AddIntConstant(PyObject *, char *, long);
|
||||
extern DL_IMPORT(int) PyModule_AddStringConstant(PyObject *, char *, char *);
|
||||
|
||||
#define PYTHON_API_VERSION 1010
|
||||
#define PYTHON_API_STRING "1010"
|
||||
#define PYTHON_API_VERSION 1011
|
||||
#define PYTHON_API_STRING "1011"
|
||||
/* The API version is maintained (independently from the Python version)
|
||||
so we can detect mismatches between the interpreter and dynamically
|
||||
loaded modules. These are diagnosed by an error message but
|
||||
|
@ -37,6 +37,8 @@ extern DL_IMPORT(int) PyModule_AddStringConstant(PyObject *, char *, char *);
|
|||
Please add a line or two to the top of this log for each API
|
||||
version change:
|
||||
|
||||
17-Jul-2001 GvR 1011 Descr-branch, just to be on the safe side
|
||||
|
||||
25-Jan-2001 FLD 1010 Parameters added to PyCode_New() and
|
||||
PyFrame_New(); Python 2.1a2
|
||||
|
||||
|
|
|
@ -202,6 +202,11 @@ typedef long (*hashfunc)(PyObject *);
|
|||
typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
|
||||
typedef PyObject *(*getiterfunc) (PyObject *);
|
||||
typedef PyObject *(*iternextfunc) (PyObject *);
|
||||
typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);
|
||||
typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);
|
||||
typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
|
||||
typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
|
||||
typedef PyObject *(*allocfunc)(struct _typeobject *, int);
|
||||
|
||||
typedef struct _typeobject {
|
||||
PyObject_VAR_HEAD
|
||||
|
@ -255,18 +260,48 @@ typedef struct _typeobject {
|
|||
getiterfunc tp_iter;
|
||||
iternextfunc tp_iternext;
|
||||
|
||||
/* Attribute descriptor and subclassing stuff */
|
||||
struct PyMethodDef *tp_methods;
|
||||
struct memberlist *tp_members;
|
||||
struct getsetlist *tp_getset;
|
||||
struct _typeobject *tp_base;
|
||||
PyObject *tp_dict;
|
||||
descrgetfunc tp_descr_get;
|
||||
descrsetfunc tp_descr_set;
|
||||
long tp_dictoffset;
|
||||
initproc tp_init;
|
||||
allocfunc tp_alloc;
|
||||
newfunc tp_new;
|
||||
destructor tp_free; /* Low-level free-memory routine */
|
||||
PyObject *tp_bases;
|
||||
PyObject *tp_mro; /* method resolution order */
|
||||
PyObject *tp_defined;
|
||||
|
||||
#ifdef COUNT_ALLOCS
|
||||
/* these must be last and never explicitly initialized */
|
||||
int tp_alloc;
|
||||
int tp_free;
|
||||
int tp_allocs;
|
||||
int tp_frees;
|
||||
int tp_maxalloc;
|
||||
struct _typeobject *tp_next;
|
||||
#endif
|
||||
} PyTypeObject;
|
||||
|
||||
extern DL_IMPORT(PyTypeObject) PyType_Type; /* The type of type objects */
|
||||
|
||||
#define PyType_Check(op) ((op)->ob_type == &PyType_Type)
|
||||
/* Generic type check */
|
||||
extern DL_IMPORT(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
|
||||
#define PyObject_TypeCheck(ob, tp) \
|
||||
((ob)->ob_type == (tp) || PyType_IsSubtype((ob)->ob_type, (tp)))
|
||||
|
||||
extern DL_IMPORT(PyTypeObject) PyType_Type; /* Metatype */
|
||||
extern DL_IMPORT(PyTypeObject) PyBaseObject_Type; /* Most base object type */
|
||||
|
||||
#define PyType_Check(op) PyObject_TypeCheck(op, &PyType_Type)
|
||||
|
||||
extern DL_IMPORT(int) PyType_InitDict(PyTypeObject *);
|
||||
extern DL_IMPORT(PyObject *) PyType_GenericAlloc(PyTypeObject *, int);
|
||||
extern DL_IMPORT(PyObject *) PyType_GenericNew(PyTypeObject *,
|
||||
PyObject *, PyObject *);
|
||||
extern DL_IMPORT(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
|
||||
|
||||
/* Generic operations on objects */
|
||||
extern DL_IMPORT(int) PyObject_Print(PyObject *, FILE *, int);
|
||||
|
@ -283,6 +318,10 @@ extern DL_IMPORT(int) PyObject_HasAttrString(PyObject *, char *);
|
|||
extern DL_IMPORT(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
|
||||
extern DL_IMPORT(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
|
||||
extern DL_IMPORT(int) PyObject_HasAttr(PyObject *, PyObject *);
|
||||
extern DL_IMPORT(PyObject **) _PyObject_GetDictPtr(PyObject *);
|
||||
extern DL_IMPORT(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
|
||||
extern DL_IMPORT(int) PyObject_GenericSetAttr(PyObject *,
|
||||
PyObject *, PyObject *);
|
||||
extern DL_IMPORT(long) PyObject_Hash(PyObject *);
|
||||
extern DL_IMPORT(int) PyObject_IsTrue(PyObject *);
|
||||
extern DL_IMPORT(int) PyObject_Not(PyObject *);
|
||||
|
@ -357,6 +396,18 @@ given type object has a specified feature.
|
|||
/* tp_iter is defined */
|
||||
#define Py_TPFLAGS_HAVE_ITER (1L<<7)
|
||||
|
||||
/* Experimental stuff for healing the type/class split */
|
||||
#define Py_TPFLAGS_HAVE_CLASS (1L<<8)
|
||||
|
||||
/* Set if the type object is dynamically allocated */
|
||||
#define Py_TPFLAGS_HEAPTYPE (1L<<9)
|
||||
|
||||
/* Set if the type allows subclassing */
|
||||
#define Py_TPFLAGS_BASETYPE (1L<<10)
|
||||
|
||||
/* Set if the type's __dict__ may change */
|
||||
#define Py_TPFLAGS_DYNAMICTYPE (1L<<11)
|
||||
|
||||
#define Py_TPFLAGS_DEFAULT ( \
|
||||
Py_TPFLAGS_HAVE_GETCHARBUFFER | \
|
||||
Py_TPFLAGS_HAVE_SEQUENCE_IN | \
|
||||
|
@ -364,6 +415,7 @@ given type object has a specified feature.
|
|||
Py_TPFLAGS_HAVE_RICHCOMPARE | \
|
||||
Py_TPFLAGS_HAVE_WEAKREFS | \
|
||||
Py_TPFLAGS_HAVE_ITER | \
|
||||
Py_TPFLAGS_HAVE_CLASS | \
|
||||
0)
|
||||
|
||||
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
|
||||
|
@ -412,8 +464,8 @@ extern DL_IMPORT(void) _Py_ResetReferences(void);
|
|||
|
||||
#ifndef Py_TRACE_REFS
|
||||
#ifdef COUNT_ALLOCS
|
||||
#define _Py_Dealloc(op) ((op)->ob_type->tp_free++, (*(op)->ob_type->tp_dealloc)((PyObject *)(op)))
|
||||
#define _Py_ForgetReference(op) ((op)->ob_type->tp_free++)
|
||||
#define _Py_Dealloc(op) ((op)->ob_type->tp_frees++, (*(op)->ob_type->tp_dealloc)((PyObject *)(op)))
|
||||
#define _Py_ForgetReference(op) ((op)->ob_type->tp_frees++)
|
||||
#else /* !COUNT_ALLOCS */
|
||||
#define _Py_Dealloc(op) (*(op)->ob_type->tp_dealloc)((PyObject *)(op))
|
||||
#define _Py_ForgetReference(op) /*empty*/
|
||||
|
|
|
@ -236,7 +236,13 @@ extern DL_IMPORT(void) _PyObject_Del(PyObject *);
|
|||
#define PyObject_GC_Fini(op)
|
||||
#define PyObject_AS_GC(op) (op)
|
||||
#define PyObject_FROM_GC(op) (op)
|
||||
|
||||
#define PyType_IS_GC(t) 0
|
||||
#define PyObject_IS_GC(o) 0
|
||||
#define PyObject_AS_GC(o) (o)
|
||||
#define PyObject_FROM_GC(o) (o)
|
||||
#define PyType_BASICSIZE(t) ((t)->tp_basicsize)
|
||||
#define PyType_SET_BASICSIZE(t, s) ((t)->tp_basicsize = (s))
|
||||
|
||||
#else
|
||||
|
||||
/* Add the object into the container set */
|
||||
|
@ -269,6 +275,13 @@ typedef struct _gc_head {
|
|||
/* Get the object given the PyGC_Head */
|
||||
#define PyObject_FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1))
|
||||
|
||||
/* Calculate tp_basicsize excluding PyGC_HEAD_SIZE if applicable */
|
||||
#define PyType_BASICSIZE(t) (!PyType_IS_GC(t) ? (t)->tp_basicsize : \
|
||||
(t)->tp_basicsize - PyGC_HEAD_SIZE)
|
||||
#define PyType_SET_BASICSIZE(t, s) (!PyType_IS_GC(t) ? \
|
||||
((t)->tp_basicsize = (s)) : \
|
||||
((t)->tp_basicsize = (s) + PyGC_HEAD_SIZE))
|
||||
|
||||
extern DL_IMPORT(void) _PyGC_Dump(PyGC_Head *);
|
||||
|
||||
#endif /* WITH_CYCLE_GC */
|
||||
|
|
|
@ -23,13 +23,13 @@
|
|||
#define PY_MINOR_VERSION 2
|
||||
#define PY_MICRO_VERSION 0
|
||||
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_ALPHA
|
||||
#define PY_RELEASE_SERIAL 0
|
||||
#define PY_RELEASE_SERIAL 1
|
||||
|
||||
/* Version as a string */
|
||||
#define PY_VERSION "2.2a0"
|
||||
#define PY_VERSION "2.2a1"
|
||||
|
||||
/* Historic */
|
||||
#define PATCHLEVEL "2.2a0"
|
||||
#define PATCHLEVEL "2.2a1"
|
||||
|
||||
/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
|
||||
Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ... */
|
||||
|
|
|
@ -92,10 +92,10 @@ DL_IMPORT(const char *) Py_GetBuildInfo(void);
|
|||
DL_IMPORT(PyObject *) _PyBuiltin_Init(void);
|
||||
DL_IMPORT(PyObject *) _PySys_Init(void);
|
||||
DL_IMPORT(void) _PyImport_Init(void);
|
||||
DL_IMPORT(void) init_exceptions(void);
|
||||
DL_IMPORT(void) _PyExc_Init(void);
|
||||
|
||||
/* Various internal finalizers */
|
||||
DL_IMPORT(void) fini_exceptions(void);
|
||||
DL_IMPORT(void) _PyExc_Fini(void);
|
||||
DL_IMPORT(void) _PyImport_Fini(void);
|
||||
DL_IMPORT(void) PyMethod_Fini(void);
|
||||
DL_IMPORT(void) PyFrame_Fini(void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue