Skip to content

Commit 6d6c1a3

Browse files
committed
Merge of descr-branch back into trunk.
1 parent 52d55a3 commit 6d6c1a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+6926
-1312
lines changed

Include/Python.h

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
#include "sliceobject.h"
9090
#include "cellobject.h"
9191
#include "iterobject.h"
92+
#include "descrobject.h"
9293

9394
#include "codecs.h"
9495
#include "pyerrors.h"

Include/abstract.h

+11
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,17 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
294294
*/
295295

296296

297+
298+
DL_IMPORT(PyObject *) PyObject_Call(PyObject *callable_object,
299+
PyObject *args, PyObject *kw);
300+
301+
/*
302+
303+
Call a callable Python object, callable_object, with
304+
arguments and keywords arguments. The 'args' argument can not be
305+
NULL, but the 'kw' argument can be NULL.
306+
307+
*/
297308

298309
DL_IMPORT(PyObject *) PyObject_CallObject(PyObject *callable_object,
299310
PyObject *args);

Include/ceval.h

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ DL_IMPORT(int) Py_MakePendingCalls(void);
4545
DL_IMPORT(void) Py_SetRecursionLimit(int);
4646
DL_IMPORT(int) Py_GetRecursionLimit(void);
4747

48+
DL_IMPORT(char *) PyEval_GetFuncName(PyObject *);
49+
DL_IMPORT(char *) PyEval_GetFuncDesc(PyObject *);
50+
4851
/* Interface for threads.
4952
5053
A module that plans to do a blocking system call (or something else

Include/classobject.h

-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ extern DL_IMPORT(PyObject *) PyInstance_New(PyObject *, PyObject *,
4747
extern DL_IMPORT(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);
4848
extern DL_IMPORT(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
4949

50-
extern DL_IMPORT(PyObject *) PyMethod_Function(PyObject *);
51-
extern DL_IMPORT(PyObject *) PyMethod_Self(PyObject *);
52-
extern DL_IMPORT(PyObject *) PyMethod_Class(PyObject *);
53-
5450
/* Macros for direct access to these values. Type checks are *not*
5551
done, so use with care. */
5652
#define PyMethod_GET_FUNCTION(meth) \

Include/descrobject.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* XXX getter, setter, getsetlist and wrapperbase need 'Py'-prefixed names */
2+
3+
typedef PyObject *(*getter)(PyObject *, void *);
4+
typedef int (*setter)(PyObject *, PyObject *, void *);
5+
6+
struct getsetlist {
7+
char *name;
8+
getter get;
9+
setter set;
10+
void *closure;
11+
};
12+
13+
typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
14+
void *wrapped);
15+
16+
struct wrapperbase {
17+
char *name;
18+
wrapperfunc wrapper;
19+
char *doc;
20+
};
21+
22+
extern DL_IMPORT(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
23+
extern DL_IMPORT(PyObject *) PyDescr_NewMember(PyTypeObject *,
24+
struct memberlist *);
25+
extern DL_IMPORT(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
26+
struct getsetlist *);
27+
extern DL_IMPORT(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
28+
struct wrapperbase *, void *);
29+
extern DL_IMPORT(int) PyDescr_IsData(PyObject *);
30+
31+
extern DL_IMPORT(PyObject *) PyDictProxy_New(PyObject *);
32+
extern DL_IMPORT(PyObject *) PyWrapper_New(PyObject *, PyObject *);

Include/dictobject.h

+76-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,83 @@ extern "C" {
77

88
/* Dictionary object type -- mapping from hashable object to object */
99

10+
/*
11+
There are three kinds of slots in the table:
12+
13+
1. Unused. me_key == me_value == NULL
14+
Does not hold an active (key, value) pair now and never did. Unused can
15+
transition to Active upon key insertion. This is the only case in which
16+
me_key is NULL, and is each slot's initial state.
17+
18+
2. Active. me_key != NULL and me_key != dummy and me_value != NULL
19+
Holds an active (key, value) pair. Active can transition to Dummy upon
20+
key deletion. This is the only case in which me_value != NULL.
21+
22+
3. Dummy. me_key == dummy and me_value == NULL
23+
Previously held an active (key, value) pair, but that was deleted and an
24+
active pair has not yet overwritten the slot. Dummy can transition to
25+
Active upon key insertion. Dummy slots cannot be made Unused again
26+
(cannot have me_key set to NULL), else the probe sequence in case of
27+
collision would have no way to know they were once active.
28+
29+
Note: .popitem() abuses the me_hash field of an Unused or Dummy slot to
30+
hold a search finger. The me_hash field of Unused or Dummy slots has no
31+
meaning otherwise.
32+
*/
33+
34+
/* PyDict_MINSIZE is the minimum size of a dictionary. This many slots are
35+
* allocated directly in the dict object (in the ma_smalltable member).
36+
* It must be a power of 2, and at least 4. 8 allows dicts with no more
37+
* than 5 active entries to live in ma_smalltable (and so avoid an
38+
* additional malloc); instrumentation suggested this suffices for the
39+
* majority of dicts (consisting mostly of usually-small instance dicts and
40+
* usually-small dicts created to pass keyword arguments).
41+
*/
42+
#define PyDict_MINSIZE 8
43+
44+
typedef struct {
45+
long me_hash; /* cached hash code of me_key */
46+
PyObject *me_key;
47+
PyObject *me_value;
48+
#ifdef USE_CACHE_ALIGNED
49+
long aligner;
50+
#endif
51+
} PyDictEntry;
52+
53+
/*
54+
To ensure the lookup algorithm terminates, there must be at least one Unused
55+
slot (NULL key) in the table.
56+
The value ma_fill is the number of non-NULL keys (sum of Active and Dummy);
57+
ma_used is the number of non-NULL, non-dummy keys (== the number of non-NULL
58+
values == the number of Active items).
59+
To avoid slowing down lookups on a near-full table, we resize the table when
60+
it's two-thirds full.
61+
*/
62+
typedef struct _dictobject PyDictObject;
63+
struct _dictobject {
64+
PyObject_HEAD
65+
int ma_fill; /* # Active + # Dummy */
66+
int ma_used; /* # Active */
67+
68+
/* The table contains ma_mask + 1 slots, and that's a power of 2.
69+
* We store the mask instead of the size because the mask is more
70+
* frequently needed.
71+
*/
72+
int ma_mask;
73+
74+
/* ma_table points to ma_smalltable for small tables, else to
75+
* additional malloc'ed memory. ma_table is never NULL! This rule
76+
* saves repeated runtime null-tests in the workhorse getitem and
77+
* setitem calls.
78+
*/
79+
PyDictEntry *ma_table;
80+
PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash);
81+
PyDictEntry ma_smalltable[PyDict_MINSIZE];
82+
};
83+
1084
extern DL_IMPORT(PyTypeObject) PyDict_Type;
1185

12-
#define PyDict_Check(op) ((op)->ob_type == &PyDict_Type)
86+
#define PyDict_Check(op) PyObject_TypeCheck(op, &PyDict_Type)
1387

1488
extern DL_IMPORT(PyObject *) PyDict_New(void);
1589
extern DL_IMPORT(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
@@ -23,6 +97,7 @@ extern DL_IMPORT(PyObject *) PyDict_Values(PyObject *mp);
2397
extern DL_IMPORT(PyObject *) PyDict_Items(PyObject *mp);
2498
extern DL_IMPORT(int) PyDict_Size(PyObject *mp);
2599
extern DL_IMPORT(PyObject *) PyDict_Copy(PyObject *mp);
100+
extern DL_IMPORT(int) PyDict_Update(PyObject *mp, PyObject *other);
26101

27102

28103
extern DL_IMPORT(PyObject *) PyDict_GetItemString(PyObject *dp, char *key);

Include/eval.h

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ extern "C" {
99

1010
DL_IMPORT(PyObject *) PyEval_EvalCode(PyCodeObject *, PyObject *, PyObject *);
1111

12+
DL_IMPORT(PyObject *) PyEval_EvalCodeEx(PyCodeObject *co,
13+
PyObject *globals,
14+
PyObject *locals,
15+
PyObject **args, int argc,
16+
PyObject **kwds, int kwdc,
17+
PyObject **defs, int defc,
18+
PyObject *closure);
19+
1220
#ifdef __cplusplus
1321
}
1422
#endif

Include/funcobject.h

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ extern DL_IMPORT(int) PyFunction_SetClosure(PyObject *, PyObject *);
4242
#define PyFunction_GET_CLOSURE(func) \
4343
(((PyFunctionObject *)func) -> func_closure)
4444

45+
/* The classmethod and staticmethod types lives here, too */
46+
extern DL_IMPORT(PyTypeObject) PyClassMethod_Type;
47+
extern DL_IMPORT(PyTypeObject) PyStaticMethod_Type;
48+
49+
extern DL_IMPORT(PyObject *) PyClassMethod_New(PyObject *);
50+
extern DL_IMPORT(PyObject *) PyStaticMethod_New(PyObject *);
51+
4552
#ifdef __cplusplus
4653
}
4754
#endif

Include/listobject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef struct {
2626

2727
extern DL_IMPORT(PyTypeObject) PyList_Type;
2828

29-
#define PyList_Check(op) ((op)->ob_type == &PyList_Type)
29+
#define PyList_Check(op) PyObject_TypeCheck(op, &PyList_Type)
3030

3131
extern DL_IMPORT(PyObject *) PyList_New(int size);
3232
extern DL_IMPORT(int) PyList_Size(PyObject *);

Include/modsupport.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ extern DL_IMPORT(int) PyModule_AddObject(PyObject *, char *, PyObject *);
2222
extern DL_IMPORT(int) PyModule_AddIntConstant(PyObject *, char *, long);
2323
extern DL_IMPORT(int) PyModule_AddStringConstant(PyObject *, char *, char *);
2424

25-
#define PYTHON_API_VERSION 1010
26-
#define PYTHON_API_STRING "1010"
25+
#define PYTHON_API_VERSION 1011
26+
#define PYTHON_API_STRING "1011"
2727
/* The API version is maintained (independently from the Python version)
2828
so we can detect mismatches between the interpreter and dynamically
2929
loaded modules. These are diagnosed by an error message but
@@ -37,6 +37,8 @@ extern DL_IMPORT(int) PyModule_AddStringConstant(PyObject *, char *, char *);
3737
Please add a line or two to the top of this log for each API
3838
version change:
3939
40+
17-Jul-2001 GvR 1011 Descr-branch, just to be on the safe side
41+
4042
25-Jan-2001 FLD 1010 Parameters added to PyCode_New() and
4143
PyFrame_New(); Python 2.1a2
4244

Include/object.h

+58-6
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ typedef long (*hashfunc)(PyObject *);
202202
typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
203203
typedef PyObject *(*getiterfunc) (PyObject *);
204204
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);
205210

206211
typedef struct _typeobject {
207212
PyObject_VAR_HEAD
@@ -255,18 +260,48 @@ typedef struct _typeobject {
255260
getiterfunc tp_iter;
256261
iternextfunc tp_iternext;
257262

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+
258280
#ifdef COUNT_ALLOCS
259281
/* these must be last and never explicitly initialized */
260-
int tp_alloc;
261-
int tp_free;
282+
int tp_allocs;
283+
int tp_frees;
262284
int tp_maxalloc;
263285
struct _typeobject *tp_next;
264286
#endif
265287
} PyTypeObject;
266288

267-
extern DL_IMPORT(PyTypeObject) PyType_Type; /* The type of type objects */
268289

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 *);
270305

271306
/* Generic operations on objects */
272307
extern DL_IMPORT(int) PyObject_Print(PyObject *, FILE *, int);
@@ -283,6 +318,10 @@ extern DL_IMPORT(int) PyObject_HasAttrString(PyObject *, char *);
283318
extern DL_IMPORT(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
284319
extern DL_IMPORT(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
285320
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 *);
286325
extern DL_IMPORT(long) PyObject_Hash(PyObject *);
287326
extern DL_IMPORT(int) PyObject_IsTrue(PyObject *);
288327
extern DL_IMPORT(int) PyObject_Not(PyObject *);
@@ -357,13 +396,26 @@ given type object has a specified feature.
357396
/* tp_iter is defined */
358397
#define Py_TPFLAGS_HAVE_ITER (1L<<7)
359398

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+
360411
#define Py_TPFLAGS_DEFAULT ( \
361412
Py_TPFLAGS_HAVE_GETCHARBUFFER | \
362413
Py_TPFLAGS_HAVE_SEQUENCE_IN | \
363414
Py_TPFLAGS_HAVE_INPLACEOPS | \
364415
Py_TPFLAGS_HAVE_RICHCOMPARE | \
365416
Py_TPFLAGS_HAVE_WEAKREFS | \
366417
Py_TPFLAGS_HAVE_ITER | \
418+
Py_TPFLAGS_HAVE_CLASS | \
367419
0)
368420

369421
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
@@ -412,8 +464,8 @@ extern DL_IMPORT(void) _Py_ResetReferences(void);
412464

413465
#ifndef Py_TRACE_REFS
414466
#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++)
417469
#else /* !COUNT_ALLOCS */
418470
#define _Py_Dealloc(op) (*(op)->ob_type->tp_dealloc)((PyObject *)(op))
419471
#define _Py_ForgetReference(op) /*empty*/

Include/objimpl.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,13 @@ extern DL_IMPORT(void) _PyObject_Del(PyObject *);
236236
#define PyObject_GC_Fini(op)
237237
#define PyObject_AS_GC(op) (op)
238238
#define PyObject_FROM_GC(op) (op)
239-
239+
#define PyType_IS_GC(t) 0
240+
#define PyObject_IS_GC(o) 0
241+
#define PyObject_AS_GC(o) (o)
242+
#define PyObject_FROM_GC(o) (o)
243+
#define PyType_BASICSIZE(t) ((t)->tp_basicsize)
244+
#define PyType_SET_BASICSIZE(t, s) ((t)->tp_basicsize = (s))
245+
240246
#else
241247

242248
/* Add the object into the container set */
@@ -269,6 +275,13 @@ typedef struct _gc_head {
269275
/* Get the object given the PyGC_Head */
270276
#define PyObject_FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1))
271277

278+
/* Calculate tp_basicsize excluding PyGC_HEAD_SIZE if applicable */
279+
#define PyType_BASICSIZE(t) (!PyType_IS_GC(t) ? (t)->tp_basicsize : \
280+
(t)->tp_basicsize - PyGC_HEAD_SIZE)
281+
#define PyType_SET_BASICSIZE(t, s) (!PyType_IS_GC(t) ? \
282+
((t)->tp_basicsize = (s)) : \
283+
((t)->tp_basicsize = (s) + PyGC_HEAD_SIZE))
284+
272285
extern DL_IMPORT(void) _PyGC_Dump(PyGC_Head *);
273286

274287
#endif /* WITH_CYCLE_GC */

Include/patchlevel.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
#define PY_MINOR_VERSION 2
2424
#define PY_MICRO_VERSION 0
2525
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_ALPHA
26-
#define PY_RELEASE_SERIAL 0
26+
#define PY_RELEASE_SERIAL 1
2727

2828
/* Version as a string */
29-
#define PY_VERSION "2.2a0"
29+
#define PY_VERSION "2.2a1"
3030

3131
/* Historic */
32-
#define PATCHLEVEL "2.2a0"
32+
#define PATCHLEVEL "2.2a1"
3333

3434
/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
3535
Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ... */

0 commit comments

Comments
 (0)