diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-08-02 04:15:00 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-08-02 04:15:00 (GMT) |
commit | 6d6c1a35e08b95a83dbe47dbd9e6474daff00354 (patch) | |
tree | 542089077b9c2650dcf5c52d6bfcef1baf12d176 /Include | |
parent | 52d55a392600011d3edfe85c694744ec550ad1fe (diff) | |
download | cpython-6d6c1a35e08b95a83dbe47dbd9e6474daff00354.zip cpython-6d6c1a35e08b95a83dbe47dbd9e6474daff00354.tar.gz cpython-6d6c1a35e08b95a83dbe47dbd9e6474daff00354.tar.bz2 |
Merge of descr-branch back into trunk.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/Python.h | 1 | ||||
-rw-r--r-- | Include/abstract.h | 11 | ||||
-rw-r--r-- | Include/ceval.h | 3 | ||||
-rw-r--r-- | Include/classobject.h | 4 | ||||
-rw-r--r-- | Include/descrobject.h | 32 | ||||
-rw-r--r-- | Include/dictobject.h | 77 | ||||
-rw-r--r-- | Include/eval.h | 8 | ||||
-rw-r--r-- | Include/funcobject.h | 7 | ||||
-rw-r--r-- | Include/listobject.h | 2 | ||||
-rw-r--r-- | Include/modsupport.h | 6 | ||||
-rw-r--r-- | Include/object.h | 64 | ||||
-rw-r--r-- | Include/objimpl.h | 15 | ||||
-rw-r--r-- | Include/patchlevel.h | 6 | ||||
-rw-r--r-- | Include/pythonrun.h | 4 |
14 files changed, 220 insertions, 20 deletions
diff --git a/Include/Python.h b/Include/Python.h index f9c33d4..9757a70 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -89,6 +89,7 @@ #include "sliceobject.h" #include "cellobject.h" #include "iterobject.h" +#include "descrobject.h" #include "codecs.h" #include "pyerrors.h" diff --git a/Include/abstract.h b/Include/abstract.h index 9082edb..799438e 100644 --- a/Include/abstract.h +++ b/Include/abstract.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); diff --git a/Include/ceval.h b/Include/ceval.h index 0fc5cba..ae4d858 100644 --- a/Include/ceval.h +++ b/Include/ceval.h @@ -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 diff --git a/Include/classobject.h b/Include/classobject.h index 3b25c74..3bd535e 100644 --- a/Include/classobject.h +++ b/Include/classobject.h @@ -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) \ diff --git a/Include/descrobject.h b/Include/descrobject.h new file mode 100644 index 0000000..b6fc521 --- /dev/null +++ b/Include/descrobject.h @@ -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 *); diff --git a/Include/dictobject.h b/Include/dictobject.h index 4f5f94a..abc8ed5 100644 --- a/Include/dictobject.h +++ b/Include/dictobject.h @@ -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); diff --git a/Include/eval.h b/Include/eval.h index 2a45009..f9334a7 100644 --- a/Include/eval.h +++ b/Include/eval.h @@ -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 diff --git a/Include/funcobject.h b/Include/funcobject.h index 8cedeb7..6b1e389 100644 --- a/Include/funcobject.h +++ b/Include/funcobject.h @@ -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 diff --git a/Include/listobject.h b/Include/listobject.h index 73ac724..af1368c 100644 --- a/Include/listobject.h +++ b/Include/listobject.h @@ -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 *); diff --git a/Include/modsupport.h b/Include/modsupport.h index 4a40499..8ef343c 100644 --- a/Include/modsupport.h +++ b/Include/modsupport.h @@ -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 diff --git a/Include/object.h b/Include/object.h index 0765748..d81d4c2 100644 --- a/Include/object.h +++ b/Include/object.h @@ -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*/ diff --git a/Include/objimpl.h b/Include/objimpl.h index 4aa38d5..18cece8 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -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 */ diff --git a/Include/patchlevel.h b/Include/patchlevel.h index dddc28f..85ffacb 100644 --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -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 >= ... */ diff --git a/Include/pythonrun.h b/Include/pythonrun.h index 6e9821b..7d947df 100644 --- a/Include/pythonrun.h +++ b/Include/pythonrun.h @@ -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); |