1993-07-28 06:05:47 -03:00
|
|
|
#ifndef Py_OBJECT_H
|
|
|
|
#define Py_OBJECT_H
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
1991-02-19 08:39:46 -04:00
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/* Object and type object interface */
|
|
|
|
|
|
|
|
/*
|
|
|
|
Objects are structures allocated on the heap. Special rules apply to
|
|
|
|
the use of objects to ensure they are properly garbage-collected.
|
|
|
|
Objects are never allocated statically or on the stack; they must be
|
|
|
|
accessed through special macros and functions only. (Type objects are
|
|
|
|
exceptions to the first rule; the standard types are represented by
|
2002-07-07 16:59:50 -03:00
|
|
|
statically initialized type objects, although work on type/class unification
|
|
|
|
for Python 2.2 made it possible to have heap-allocated type objects too).
|
1990-10-14 09:07:46 -03:00
|
|
|
|
|
|
|
An object has a 'reference count' that is increased or decreased when a
|
|
|
|
pointer to the object is copied or deleted; when the reference count
|
|
|
|
reaches zero there are no references to the object left and it can be
|
|
|
|
removed from the heap.
|
|
|
|
|
|
|
|
An object has a 'type' that determines what it represents and what kind
|
|
|
|
of data it contains. An object's type is fixed when it is created.
|
|
|
|
Types themselves are represented as objects; an object contains a
|
|
|
|
pointer to the corresponding type object. The type itself has a type
|
|
|
|
pointer pointing to the object representing the type 'type', which
|
|
|
|
contains a pointer to itself!).
|
|
|
|
|
|
|
|
Objects do not float around in memory; once allocated an object keeps
|
|
|
|
the same size and address. Objects that must hold variable-size data
|
|
|
|
can contain pointers to variable-size parts of the object. Not all
|
|
|
|
objects of the same type have the same size; but the size cannot change
|
|
|
|
after allocation. (These restrictions are made so a reference to an
|
|
|
|
object can be simply a pointer -- moving an object would require
|
|
|
|
updating all the pointers, and changing an object's size would require
|
|
|
|
moving it if there was another object right next to it.)
|
|
|
|
|
1995-01-12 07:45:45 -04:00
|
|
|
Objects are always accessed through pointers of the type 'PyObject *'.
|
|
|
|
The type 'PyObject' is a structure that only contains the reference count
|
1990-10-14 09:07:46 -03:00
|
|
|
and the type pointer. The actual memory allocated for an object
|
|
|
|
contains other data that can only be accessed after casting the pointer
|
|
|
|
to a pointer to a longer structure type. This longer type must start
|
1995-01-12 07:45:45 -04:00
|
|
|
with the reference count and type fields; the macro PyObject_HEAD should be
|
2000-07-16 09:04:32 -03:00
|
|
|
used for this (to accommodate for future changes). The implementation
|
1990-10-14 09:07:46 -03:00
|
|
|
of a particular object type can cast the object pointer to the proper
|
|
|
|
type and back.
|
|
|
|
|
|
|
|
A standard interface exists for objects that contain an array of items
|
|
|
|
whose size is determined when the object is allocated.
|
|
|
|
*/
|
|
|
|
|
object.h special-build macro minefield: renamed all the new lexical
helper macros to something saner, and used them appropriately in other
files too, to reduce #ifdef blocks.
classobject.c, instance_dealloc(): One of my worst Python Memories is
trying to fix this routine a few years ago when COUNT_ALLOCS was defined
but Py_TRACE_REFS wasn't. The special-build code here is way too
complicated. Now it's much simpler. Difference: in a Py_TRACE_REFS
build, the instance is no longer in the doubly-linked list of live
objects while its __del__ method is executing, and that may be visible
via sys.getobjects() called from a __del__ method. Tough -- the object
is presumed dead while its __del__ is executing anyway, and not calling
_Py_NewReference() at the start allows enormous code simplification.
typeobject.c, call_finalizer(): The special-build instance_dealloc()
pain apparently spread to here too via cut-'n-paste, and this is much
simpler now too. In addition, I didn't understand why this routine
was calling _PyObject_GC_TRACK() after a resurrection, since there's no
plausible way _PyObject_GC_UNTRACK() could have been called on the
object by this point. I suspect it was left over from pasting the
instance_delloc() code. Instead asserted that the object is still
tracked. Caution: I suspect we don't have a test that actually
exercises the subtype_dealloc() __del__-resurrected-me code.
2002-07-11 03:23:50 -03:00
|
|
|
/* Py_DEBUG implies Py_TRACE_REFS. */
|
|
|
|
#if defined(Py_DEBUG) && !defined(Py_TRACE_REFS)
|
1995-01-12 07:45:45 -04:00
|
|
|
#define Py_TRACE_REFS
|
object.h special-build macro minefield: renamed all the new lexical
helper macros to something saner, and used them appropriately in other
files too, to reduce #ifdef blocks.
classobject.c, instance_dealloc(): One of my worst Python Memories is
trying to fix this routine a few years ago when COUNT_ALLOCS was defined
but Py_TRACE_REFS wasn't. The special-build code here is way too
complicated. Now it's much simpler. Difference: in a Py_TRACE_REFS
build, the instance is no longer in the doubly-linked list of live
objects while its __del__ method is executing, and that may be visible
via sys.getobjects() called from a __del__ method. Tough -- the object
is presumed dead while its __del__ is executing anyway, and not calling
_Py_NewReference() at the start allows enormous code simplification.
typeobject.c, call_finalizer(): The special-build instance_dealloc()
pain apparently spread to here too via cut-'n-paste, and this is much
simpler now too. In addition, I didn't understand why this routine
was calling _PyObject_GC_TRACK() after a resurrection, since there's no
plausible way _PyObject_GC_UNTRACK() could have been called on the
object by this point. I suspect it was left over from pasting the
instance_delloc() code. Instead asserted that the object is still
tracked. Caution: I suspect we don't have a test that actually
exercises the subtype_dealloc() __del__-resurrected-me code.
2002-07-11 03:23:50 -03:00
|
|
|
#endif
|
1990-12-20 11:06:42 -04:00
|
|
|
|
2002-07-07 16:59:50 -03:00
|
|
|
/* Py_TRACE_REFS implies Py_REF_DEBUG. */
|
|
|
|
#if defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)
|
1995-01-12 07:45:45 -04:00
|
|
|
#define Py_REF_DEBUG
|
2002-07-07 16:59:50 -03:00
|
|
|
#endif
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2010-12-03 16:14:31 -04:00
|
|
|
#if defined(Py_LIMITED_API) && defined(Py_REF_DEBUG)
|
|
|
|
#error Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, and Py_REF_DEBUG
|
|
|
|
#endif
|
|
|
|
|
1995-01-12 07:45:45 -04:00
|
|
|
#ifdef Py_TRACE_REFS
|
2002-07-07 16:59:50 -03:00
|
|
|
/* Define pointers to support a doubly-linked list of all live heap objects. */
|
2010-05-09 12:52:27 -03:00
|
|
|
#define _PyObject_HEAD_EXTRA \
|
|
|
|
struct _object *_ob_next; \
|
|
|
|
struct _object *_ob_prev;
|
2002-07-07 16:59:50 -03:00
|
|
|
|
|
|
|
#define _PyObject_EXTRA_INIT 0, 0,
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define _PyObject_HEAD_EXTRA
|
|
|
|
#define _PyObject_EXTRA_INIT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* PyObject_HEAD defines the initial segment of every PyObject. */
|
2010-05-09 12:52:27 -03:00
|
|
|
#define PyObject_HEAD PyObject ob_base;
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
#define PyObject_HEAD_INIT(type) \
|
|
|
|
{ _PyObject_EXTRA_INIT \
|
|
|
|
1, type },
|
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.
................
2007-07-21 14:22:18 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
#define PyVarObject_HEAD_INIT(type, size) \
|
|
|
|
{ PyObject_HEAD_INIT(type) size },
|
2002-07-07 16:59:50 -03:00
|
|
|
|
|
|
|
/* PyObject_VAR_HEAD defines the initial segment of all variable-size
|
|
|
|
* container objects. These end with a declaration of an array with 1
|
|
|
|
* element, but enough space is malloc'ed so that the array actually
|
|
|
|
* has room for ob_size elements. Note that ob_size is an element count,
|
|
|
|
* not necessarily a byte count.
|
|
|
|
*/
|
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.
................
2007-07-21 14:22:18 -03:00
|
|
|
#define PyObject_VAR_HEAD PyVarObject ob_base;
|
2006-02-15 13:27:45 -04:00
|
|
|
#define Py_INVALID_SIZE (Py_ssize_t)-1
|
2002-07-07 02:13:56 -03:00
|
|
|
|
2002-07-07 16:59:50 -03:00
|
|
|
/* Nothing is actually declared to be a PyObject, but every pointer to
|
|
|
|
* a Python object can be cast to a PyObject*. This is inheritance built
|
|
|
|
* by hand. Similarly every pointer to a variable-size Python object can,
|
|
|
|
* in addition, be cast to PyVarObject*.
|
|
|
|
*/
|
1990-10-14 09:07:46 -03:00
|
|
|
typedef struct _object {
|
2010-05-09 12:52:27 -03:00
|
|
|
_PyObject_HEAD_EXTRA
|
|
|
|
Py_ssize_t ob_refcnt;
|
|
|
|
struct _typeobject *ob_type;
|
1995-01-12 07:45:45 -04:00
|
|
|
} PyObject;
|
1990-10-14 09:07:46 -03:00
|
|
|
|
|
|
|
typedef struct {
|
2010-05-09 12:52:27 -03:00
|
|
|
PyObject ob_base;
|
|
|
|
Py_ssize_t ob_size; /* Number of items in variable part */
|
1997-05-15 18:31:03 -03:00
|
|
|
} PyVarObject;
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
|
|
|
|
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
|
|
|
|
#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2012-01-22 12:24:29 -04:00
|
|
|
/********************* String Literals ****************************************/
|
|
|
|
/* This structure helps managing static strings. The basic usage goes like this:
|
|
|
|
Instead of doing
|
|
|
|
|
|
|
|
r = PyObject_CallMethod(o, "foo", "args", ...);
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
|
|
_Py_IDENTIFIER(foo);
|
|
|
|
...
|
|
|
|
r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...);
|
|
|
|
|
|
|
|
PyId_foo is a static variable, either on block level or file level. On first
|
|
|
|
usage, the string "foo" is interned, and the structures are linked. On interpreter
|
|
|
|
shutdown, all strings are released (through _PyUnicode_ClearStaticStrings).
|
|
|
|
|
|
|
|
Alternatively, _Py_static_string allows to choose the variable name.
|
|
|
|
_PyUnicode_FromId returns a borrowed reference to the interned string.
|
|
|
|
_PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*.
|
|
|
|
*/
|
|
|
|
typedef struct _Py_Identifier {
|
|
|
|
struct _Py_Identifier *next;
|
|
|
|
const char* string;
|
|
|
|
PyObject *object;
|
|
|
|
} _Py_Identifier;
|
|
|
|
|
2013-11-06 17:41:44 -04:00
|
|
|
#define _Py_static_string_init(value) { 0, value, 0 }
|
|
|
|
#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value)
|
2012-01-22 12:24:29 -04:00
|
|
|
#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
|
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/*
|
|
|
|
Type objects contain a string containing the type name (to help somewhat
|
2002-07-07 16:59:50 -03:00
|
|
|
in debugging), the allocation parameters (see PyObject_New() and
|
|
|
|
PyObject_NewVar()),
|
|
|
|
and methods for accessing objects of the type. Methods are optional, a
|
1990-10-14 09:07:46 -03:00
|
|
|
nil pointer meaning that particular kind of access is not available for
|
1995-01-12 07:45:45 -04:00
|
|
|
this type. The Py_DECREF() macro uses the tp_dealloc method without
|
1990-10-14 09:07:46 -03:00
|
|
|
checking for a nil pointer; it should always be implemented except if
|
|
|
|
the implementation can guarantee that the reference count will never
|
2002-07-07 16:59:50 -03:00
|
|
|
reach zero (e.g., for statically allocated type objects).
|
1990-10-14 09:07:46 -03:00
|
|
|
|
|
|
|
NB: the methods for certain type groups are now contained in separate
|
|
|
|
method blocks.
|
|
|
|
*/
|
|
|
|
|
2000-07-07 21:32:04 -03:00
|
|
|
typedef PyObject * (*unaryfunc)(PyObject *);
|
|
|
|
typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
|
|
|
|
typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
|
|
|
|
typedef int (*inquiry)(PyObject *);
|
2006-02-15 13:27:45 -04:00
|
|
|
typedef Py_ssize_t (*lenfunc)(PyObject *);
|
|
|
|
typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
|
|
|
|
typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
|
|
|
|
typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
|
|
|
|
typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
|
2000-07-07 21:32:04 -03:00
|
|
|
typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
|
2006-02-15 13:27:45 -04:00
|
|
|
|
2011-01-06 15:15:47 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
2007-08-18 08:21:56 -03:00
|
|
|
/* buffer interface */
|
|
|
|
typedef struct bufferinfo {
|
2010-05-09 12:52:27 -03:00
|
|
|
void *buf;
|
|
|
|
PyObject *obj; /* owned reference */
|
|
|
|
Py_ssize_t len;
|
|
|
|
Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
|
|
|
|
pointed to by strides in simple case.*/
|
|
|
|
int readonly;
|
|
|
|
int ndim;
|
|
|
|
char *format;
|
|
|
|
Py_ssize_t *shape;
|
|
|
|
Py_ssize_t *strides;
|
|
|
|
Py_ssize_t *suboffsets;
|
|
|
|
void *internal;
|
2007-09-22 23:00:13 -03:00
|
|
|
} Py_buffer;
|
2007-08-18 08:21:56 -03:00
|
|
|
|
2007-09-22 23:00:13 -03:00
|
|
|
typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
|
|
|
|
typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
|
2007-08-18 08:21:56 -03:00
|
|
|
|
2012-02-25 07:24:21 -04:00
|
|
|
/* Maximum number of dimensions */
|
|
|
|
#define PyBUF_MAX_NDIM 64
|
|
|
|
|
|
|
|
/* Flags for getting buffers */
|
2007-08-18 08:21:56 -03:00
|
|
|
#define PyBUF_SIMPLE 0
|
2007-10-13 18:03:27 -03:00
|
|
|
#define PyBUF_WRITABLE 0x0001
|
2007-09-17 14:55:36 -03:00
|
|
|
/* we used to include an E, backwards compatible alias */
|
|
|
|
#define PyBUF_WRITEABLE PyBUF_WRITABLE
|
2007-10-13 18:03:27 -03:00
|
|
|
#define PyBUF_FORMAT 0x0004
|
|
|
|
#define PyBUF_ND 0x0008
|
|
|
|
#define PyBUF_STRIDES (0x0010 | PyBUF_ND)
|
|
|
|
#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
|
|
|
|
#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
|
|
|
|
#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
|
|
|
|
#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
|
2007-08-18 08:21:56 -03:00
|
|
|
|
2007-09-17 14:55:36 -03:00
|
|
|
#define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)
|
2007-08-18 08:21:56 -03:00
|
|
|
#define PyBUF_CONTIG_RO (PyBUF_ND)
|
|
|
|
|
2007-09-17 14:55:36 -03:00
|
|
|
#define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)
|
2007-08-18 08:21:56 -03:00
|
|
|
#define PyBUF_STRIDED_RO (PyBUF_STRIDES)
|
|
|
|
|
2007-09-17 14:55:36 -03:00
|
|
|
#define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)
|
2007-08-18 08:21:56 -03:00
|
|
|
#define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)
|
|
|
|
|
2007-09-17 14:55:36 -03:00
|
|
|
#define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)
|
2007-08-18 08:21:56 -03:00
|
|
|
#define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)
|
|
|
|
|
|
|
|
|
|
|
|
#define PyBUF_READ 0x100
|
|
|
|
#define PyBUF_WRITE 0x200
|
|
|
|
|
|
|
|
/* End buffer interface */
|
2011-01-06 15:15:47 -04:00
|
|
|
#endif /* Py_LIMITED_API */
|
2006-02-15 13:27:45 -04:00
|
|
|
|
2000-07-07 21:32:04 -03:00
|
|
|
typedef int (*objobjproc)(PyObject *, PyObject *);
|
|
|
|
typedef int (*visitproc)(PyObject *, void *);
|
|
|
|
typedef int (*traverseproc)(PyObject *, visitproc, void *);
|
1994-08-01 08:34:53 -03:00
|
|
|
|
2010-12-03 16:14:31 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
1990-10-14 09:07:46 -03:00
|
|
|
typedef struct {
|
2010-05-09 12:52:27 -03:00
|
|
|
/* Number implementations must check *both*
|
|
|
|
arguments for proper type and implement the necessary conversions
|
|
|
|
in the slot functions themselves. */
|
|
|
|
|
|
|
|
binaryfunc nb_add;
|
|
|
|
binaryfunc nb_subtract;
|
|
|
|
binaryfunc nb_multiply;
|
|
|
|
binaryfunc nb_remainder;
|
|
|
|
binaryfunc nb_divmod;
|
|
|
|
ternaryfunc nb_power;
|
|
|
|
unaryfunc nb_negative;
|
|
|
|
unaryfunc nb_positive;
|
|
|
|
unaryfunc nb_absolute;
|
|
|
|
inquiry nb_bool;
|
|
|
|
unaryfunc nb_invert;
|
|
|
|
binaryfunc nb_lshift;
|
|
|
|
binaryfunc nb_rshift;
|
|
|
|
binaryfunc nb_and;
|
|
|
|
binaryfunc nb_xor;
|
|
|
|
binaryfunc nb_or;
|
|
|
|
unaryfunc nb_int;
|
|
|
|
void *nb_reserved; /* the slot formerly known as nb_long */
|
|
|
|
unaryfunc nb_float;
|
|
|
|
|
|
|
|
binaryfunc nb_inplace_add;
|
|
|
|
binaryfunc nb_inplace_subtract;
|
|
|
|
binaryfunc nb_inplace_multiply;
|
|
|
|
binaryfunc nb_inplace_remainder;
|
|
|
|
ternaryfunc nb_inplace_power;
|
|
|
|
binaryfunc nb_inplace_lshift;
|
|
|
|
binaryfunc nb_inplace_rshift;
|
|
|
|
binaryfunc nb_inplace_and;
|
|
|
|
binaryfunc nb_inplace_xor;
|
|
|
|
binaryfunc nb_inplace_or;
|
|
|
|
|
|
|
|
binaryfunc nb_floor_divide;
|
|
|
|
binaryfunc nb_true_divide;
|
|
|
|
binaryfunc nb_inplace_floor_divide;
|
|
|
|
binaryfunc nb_inplace_true_divide;
|
|
|
|
|
|
|
|
unaryfunc nb_index;
|
1995-01-12 07:45:45 -04:00
|
|
|
} PyNumberMethods;
|
1990-10-14 09:07:46 -03:00
|
|
|
|
|
|
|
typedef struct {
|
2010-05-09 12:52:27 -03:00
|
|
|
lenfunc sq_length;
|
|
|
|
binaryfunc sq_concat;
|
|
|
|
ssizeargfunc sq_repeat;
|
|
|
|
ssizeargfunc sq_item;
|
|
|
|
void *was_sq_slice;
|
|
|
|
ssizeobjargproc sq_ass_item;
|
|
|
|
void *was_sq_ass_slice;
|
|
|
|
objobjproc sq_contains;
|
|
|
|
|
|
|
|
binaryfunc sq_inplace_concat;
|
|
|
|
ssizeargfunc sq_inplace_repeat;
|
1995-01-12 07:45:45 -04:00
|
|
|
} PySequenceMethods;
|
1990-10-14 09:07:46 -03:00
|
|
|
|
|
|
|
typedef struct {
|
2010-05-09 12:52:27 -03:00
|
|
|
lenfunc mp_length;
|
|
|
|
binaryfunc mp_subscript;
|
|
|
|
objobjargproc mp_ass_subscript;
|
1995-01-12 07:45:45 -04:00
|
|
|
} PyMappingMethods;
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2007-08-18 08:21:56 -03:00
|
|
|
|
1997-05-05 19:15:02 -03:00
|
|
|
typedef struct {
|
2007-08-18 08:21:56 -03:00
|
|
|
getbufferproc bf_getbuffer;
|
|
|
|
releasebufferproc bf_releasebuffer;
|
1997-05-05 19:15:02 -03:00
|
|
|
} PyBufferProcs;
|
2010-12-03 16:14:31 -04:00
|
|
|
#endif /* Py_LIMITED_API */
|
2002-07-07 02:13:56 -03:00
|
|
|
|
2002-04-11 22:57:06 -03:00
|
|
|
typedef void (*freefunc)(void *);
|
2000-07-07 21:32:04 -03:00
|
|
|
typedef void (*destructor)(PyObject *);
|
2010-12-03 16:14:31 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
|
|
|
/* We can't provide a full compile-time check that limited-API
|
|
|
|
users won't implement tp_print. However, not defining printfunc
|
|
|
|
and making tp_print of a different function pointer type
|
|
|
|
should at least cause a warning in most cases. */
|
2000-07-07 21:32:04 -03:00
|
|
|
typedef int (*printfunc)(PyObject *, FILE *, int);
|
2010-12-03 16:14:31 -04:00
|
|
|
#endif
|
2006-02-27 12:46:16 -04:00
|
|
|
typedef PyObject *(*getattrfunc)(PyObject *, char *);
|
2000-07-07 21:32:04 -03:00
|
|
|
typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
|
2006-02-27 12:46:16 -04:00
|
|
|
typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
|
2000-07-07 21:32:04 -03:00
|
|
|
typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
|
|
|
|
typedef PyObject *(*reprfunc)(PyObject *);
|
2010-10-17 17:54:53 -03:00
|
|
|
typedef Py_hash_t (*hashfunc)(PyObject *);
|
2001-01-17 11:20:39 -04:00
|
|
|
typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
|
2001-04-20 16:13:02 -03:00
|
|
|
typedef PyObject *(*getiterfunc) (PyObject *);
|
2001-04-23 11:08:49 -03:00
|
|
|
typedef PyObject *(*iternextfunc) (PyObject *);
|
2001-08-02 01:15:00 -03:00
|
|
|
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 *);
|
2006-02-15 13:27:45 -04:00
|
|
|
typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
|
1994-08-01 08:34:53 -03:00
|
|
|
|
2010-12-03 16:14:31 -04:00
|
|
|
#ifdef Py_LIMITED_API
|
|
|
|
typedef struct _typeobject PyTypeObject; /* opaque */
|
|
|
|
#else
|
1990-10-14 09:07:46 -03:00
|
|
|
typedef struct _typeobject {
|
2010-05-09 12:52:27 -03:00
|
|
|
PyObject_VAR_HEAD
|
|
|
|
const char *tp_name; /* For printing, in format "<module>.<name>" */
|
|
|
|
Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
|
|
|
|
|
|
|
|
/* Methods to implement standard operations */
|
|
|
|
|
|
|
|
destructor tp_dealloc;
|
|
|
|
printfunc tp_print;
|
|
|
|
getattrfunc tp_getattr;
|
|
|
|
setattrfunc tp_setattr;
|
|
|
|
void *tp_reserved; /* formerly known as tp_compare */
|
|
|
|
reprfunc tp_repr;
|
|
|
|
|
|
|
|
/* Method suites for standard classes */
|
|
|
|
|
|
|
|
PyNumberMethods *tp_as_number;
|
|
|
|
PySequenceMethods *tp_as_sequence;
|
|
|
|
PyMappingMethods *tp_as_mapping;
|
|
|
|
|
|
|
|
/* More standard operations (here for binary compatibility) */
|
|
|
|
|
|
|
|
hashfunc tp_hash;
|
|
|
|
ternaryfunc tp_call;
|
|
|
|
reprfunc tp_str;
|
|
|
|
getattrofunc tp_getattro;
|
|
|
|
setattrofunc tp_setattro;
|
|
|
|
|
|
|
|
/* Functions to access object as input/output buffer */
|
|
|
|
PyBufferProcs *tp_as_buffer;
|
|
|
|
|
|
|
|
/* Flags to define presence of optional/expanded features */
|
2012-10-30 19:40:45 -03:00
|
|
|
unsigned long tp_flags;
|
2010-05-09 12:52:27 -03:00
|
|
|
|
|
|
|
const char *tp_doc; /* Documentation string */
|
|
|
|
|
|
|
|
/* Assigned meaning in release 2.0 */
|
|
|
|
/* call function for all accessible objects */
|
|
|
|
traverseproc tp_traverse;
|
|
|
|
|
|
|
|
/* delete references to contained objects */
|
|
|
|
inquiry tp_clear;
|
|
|
|
|
|
|
|
/* Assigned meaning in release 2.1 */
|
|
|
|
/* rich comparisons */
|
|
|
|
richcmpfunc tp_richcompare;
|
|
|
|
|
|
|
|
/* weak reference enabler */
|
|
|
|
Py_ssize_t tp_weaklistoffset;
|
|
|
|
|
|
|
|
/* Iterators */
|
|
|
|
getiterfunc tp_iter;
|
|
|
|
iternextfunc tp_iternext;
|
|
|
|
|
|
|
|
/* Attribute descriptor and subclassing stuff */
|
|
|
|
struct PyMethodDef *tp_methods;
|
|
|
|
struct PyMemberDef *tp_members;
|
|
|
|
struct PyGetSetDef *tp_getset;
|
|
|
|
struct _typeobject *tp_base;
|
|
|
|
PyObject *tp_dict;
|
|
|
|
descrgetfunc tp_descr_get;
|
|
|
|
descrsetfunc tp_descr_set;
|
|
|
|
Py_ssize_t tp_dictoffset;
|
|
|
|
initproc tp_init;
|
|
|
|
allocfunc tp_alloc;
|
|
|
|
newfunc tp_new;
|
|
|
|
freefunc tp_free; /* Low-level free-memory routine */
|
|
|
|
inquiry tp_is_gc; /* For PyObject_IS_GC */
|
|
|
|
PyObject *tp_bases;
|
|
|
|
PyObject *tp_mro; /* method resolution order */
|
|
|
|
PyObject *tp_cache;
|
|
|
|
PyObject *tp_subclasses;
|
|
|
|
PyObject *tp_weaklist;
|
|
|
|
destructor tp_del;
|
|
|
|
|
|
|
|
/* Type attribute cache version tag. Added in version 2.6 */
|
|
|
|
unsigned int tp_version_tag;
|
Merged revisions 59921-59932 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59923 | raymond.hettinger | 2008-01-11 19:04:55 +0100 (Fri, 11 Jan 2008) | 1 line
Speed-up and simplify code urlparse's result objects.
........
r59924 | andrew.kuchling | 2008-01-11 20:33:24 +0100 (Fri, 11 Jan 2008) | 1 line
Bug #1790: update link; remove outdated paragraph
........
r59925 | thomas.heller | 2008-01-11 20:34:06 +0100 (Fri, 11 Jan 2008) | 5 lines
Raise an error instead of crashing with a segfault when a NULL
function pointer is called.
Will backport to release25-maint.
........
r59927 | thomas.heller | 2008-01-11 21:29:19 +0100 (Fri, 11 Jan 2008) | 4 lines
Fix a potential 'SystemError: NULL result without error'.
NULL may be a valid return value from PyLong_AsVoidPtr.
Will backport to release25-maint.
........
r59928 | raymond.hettinger | 2008-01-12 00:25:18 +0100 (Sat, 12 Jan 2008) | 1 line
Update the opcode docs for STORE_MAP and BUILD_MAP
........
r59929 | mark.dickinson | 2008-01-12 02:56:00 +0100 (Sat, 12 Jan 2008) | 4 lines
Issue 1780: Allow leading and trailing whitespace in Decimal constructor,
when constructing from a string. Disallow trailing newlines in
Context.create_decimal.
........
r59930 | georg.brandl | 2008-01-12 11:53:29 +0100 (Sat, 12 Jan 2008) | 3 lines
Move OSError docs to exceptions doc, remove obsolete descriptions
from os docs, rework posix docs.
........
r59931 | georg.brandl | 2008-01-12 14:47:57 +0100 (Sat, 12 Jan 2008) | 3 lines
Patch #1700288: Method cache optimization, by Armin Rigo, ported to
2.6 by Kevin Jacobs.
........
r59932 | georg.brandl | 2008-01-12 17:11:09 +0100 (Sat, 12 Jan 2008) | 2 lines
Fix editing glitch.
........
2008-01-12 15:39:10 -04:00
|
|
|
|
2013-07-30 14:59:21 -03:00
|
|
|
destructor tp_finalize;
|
|
|
|
|
1993-10-11 09:54:31 -03:00
|
|
|
#ifdef COUNT_ALLOCS
|
2010-05-09 12:52:27 -03:00
|
|
|
/* these must be last and never explicitly initialized */
|
|
|
|
Py_ssize_t tp_allocs;
|
|
|
|
Py_ssize_t tp_frees;
|
|
|
|
Py_ssize_t tp_maxalloc;
|
|
|
|
struct _typeobject *tp_prev;
|
|
|
|
struct _typeobject *tp_next;
|
1993-10-11 09:54:31 -03:00
|
|
|
#endif
|
1995-01-12 07:45:45 -04:00
|
|
|
} PyTypeObject;
|
2010-12-03 16:14:31 -04:00
|
|
|
#endif
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2010-12-03 16:14:31 -04:00
|
|
|
typedef struct{
|
|
|
|
int slot; /* slot id, see below */
|
|
|
|
void *pfunc; /* function pointer */
|
|
|
|
} PyType_Slot;
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2010-12-03 16:14:31 -04:00
|
|
|
typedef struct{
|
|
|
|
const char* name;
|
|
|
|
int basicsize;
|
|
|
|
int itemsize;
|
2012-10-30 19:40:45 -03:00
|
|
|
unsigned int flags;
|
2010-12-03 16:14:31 -04:00
|
|
|
PyType_Slot *slots; /* terminated by slot==0. */
|
|
|
|
} PyType_Spec;
|
|
|
|
|
|
|
|
PyAPI_FUNC(PyObject*) PyType_FromSpec(PyType_Spec*);
|
2012-06-23 18:20:45 -03:00
|
|
|
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
|
|
|
|
PyAPI_FUNC(PyObject*) PyType_FromSpecWithBases(PyType_Spec*, PyObject*);
|
|
|
|
#endif
|
2014-02-04 04:33:05 -04:00
|
|
|
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
|
|
|
|
PyAPI_FUNC(void*) PyType_GetSlot(PyTypeObject*, int);
|
|
|
|
#endif
|
2010-12-03 16:14:31 -04:00
|
|
|
|
|
|
|
#ifndef Py_LIMITED_API
|
2003-03-07 11:13:17 -04:00
|
|
|
/* The *real* layout of a type object when allocated on the heap */
|
|
|
|
typedef struct _heaptypeobject {
|
2010-05-09 12:52:27 -03:00
|
|
|
/* Note: there's a dependency on the order of these members
|
|
|
|
in slotptr() in typeobject.c . */
|
|
|
|
PyTypeObject ht_type;
|
|
|
|
PyNumberMethods as_number;
|
|
|
|
PyMappingMethods as_mapping;
|
|
|
|
PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
|
|
|
|
so that the mapping wins when both
|
|
|
|
the mapping and the sequence define
|
|
|
|
a given operator (e.g. __getitem__).
|
|
|
|
see add_operators() in typeobject.c . */
|
|
|
|
PyBufferProcs as_buffer;
|
2011-11-25 13:56:07 -04:00
|
|
|
PyObject *ht_name, *ht_slots, *ht_qualname;
|
2012-04-23 12:24:50 -03:00
|
|
|
struct _dictkeysobject *ht_cached_keys;
|
2010-05-09 12:52:27 -03:00
|
|
|
/* here are optional user slots, followed by the members. */
|
2003-03-07 11:13:17 -04:00
|
|
|
} PyHeapTypeObject;
|
|
|
|
|
|
|
|
/* access macro to the members which are floating "behind" the object */
|
|
|
|
#define PyHeapType_GET_MEMBERS(etype) \
|
2007-12-18 22:45:37 -04:00
|
|
|
((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))
|
2010-12-03 16:14:31 -04:00
|
|
|
#endif
|
2003-03-07 11:13:17 -04:00
|
|
|
|
2001-08-02 01:15:00 -03:00
|
|
|
/* Generic type check */
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
|
2001-08-02 01:15:00 -03:00
|
|
|
#define PyObject_TypeCheck(ob, tp) \
|
2010-05-09 12:52:27 -03:00
|
|
|
(Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
|
2001-08-02 01:15:00 -03:00
|
|
|
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
|
|
|
|
PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
|
|
|
|
PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
|
2001-08-02 01:15:00 -03:00
|
|
|
|
2012-10-30 19:40:45 -03:00
|
|
|
PyAPI_FUNC(unsigned long) PyType_GetFlags(PyTypeObject*);
|
2011-02-05 16:35:29 -04:00
|
|
|
|
2007-02-25 16:39:11 -04:00
|
|
|
#define PyType_Check(op) \
|
2010-05-09 12:52:27 -03:00
|
|
|
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
|
2007-12-18 22:45:37 -04:00
|
|
|
#define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)
|
2001-08-02 01:15:00 -03:00
|
|
|
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
|
2006-02-15 13:27:45 -04:00
|
|
|
PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
|
2010-05-09 12:52:27 -03:00
|
|
|
PyObject *, PyObject *);
|
2010-12-03 16:14:31 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
|
2013-10-01 04:55:43 -03:00
|
|
|
PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *);
|
2012-01-22 12:24:29 -04:00
|
|
|
PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, _Py_Identifier *);
|
2011-10-23 09:04:16 -03:00
|
|
|
PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
|
2010-12-03 16:14:31 -04:00
|
|
|
#endif
|
2008-01-27 19:50:43 -04:00
|
|
|
PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
|
Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63724 | gregory.p.smith | 2008-05-26 22:22:14 +0200 (Mon, 26 May 2008) | 6 lines
Fixes issue2791: subprocess.Popen.communicate leaked a file descripton until
the last reference to the Popen instance was dropped. Adding explicit
close() calls fixes it.
Candidate for backport to release25-maint.
........
r63726 | benjamin.peterson | 2008-05-26 22:43:24 +0200 (Mon, 26 May 2008) | 2 lines
fix minor grammar typo
........
r63732 | benjamin.peterson | 2008-05-26 23:44:26 +0200 (Mon, 26 May 2008) | 2 lines
remove duplication in test module
........
r63744 | lars.gustaebel | 2008-05-27 14:39:23 +0200 (Tue, 27 May 2008) | 3 lines
Do not close external file objects passed to tarfile.open(mode='w:bz2')
when the TarFile is closed.
........
r63754 | benjamin.peterson | 2008-05-28 03:12:35 +0200 (Wed, 28 May 2008) | 2 lines
update tutorial function with more appropiate one from Eric Smith
........
r63755 | mark.hammond | 2008-05-28 03:54:55 +0200 (Wed, 28 May 2008) | 2 lines
bdist_wininst now works correctly when both --skip-build and --plat-name are specified.
........
r63757 | georg.brandl | 2008-05-28 13:21:39 +0200 (Wed, 28 May 2008) | 2 lines
#2989: add PyType_Modified().
........
r63758 | benjamin.peterson | 2008-05-28 13:51:41 +0200 (Wed, 28 May 2008) | 2 lines
fix spelling
........
r63760 | georg.brandl | 2008-05-28 17:41:36 +0200 (Wed, 28 May 2008) | 2 lines
#2990: prevent inconsistent state while updating method cache.
........
r63775 | georg.brandl | 2008-05-29 09:18:17 +0200 (Thu, 29 May 2008) | 2 lines
Two fixes in bytearray docs.
........
r63781 | georg.brandl | 2008-05-29 09:38:37 +0200 (Thu, 29 May 2008) | 2 lines
#2988: add note about catching CookieError when parsing untrusted cookie data.
........
r63782 | georg.brandl | 2008-05-29 09:45:26 +0200 (Thu, 29 May 2008) | 2 lines
#2985: allow i8 in XMLRPC responses.
........
r63787 | georg.brandl | 2008-05-29 16:35:39 +0200 (Thu, 29 May 2008) | 2 lines
Revert #2990 patch; it's not necessary as Armin showed.
........
r63805 | raymond.hettinger | 2008-05-30 08:37:27 +0200 (Fri, 30 May 2008) | 1 line
Issue 2784: fix leaks in exception exit.
........
r63806 | raymond.hettinger | 2008-05-30 08:49:47 +0200 (Fri, 30 May 2008) | 1 line
Issue 2855: Fix obscure crasher by slowing down the entire module. Mimics what was done to dictionaries in r59223.
........
r63807 | raymond.hettinger | 2008-05-30 09:16:53 +0200 (Fri, 30 May 2008) | 1 line
Issue 2903: Add __name__ in globals for namedtuple namespace.
........
r63808 | georg.brandl | 2008-05-30 09:54:16 +0200 (Fri, 30 May 2008) | 2 lines
#2999: fix name of third parameter in unicode.replace()'s docstring.
........
r63818 | georg.brandl | 2008-05-30 21:12:13 +0200 (Fri, 30 May 2008) | 2 lines
getloadavg() is not available on Windows.
........
r63819 | georg.brandl | 2008-05-30 21:17:29 +0200 (Fri, 30 May 2008) | 2 lines
Better quote with single quotes.
........
r63823 | benjamin.peterson | 2008-05-30 22:44:39 +0200 (Fri, 30 May 2008) | 2 lines
fix grammar
........
r63824 | marc-andre.lemburg | 2008-05-30 22:52:18 +0200 (Fri, 30 May 2008) | 5 lines
Update the locale module alias table.
Closes #3011.
........
2008-06-10 13:57:31 -03:00
|
|
|
PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2014-01-26 00:43:29 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
2014-02-09 02:15:29 -04:00
|
|
|
PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *);
|
|
|
|
PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *);
|
2014-01-26 00:43:29 -04:00
|
|
|
#endif
|
2014-01-24 10:17:25 -04:00
|
|
|
|
1990-12-20 11:06:42 -04:00
|
|
|
/* Generic operations on objects */
|
2011-10-09 05:38:36 -03:00
|
|
|
struct _Py_Identifier;
|
2010-12-03 16:14:31 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
|
Merged revisions 53451-53537 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r53454 | brett.cannon | 2007-01-15 20:12:08 +0100 (Mon, 15 Jan 2007) | 3 lines
Add a note for strptime that just because strftime supports some extra
directive that is not documented that strptime will as well.
........
r53458 | vinay.sajip | 2007-01-16 10:50:07 +0100 (Tue, 16 Jan 2007) | 1 line
Updated rotating file handlers to use _open().
........
r53459 | marc-andre.lemburg | 2007-01-16 14:03:06 +0100 (Tue, 16 Jan 2007) | 2 lines
Add news items for the recent pybench and platform changes.
........
r53460 | sjoerd.mullender | 2007-01-16 17:42:38 +0100 (Tue, 16 Jan 2007) | 4 lines
Fixed ntpath.expandvars to not replace references to non-existing
variables with nothing. Also added tests.
This fixes bug #494589.
........
r53464 | neal.norwitz | 2007-01-17 07:23:51 +0100 (Wed, 17 Jan 2007) | 1 line
Give Calvin Spealman access for python-dev summaries.
........
r53465 | neal.norwitz | 2007-01-17 09:37:26 +0100 (Wed, 17 Jan 2007) | 1 line
Remove Calvin since he only has access to the website currently.
........
r53466 | thomas.heller | 2007-01-17 10:40:34 +0100 (Wed, 17 Jan 2007) | 2 lines
Replace C++ comments with C comments.
........
r53472 | andrew.kuchling | 2007-01-17 20:55:06 +0100 (Wed, 17 Jan 2007) | 1 line
[Part of bug #1599254] Add suggestion to Mailbox docs to use Maildir, and warn user to lock/unlock mailboxes when modifying them
........
r53475 | georg.brandl | 2007-01-17 22:09:04 +0100 (Wed, 17 Jan 2007) | 2 lines
Bug #1637967: missing //= operator in list.
........
r53477 | georg.brandl | 2007-01-17 22:19:58 +0100 (Wed, 17 Jan 2007) | 2 lines
Bug #1629125: fix wrong data type (int -> Py_ssize_t) in PyDict_Next docs.
........
r53481 | neal.norwitz | 2007-01-18 06:40:58 +0100 (Thu, 18 Jan 2007) | 1 line
Try reverting part of r53145 that seems to cause the Windows buildbots to fail in test_uu.UUFileTest.test_encode
........
r53482 | fred.drake | 2007-01-18 06:42:30 +0100 (Thu, 18 Jan 2007) | 1 line
add missing version entry
........
r53483 | neal.norwitz | 2007-01-18 07:20:55 +0100 (Thu, 18 Jan 2007) | 7 lines
This test doesn't pass on Windows. The cause seems to be that chmod
doesn't support the same funcationality as on Unix. I'm not sure if
this fix is the best (or if it will even work)--it's a test to see
if the buildbots start passing again.
It might be better to not even run this test if it's windows (or non-posix).
........
r53488 | neal.norwitz | 2007-01-19 06:53:33 +0100 (Fri, 19 Jan 2007) | 1 line
SF #1635217, Fix unbalanced paren
........
r53489 | martin.v.loewis | 2007-01-19 07:42:22 +0100 (Fri, 19 Jan 2007) | 3 lines
Prefix AST symbols with _Py_. Fixes #1637022.
Will backport.
........
r53497 | martin.v.loewis | 2007-01-19 19:01:38 +0100 (Fri, 19 Jan 2007) | 2 lines
Add UUIDs for 2.5.1 and 2.5.2
........
r53499 | raymond.hettinger | 2007-01-19 19:07:18 +0100 (Fri, 19 Jan 2007) | 1 line
SF# 1635892: Fix docs for betavariate's input parameters .
........
r53503 | martin.v.loewis | 2007-01-20 15:05:39 +0100 (Sat, 20 Jan 2007) | 2 lines
Merge 53501 and 53502 from 25 branch:
Add /GS- for AMD64 and Itanium builds where missing.
........
r53504 | walter.doerwald | 2007-01-20 18:28:31 +0100 (Sat, 20 Jan 2007) | 2 lines
Port test_resource.py to unittest.
........
r53505 | walter.doerwald | 2007-01-20 19:19:33 +0100 (Sat, 20 Jan 2007) | 2 lines
Add argument tests an calls of resource.getrusage().
........
r53506 | walter.doerwald | 2007-01-20 20:03:17 +0100 (Sat, 20 Jan 2007) | 2 lines
resource.RUSAGE_BOTH might not exist.
........
r53507 | walter.doerwald | 2007-01-21 00:07:28 +0100 (Sun, 21 Jan 2007) | 2 lines
Port test_new.py to unittest.
........
r53508 | martin.v.loewis | 2007-01-21 10:33:07 +0100 (Sun, 21 Jan 2007) | 2 lines
Patch #1610575: Add support for _Bool to struct.
........
r53509 | georg.brandl | 2007-01-21 11:28:43 +0100 (Sun, 21 Jan 2007) | 3 lines
Bug #1486663: don't reject keyword arguments for subclasses of builtin
types.
........
r53511 | georg.brandl | 2007-01-21 11:35:10 +0100 (Sun, 21 Jan 2007) | 2 lines
Patch #1627441: close sockets properly in urllib2.
........
r53517 | georg.brandl | 2007-01-22 20:40:21 +0100 (Mon, 22 Jan 2007) | 3 lines
Use new email module names (#1637162, #1637159, #1637157).
........
r53518 | andrew.kuchling | 2007-01-22 21:26:40 +0100 (Mon, 22 Jan 2007) | 1 line
Improve pattern used for mbox 'From' lines; add a simple test
........
r53519 | andrew.kuchling | 2007-01-22 21:27:50 +0100 (Mon, 22 Jan 2007) | 1 line
Make comment match the code
........
r53522 | georg.brandl | 2007-01-22 22:10:33 +0100 (Mon, 22 Jan 2007) | 2 lines
Bug #1249573: fix rfc822.parsedate not accepting a certain date format
........
r53524 | georg.brandl | 2007-01-22 22:23:41 +0100 (Mon, 22 Jan 2007) | 2 lines
Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
........
r53526 | lars.gustaebel | 2007-01-23 12:17:33 +0100 (Tue, 23 Jan 2007) | 4 lines
Patch #1507247: tarfile.py: use current umask for intermediate
directories.
........
r53527 | thomas.wouters | 2007-01-23 14:42:00 +0100 (Tue, 23 Jan 2007) | 13 lines
SF patch #1630975: Fix crash when replacing sys.stdout in sitecustomize
When running the interpreter in an environment that would cause it to set
stdout/stderr/stdin's encoding, having a sitecustomize that would replace
them with something other than PyFile objects would crash the interpreter.
Fix it by simply ignoring the encoding-setting for non-files.
This could do with a test, but I can think of no maintainable and portable
way to test this bug, short of adding a sitecustomize.py to the buildsystem
and have it always run with it (hmmm....)
........
r53528 | thomas.wouters | 2007-01-23 14:50:49 +0100 (Tue, 23 Jan 2007) | 4 lines
Add news entry about last checkin (oops.)
........
r53531 | martin.v.loewis | 2007-01-23 22:11:47 +0100 (Tue, 23 Jan 2007) | 4 lines
Make PyTraceBack_Here use the current thread, not the
frame's thread state. Fixes #1579370.
Will backport.
........
r53535 | brett.cannon | 2007-01-24 00:21:22 +0100 (Wed, 24 Jan 2007) | 5 lines
Fix crasher for when an object's __del__ creates a new weakref to itself.
Patch only fixes new-style classes; classic classes still buggy.
Closes bug #1377858. Already backported.
........
r53536 | walter.doerwald | 2007-01-24 01:42:19 +0100 (Wed, 24 Jan 2007) | 2 lines
Port test_popen.py to unittest.
........
2007-02-01 14:02:27 -04:00
|
|
|
PyAPI_FUNC(void) _Py_BreakPoint(void);
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
|
2010-12-03 16:14:31 -04:00
|
|
|
#endif
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *);
|
2008-06-11 15:37:52 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyObject_ASCII(PyObject *);
|
2008-08-26 13:46:47 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyObject_Bytes(PyObject *);
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
|
|
|
|
PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
|
2005-12-10 14:50:16 -04:00
|
|
|
PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *);
|
|
|
|
PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *);
|
|
|
|
PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
|
|
|
|
PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
|
|
|
|
PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
|
2011-12-15 16:34:02 -04:00
|
|
|
PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *);
|
2011-10-09 05:38:36 -03:00
|
|
|
PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *);
|
|
|
|
PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *);
|
|
|
|
PyAPI_FUNC(int) _PyObject_HasAttrId(PyObject *, struct _Py_Identifier *);
|
2010-12-03 16:14:31 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
|
2010-12-03 16:14:31 -04:00
|
|
|
#endif
|
2003-03-17 15:46:11 -04:00
|
|
|
PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
|
2010-12-03 16:14:31 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
2009-01-12 19:58:21 -04:00
|
|
|
PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
|
2010-12-03 16:14:31 -04:00
|
|
|
#endif
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
|
|
|
|
PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
|
2010-05-09 12:52:27 -03:00
|
|
|
PyObject *, PyObject *);
|
2012-02-19 20:59:10 -04:00
|
|
|
PyAPI_FUNC(int) PyObject_GenericSetDict(PyObject *, PyObject *, void *);
|
2010-10-17 17:54:53 -03:00
|
|
|
PyAPI_FUNC(Py_hash_t) PyObject_Hash(PyObject *);
|
|
|
|
PyAPI_FUNC(Py_hash_t) PyObject_HashNotImplemented(PyObject *);
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);
|
|
|
|
PyAPI_FUNC(int) PyObject_Not(PyObject *);
|
|
|
|
PyAPI_FUNC(int) PyCallable_Check(PyObject *);
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(void) PyObject_ClearWeakRefs(PyObject *);
|
2014-01-03 16:36:49 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
2013-07-30 14:59:21 -03:00
|
|
|
PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *);
|
|
|
|
PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *);
|
2014-01-03 16:36:49 -04:00
|
|
|
#endif
|
2001-02-01 01:27:45 -04:00
|
|
|
|
2010-08-28 15:17:03 -03:00
|
|
|
/* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes
|
|
|
|
dict as the last parameter. */
|
|
|
|
PyAPI_FUNC(PyObject *)
|
|
|
|
_PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *);
|
|
|
|
PyAPI_FUNC(int)
|
|
|
|
_PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
|
|
|
|
PyObject *, PyObject *);
|
|
|
|
|
2012-04-04 19:04:20 -03:00
|
|
|
/* Helper to look up a builtin object */
|
|
|
|
#ifndef Py_LIMITED_API
|
|
|
|
PyAPI_FUNC(PyObject *)
|
|
|
|
_PyObject_GetBuiltin(const char *name);
|
|
|
|
#endif
|
2001-09-18 17:38:53 -03:00
|
|
|
|
2007-12-02 05:40:06 -04:00
|
|
|
/* PyObject_Dir(obj) acts like Python builtins.dir(obj), returning a
|
|
|
|
list of strings. PyObject_Dir(NULL) is like builtins.dir(),
|
2001-09-04 19:08:56 -03:00
|
|
|
returning the names of the current locals. In this case, if there are
|
|
|
|
no current locals, NULL is returned, and PyErr_Occurred() is false.
|
|
|
|
*/
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyObject_Dir(PyObject *);
|
2001-09-04 19:08:56 -03:00
|
|
|
|
|
|
|
|
1998-04-10 19:32:24 -03:00
|
|
|
/* Helpers for printing recursive container types */
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(int) Py_ReprEnter(PyObject *);
|
|
|
|
PyAPI_FUNC(void) Py_ReprLeave(PyObject *);
|
1998-04-10 19:32:24 -03:00
|
|
|
|
2014-11-18 18:08:38 -04:00
|
|
|
#ifndef Py_LIMITED_API
|
|
|
|
/* Helper for passing objects to printf and the like.
|
|
|
|
Leaks refcounts. Don't use it!
|
|
|
|
*/
|
|
|
|
#define PyObject_REPR(obj) PyUnicode_AsUTF8(PyObject_Repr(obj))
|
|
|
|
#endif
|
2001-02-01 16:20:45 -04:00
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/* Flag bits for printing: */
|
2010-05-09 12:52:27 -03:00
|
|
|
#define Py_PRINT_RAW 1 /* No string quotes etc. */
|
1990-10-14 09:07:46 -03:00
|
|
|
|
Changes by Greg Stein (code) and GvR (design).
Add a new member to the PyBufferProcs struct, bf_getcharbuffer. For
backward compatibility, this member should only be used (this includes
testing for NULL!) when the flag Py_TPFLAGS_HAVE_GETCHARBUFFER is set
in the type structure, below. Note that if its flag is not set, we
may be looking at an extension module compiled for 1.5.1, which will
have garbage at the bf_getcharbuffer member (because the struct wasn't
as long then). If the flag is one, the pointer may still be NULL.
The function found at this member is used in a similar manner as
bf_getreadbuffer, but it is known to point to 8-bit character data.
(See discussion in getargs.c checked in later.)
As a general feature for extending the type structure and the various
structures that (may) hang off it in a backwards compatible way, we
rename the tp_xxx4 "spare" slot to tp_flags. In 1.5.1 and before,
this slot was always zero. In 1.5.1, it may contain various flags
indicating extra fields that weren't present in 1.5.1. The only flag
defined so far is for the bf_getcharbuffer member of the PyBufferProcs
struct.
Note that the new spares (tp_xxx5 - tp_xxx8), once they become used,
should also be protected by a flag (or flags) in tp_flags.
1998-10-07 23:10:56 -03:00
|
|
|
/*
|
2002-07-07 16:59:50 -03:00
|
|
|
`Type flags (tp_flags)
|
Changes by Greg Stein (code) and GvR (design).
Add a new member to the PyBufferProcs struct, bf_getcharbuffer. For
backward compatibility, this member should only be used (this includes
testing for NULL!) when the flag Py_TPFLAGS_HAVE_GETCHARBUFFER is set
in the type structure, below. Note that if its flag is not set, we
may be looking at an extension module compiled for 1.5.1, which will
have garbage at the bf_getcharbuffer member (because the struct wasn't
as long then). If the flag is one, the pointer may still be NULL.
The function found at this member is used in a similar manner as
bf_getreadbuffer, but it is known to point to 8-bit character data.
(See discussion in getargs.c checked in later.)
As a general feature for extending the type structure and the various
structures that (may) hang off it in a backwards compatible way, we
rename the tp_xxx4 "spare" slot to tp_flags. In 1.5.1 and before,
this slot was always zero. In 1.5.1, it may contain various flags
indicating extra fields that weren't present in 1.5.1. The only flag
defined so far is for the bf_getcharbuffer member of the PyBufferProcs
struct.
Note that the new spares (tp_xxx5 - tp_xxx8), once they become used,
should also be protected by a flag (or flags) in tp_flags.
1998-10-07 23:10:56 -03:00
|
|
|
|
|
|
|
These flags are used to extend the type structure in a backwards-compatible
|
|
|
|
fashion. Extensions can use the flags to indicate (and test) when a given
|
|
|
|
type structure contains a new feature. The Python core will use these when
|
|
|
|
introducing new functionality between major revisions (to avoid mid-version
|
|
|
|
changes in the PYTHON_API_VERSION).
|
|
|
|
|
|
|
|
Arbitration of the flag bit positions will need to be coordinated among
|
|
|
|
all extension writers who publically release their extensions (this will
|
|
|
|
be fewer than you might expect!)..
|
|
|
|
|
2006-07-27 18:53:35 -03:00
|
|
|
Most flags were removed as of Python 3.0 to make room for new flags. (Some
|
|
|
|
flags are not for backwards compatibility but to indicate the presence of an
|
|
|
|
optional feature; these flags remain of course.)
|
Changes by Greg Stein (code) and GvR (design).
Add a new member to the PyBufferProcs struct, bf_getcharbuffer. For
backward compatibility, this member should only be used (this includes
testing for NULL!) when the flag Py_TPFLAGS_HAVE_GETCHARBUFFER is set
in the type structure, below. Note that if its flag is not set, we
may be looking at an extension module compiled for 1.5.1, which will
have garbage at the bf_getcharbuffer member (because the struct wasn't
as long then). If the flag is one, the pointer may still be NULL.
The function found at this member is used in a similar manner as
bf_getreadbuffer, but it is known to point to 8-bit character data.
(See discussion in getargs.c checked in later.)
As a general feature for extending the type structure and the various
structures that (may) hang off it in a backwards compatible way, we
rename the tp_xxx4 "spare" slot to tp_flags. In 1.5.1 and before,
this slot was always zero. In 1.5.1, it may contain various flags
indicating extra fields that weren't present in 1.5.1. The only flag
defined so far is for the bf_getcharbuffer member of the PyBufferProcs
struct.
Note that the new spares (tp_xxx5 - tp_xxx8), once they become used,
should also be protected by a flag (or flags) in tp_flags.
1998-10-07 23:10:56 -03:00
|
|
|
|
|
|
|
Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value.
|
|
|
|
|
|
|
|
Code can use PyType_HasFeature(type_ob, flag_value) to test whether the
|
|
|
|
given type object has a specified feature.
|
|
|
|
*/
|
|
|
|
|
2001-08-02 01:15:00 -03:00
|
|
|
/* Set if the type object is dynamically allocated */
|
2012-10-30 19:40:45 -03:00
|
|
|
#define Py_TPFLAGS_HEAPTYPE (1UL << 9)
|
2001-08-02 01:15:00 -03:00
|
|
|
|
|
|
|
/* Set if the type allows subclassing */
|
2012-10-30 19:40:45 -03:00
|
|
|
#define Py_TPFLAGS_BASETYPE (1UL << 10)
|
2001-08-02 01:15:00 -03:00
|
|
|
|
2001-08-10 14:37:02 -03:00
|
|
|
/* Set if the type is 'ready' -- fully initialized */
|
2012-10-30 19:40:45 -03:00
|
|
|
#define Py_TPFLAGS_READY (1UL << 12)
|
2001-08-10 14:37:02 -03:00
|
|
|
|
|
|
|
/* Set while the type is being 'readied', to prevent recursive ready calls */
|
2012-10-30 19:40:45 -03:00
|
|
|
#define Py_TPFLAGS_READYING (1UL << 13)
|
2001-08-10 14:37:02 -03:00
|
|
|
|
2001-08-29 20:46:35 -03:00
|
|
|
/* Objects support garbage collection (see objimp.h) */
|
2012-10-30 19:40:45 -03:00
|
|
|
#define Py_TPFLAGS_HAVE_GC (1UL << 14)
|
2001-08-29 20:46:35 -03:00
|
|
|
|
2006-03-07 14:50:55 -04:00
|
|
|
/* These two bits are preserved for Stackless Python, next after this is 17 */
|
2003-05-20 12:14:31 -03:00
|
|
|
#ifdef STACKLESS
|
2012-10-30 19:40:45 -03:00
|
|
|
#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION (3UL << 15)
|
2003-05-20 12:14:31 -03:00
|
|
|
#else
|
2003-05-23 00:33:35 -03:00
|
|
|
#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
|
2003-05-20 12:14:31 -03:00
|
|
|
#endif
|
|
|
|
|
Merged revisions 59921-59932 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59923 | raymond.hettinger | 2008-01-11 19:04:55 +0100 (Fri, 11 Jan 2008) | 1 line
Speed-up and simplify code urlparse's result objects.
........
r59924 | andrew.kuchling | 2008-01-11 20:33:24 +0100 (Fri, 11 Jan 2008) | 1 line
Bug #1790: update link; remove outdated paragraph
........
r59925 | thomas.heller | 2008-01-11 20:34:06 +0100 (Fri, 11 Jan 2008) | 5 lines
Raise an error instead of crashing with a segfault when a NULL
function pointer is called.
Will backport to release25-maint.
........
r59927 | thomas.heller | 2008-01-11 21:29:19 +0100 (Fri, 11 Jan 2008) | 4 lines
Fix a potential 'SystemError: NULL result without error'.
NULL may be a valid return value from PyLong_AsVoidPtr.
Will backport to release25-maint.
........
r59928 | raymond.hettinger | 2008-01-12 00:25:18 +0100 (Sat, 12 Jan 2008) | 1 line
Update the opcode docs for STORE_MAP and BUILD_MAP
........
r59929 | mark.dickinson | 2008-01-12 02:56:00 +0100 (Sat, 12 Jan 2008) | 4 lines
Issue 1780: Allow leading and trailing whitespace in Decimal constructor,
when constructing from a string. Disallow trailing newlines in
Context.create_decimal.
........
r59930 | georg.brandl | 2008-01-12 11:53:29 +0100 (Sat, 12 Jan 2008) | 3 lines
Move OSError docs to exceptions doc, remove obsolete descriptions
from os docs, rework posix docs.
........
r59931 | georg.brandl | 2008-01-12 14:47:57 +0100 (Sat, 12 Jan 2008) | 3 lines
Patch #1700288: Method cache optimization, by Armin Rigo, ported to
2.6 by Kevin Jacobs.
........
r59932 | georg.brandl | 2008-01-12 17:11:09 +0100 (Sat, 12 Jan 2008) | 2 lines
Fix editing glitch.
........
2008-01-12 15:39:10 -04:00
|
|
|
/* Objects support type attribute cache */
|
2012-10-30 19:40:45 -03:00
|
|
|
#define Py_TPFLAGS_HAVE_VERSION_TAG (1UL << 18)
|
|
|
|
#define Py_TPFLAGS_VALID_VERSION_TAG (1UL << 19)
|
Merged revisions 59921-59932 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59923 | raymond.hettinger | 2008-01-11 19:04:55 +0100 (Fri, 11 Jan 2008) | 1 line
Speed-up and simplify code urlparse's result objects.
........
r59924 | andrew.kuchling | 2008-01-11 20:33:24 +0100 (Fri, 11 Jan 2008) | 1 line
Bug #1790: update link; remove outdated paragraph
........
r59925 | thomas.heller | 2008-01-11 20:34:06 +0100 (Fri, 11 Jan 2008) | 5 lines
Raise an error instead of crashing with a segfault when a NULL
function pointer is called.
Will backport to release25-maint.
........
r59927 | thomas.heller | 2008-01-11 21:29:19 +0100 (Fri, 11 Jan 2008) | 4 lines
Fix a potential 'SystemError: NULL result without error'.
NULL may be a valid return value from PyLong_AsVoidPtr.
Will backport to release25-maint.
........
r59928 | raymond.hettinger | 2008-01-12 00:25:18 +0100 (Sat, 12 Jan 2008) | 1 line
Update the opcode docs for STORE_MAP and BUILD_MAP
........
r59929 | mark.dickinson | 2008-01-12 02:56:00 +0100 (Sat, 12 Jan 2008) | 4 lines
Issue 1780: Allow leading and trailing whitespace in Decimal constructor,
when constructing from a string. Disallow trailing newlines in
Context.create_decimal.
........
r59930 | georg.brandl | 2008-01-12 11:53:29 +0100 (Sat, 12 Jan 2008) | 3 lines
Move OSError docs to exceptions doc, remove obsolete descriptions
from os docs, rework posix docs.
........
r59931 | georg.brandl | 2008-01-12 14:47:57 +0100 (Sat, 12 Jan 2008) | 3 lines
Patch #1700288: Method cache optimization, by Armin Rigo, ported to
2.6 by Kevin Jacobs.
........
r59932 | georg.brandl | 2008-01-12 17:11:09 +0100 (Sat, 12 Jan 2008) | 2 lines
Fix editing glitch.
........
2008-01-12 15:39:10 -04:00
|
|
|
|
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61098 | jeffrey.yasskin | 2008-02-28 05:45:36 +0100 (Thu, 28 Feb 2008) | 7 lines
Move abc._Abstract into object by adding a new flag Py_TPFLAGS_IS_ABSTRACT,
which forbids constructing types that have it set. The effect is to speed
./python.exe -m timeit -s 'import abc' -s 'class Foo(object): __metaclass__ = abc.ABCMeta' 'Foo()'
up from 2.5us to 0.201us. This fixes issue 1762.
........
r61099 | jeffrey.yasskin | 2008-02-28 06:53:18 +0100 (Thu, 28 Feb 2008) | 3 lines
Speed test_socketserver up from 28.739s to 0.226s, simplify the logic, and make
sure all tests run even if some fail.
........
r61100 | jeffrey.yasskin | 2008-02-28 07:09:19 +0100 (Thu, 28 Feb 2008) | 21 lines
Thread.start() used sleep(0.000001) to make sure it didn't return before the
new thread had started. At least on my MacBook Pro, that wound up sleeping for
a full 10ms (probably 1 jiffy). By using an Event instead, we can be absolutely
certain that the thread has started, and return more quickly (217us).
Before:
$ ./python.exe -m timeit -s 'from threading import Thread' 't = Thread(); t.start(); t.join()'
100 loops, best of 3: 10.3 msec per loop
$ ./python.exe -m timeit -s 'from threading import Thread; t = Thread()' 't.isAlive()'
1000000 loops, best of 3: 0.47 usec per loop
After:
$ ./python.exe -m timeit -s 'from threading import Thread' 't = Thread(); t.start(); t.join()'
1000 loops, best of 3: 217 usec per loop
$ ./python.exe -m timeit -s 'from threading import Thread; t = Thread()' 't.isAlive()'
1000000 loops, best of 3: 0.86 usec per loop
To be fair, the 10ms isn't CPU time, and other threads including the spawned
one get to run during it. There are also some slightly more complicated ways to
get back the .4us in isAlive() if we want.
........
r61101 | raymond.hettinger | 2008-02-28 10:23:48 +0100 (Thu, 28 Feb 2008) | 1 line
Add repeat keyword argument to itertools.product().
........
r61102 | christian.heimes | 2008-02-28 12:18:49 +0100 (Thu, 28 Feb 2008) | 1 line
The empty tuple is usually a singleton with a much higher refcnt than 1
........
2008-02-28 08:27:11 -04:00
|
|
|
/* Type is abstract and cannot be instantiated */
|
2012-10-30 19:40:45 -03:00
|
|
|
#define Py_TPFLAGS_IS_ABSTRACT (1UL << 20)
|
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61098 | jeffrey.yasskin | 2008-02-28 05:45:36 +0100 (Thu, 28 Feb 2008) | 7 lines
Move abc._Abstract into object by adding a new flag Py_TPFLAGS_IS_ABSTRACT,
which forbids constructing types that have it set. The effect is to speed
./python.exe -m timeit -s 'import abc' -s 'class Foo(object): __metaclass__ = abc.ABCMeta' 'Foo()'
up from 2.5us to 0.201us. This fixes issue 1762.
........
r61099 | jeffrey.yasskin | 2008-02-28 06:53:18 +0100 (Thu, 28 Feb 2008) | 3 lines
Speed test_socketserver up from 28.739s to 0.226s, simplify the logic, and make
sure all tests run even if some fail.
........
r61100 | jeffrey.yasskin | 2008-02-28 07:09:19 +0100 (Thu, 28 Feb 2008) | 21 lines
Thread.start() used sleep(0.000001) to make sure it didn't return before the
new thread had started. At least on my MacBook Pro, that wound up sleeping for
a full 10ms (probably 1 jiffy). By using an Event instead, we can be absolutely
certain that the thread has started, and return more quickly (217us).
Before:
$ ./python.exe -m timeit -s 'from threading import Thread' 't = Thread(); t.start(); t.join()'
100 loops, best of 3: 10.3 msec per loop
$ ./python.exe -m timeit -s 'from threading import Thread; t = Thread()' 't.isAlive()'
1000000 loops, best of 3: 0.47 usec per loop
After:
$ ./python.exe -m timeit -s 'from threading import Thread' 't = Thread(); t.start(); t.join()'
1000 loops, best of 3: 217 usec per loop
$ ./python.exe -m timeit -s 'from threading import Thread; t = Thread()' 't.isAlive()'
1000000 loops, best of 3: 0.86 usec per loop
To be fair, the 10ms isn't CPU time, and other threads including the spawned
one get to run during it. There are also some slightly more complicated ways to
get back the .4us in isAlive() if we want.
........
r61101 | raymond.hettinger | 2008-02-28 10:23:48 +0100 (Thu, 28 Feb 2008) | 1 line
Add repeat keyword argument to itertools.product().
........
r61102 | christian.heimes | 2008-02-28 12:18:49 +0100 (Thu, 28 Feb 2008) | 1 line
The empty tuple is usually a singleton with a much higher refcnt than 1
........
2008-02-28 08:27:11 -04:00
|
|
|
|
2007-02-25 16:39:11 -04:00
|
|
|
/* These flags are used to determine if a type is a subclass. */
|
2012-10-30 19:40:45 -03:00
|
|
|
#define Py_TPFLAGS_LONG_SUBCLASS (1UL << 24)
|
|
|
|
#define Py_TPFLAGS_LIST_SUBCLASS (1UL << 25)
|
|
|
|
#define Py_TPFLAGS_TUPLE_SUBCLASS (1UL << 26)
|
|
|
|
#define Py_TPFLAGS_BYTES_SUBCLASS (1UL << 27)
|
|
|
|
#define Py_TPFLAGS_UNICODE_SUBCLASS (1UL << 28)
|
|
|
|
#define Py_TPFLAGS_DICT_SUBCLASS (1UL << 29)
|
|
|
|
#define Py_TPFLAGS_BASE_EXC_SUBCLASS (1UL << 30)
|
|
|
|
#define Py_TPFLAGS_TYPE_SUBCLASS (1UL << 31)
|
2007-02-25 16:39:11 -04:00
|
|
|
|
2001-01-24 18:13:48 -04:00
|
|
|
#define Py_TPFLAGS_DEFAULT ( \
|
2010-05-09 12:52:27 -03:00
|
|
|
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
|
|
|
|
Py_TPFLAGS_HAVE_VERSION_TAG | \
|
|
|
|
0)
|
Changes by Greg Stein (code) and GvR (design).
Add a new member to the PyBufferProcs struct, bf_getcharbuffer. For
backward compatibility, this member should only be used (this includes
testing for NULL!) when the flag Py_TPFLAGS_HAVE_GETCHARBUFFER is set
in the type structure, below. Note that if its flag is not set, we
may be looking at an extension module compiled for 1.5.1, which will
have garbage at the bf_getcharbuffer member (because the struct wasn't
as long then). If the flag is one, the pointer may still be NULL.
The function found at this member is used in a similar manner as
bf_getreadbuffer, but it is known to point to 8-bit character data.
(See discussion in getargs.c checked in later.)
As a general feature for extending the type structure and the various
structures that (may) hang off it in a backwards compatible way, we
rename the tp_xxx4 "spare" slot to tp_flags. In 1.5.1 and before,
this slot was always zero. In 1.5.1, it may contain various flags
indicating extra fields that weren't present in 1.5.1. The only flag
defined so far is for the bf_getcharbuffer member of the PyBufferProcs
struct.
Note that the new spares (tp_xxx5 - tp_xxx8), once they become used,
should also be protected by a flag (or flags) in tp_flags.
1998-10-07 23:10:56 -03:00
|
|
|
|
2013-07-30 14:59:21 -03:00
|
|
|
/* NOTE: The following flags reuse lower bits (removed as part of the
|
|
|
|
* Python 3.0 transition). */
|
|
|
|
|
|
|
|
/* Type structure has tp_finalize member (3.4) */
|
|
|
|
#define Py_TPFLAGS_HAVE_FINALIZE (1UL << 0)
|
|
|
|
|
2011-02-05 16:35:29 -04:00
|
|
|
#ifdef Py_LIMITED_API
|
|
|
|
#define PyType_HasFeature(t,f) ((PyType_GetFlags(t) & (f)) != 0)
|
|
|
|
#else
|
Changes by Greg Stein (code) and GvR (design).
Add a new member to the PyBufferProcs struct, bf_getcharbuffer. For
backward compatibility, this member should only be used (this includes
testing for NULL!) when the flag Py_TPFLAGS_HAVE_GETCHARBUFFER is set
in the type structure, below. Note that if its flag is not set, we
may be looking at an extension module compiled for 1.5.1, which will
have garbage at the bf_getcharbuffer member (because the struct wasn't
as long then). If the flag is one, the pointer may still be NULL.
The function found at this member is used in a similar manner as
bf_getreadbuffer, but it is known to point to 8-bit character data.
(See discussion in getargs.c checked in later.)
As a general feature for extending the type structure and the various
structures that (may) hang off it in a backwards compatible way, we
rename the tp_xxx4 "spare" slot to tp_flags. In 1.5.1 and before,
this slot was always zero. In 1.5.1, it may contain various flags
indicating extra fields that weren't present in 1.5.1. The only flag
defined so far is for the bf_getcharbuffer member of the PyBufferProcs
struct.
Note that the new spares (tp_xxx5 - tp_xxx8), once they become used,
should also be protected by a flag (or flags) in tp_flags.
1998-10-07 23:10:56 -03:00
|
|
|
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
|
2011-02-05 16:35:29 -04:00
|
|
|
#endif
|
2007-02-25 16:39:11 -04:00
|
|
|
#define PyType_FastSubclass(t,f) PyType_HasFeature(t,f)
|
Changes by Greg Stein (code) and GvR (design).
Add a new member to the PyBufferProcs struct, bf_getcharbuffer. For
backward compatibility, this member should only be used (this includes
testing for NULL!) when the flag Py_TPFLAGS_HAVE_GETCHARBUFFER is set
in the type structure, below. Note that if its flag is not set, we
may be looking at an extension module compiled for 1.5.1, which will
have garbage at the bf_getcharbuffer member (because the struct wasn't
as long then). If the flag is one, the pointer may still be NULL.
The function found at this member is used in a similar manner as
bf_getreadbuffer, but it is known to point to 8-bit character data.
(See discussion in getargs.c checked in later.)
As a general feature for extending the type structure and the various
structures that (may) hang off it in a backwards compatible way, we
rename the tp_xxx4 "spare" slot to tp_flags. In 1.5.1 and before,
this slot was always zero. In 1.5.1, it may contain various flags
indicating extra fields that weren't present in 1.5.1. The only flag
defined so far is for the bf_getcharbuffer member of the PyBufferProcs
struct.
Note that the new spares (tp_xxx5 - tp_xxx8), once they become used,
should also be protected by a flag (or flags) in tp_flags.
1998-10-07 23:10:56 -03:00
|
|
|
|
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/*
|
1995-01-12 07:45:45 -04:00
|
|
|
The macros Py_INCREF(op) and Py_DECREF(op) are used to increment or decrement
|
2002-07-07 16:59:50 -03:00
|
|
|
reference counts. Py_DECREF calls the object's deallocator function when
|
|
|
|
the refcount falls to 0; for
|
1990-10-14 09:07:46 -03:00
|
|
|
objects that don't contain references to other objects or heap memory
|
|
|
|
this can be the standard function free(). Both macros can be used
|
2002-07-07 16:59:50 -03:00
|
|
|
wherever a void expression is allowed. The argument must not be a
|
Merged revisions 62021,62029,62035-62038,62043-62044,62052-62053 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62021 | benjamin.peterson | 2008-03-28 18:11:01 -0500 (Fri, 28 Mar 2008) | 2 lines
NIL => NULL
........
r62029 | amaury.forgeotdarc | 2008-03-28 20:42:31 -0500 (Fri, 28 Mar 2008) | 3 lines
Correctly call the base class tearDown();
otherwise running test_logging twice produce the errors we see on all buildbots
........
r62035 | raymond.hettinger | 2008-03-29 05:42:07 -0500 (Sat, 29 Mar 2008) | 1 line
Be explicit about what efficient means.
........
r62036 | georg.brandl | 2008-03-29 06:46:18 -0500 (Sat, 29 Mar 2008) | 2 lines
Fix capitalization.
........
r62037 | amaury.forgeotdarc | 2008-03-29 07:42:54 -0500 (Sat, 29 Mar 2008) | 5 lines
lib2to3 should install a logging handler only when run as a main program,
not when used as a library.
This may please the buildbots, which fail when test_lib2to3 is run before test_logging.
........
r62043 | benjamin.peterson | 2008-03-29 10:24:25 -0500 (Sat, 29 Mar 2008) | 3 lines
#2503 make singletons compared with "is" not == or !=
Thanks to Wummel for the patch
........
r62044 | gerhard.haering | 2008-03-29 14:11:52 -0500 (Sat, 29 Mar 2008) | 2 lines
Documented the lastrowid attribute.
........
r62052 | benjamin.peterson | 2008-03-30 14:35:10 -0500 (Sun, 30 Mar 2008) | 2 lines
Updated README regarding doc formats
........
r62053 | georg.brandl | 2008-03-30 14:41:39 -0500 (Sun, 30 Mar 2008) | 2 lines
The other download formats will be available for 2.6 too.
........
2008-03-30 22:51:45 -03:00
|
|
|
NULL pointer. If it may be NULL, use Py_XINCREF/Py_XDECREF instead.
|
2002-07-07 16:59:50 -03:00
|
|
|
The macro _Py_NewReference(op) initialize reference counts to 1, and
|
|
|
|
in special builds (Py_REF_DEBUG, Py_TRACE_REFS) performs additional
|
|
|
|
bookkeeping appropriate to the special build.
|
1990-10-14 09:07:46 -03:00
|
|
|
|
|
|
|
We assume that the reference count field can never overflow; this can
|
2002-07-07 16:59:50 -03:00
|
|
|
be proven when the size of the field is the same as the pointer size, so
|
|
|
|
we ignore the possibility. Provided a C int is at least 32 bits (which
|
|
|
|
is implicitly assumed in many parts of this code), that's enough for
|
|
|
|
about 2**31 references to an object.
|
|
|
|
|
|
|
|
XXX The following became out of date in Python 2.2, but I'm not sure
|
|
|
|
XXX what the full truth is now. Certainly, heap-allocated type objects
|
|
|
|
XXX can and should be deallocated.
|
1990-10-14 09:07:46 -03:00
|
|
|
Type objects should never be deallocated; the type pointer in an object
|
|
|
|
is not considered to be a reference to the type object, to save
|
|
|
|
complications in the deallocation function. (This is actually a
|
|
|
|
decision that's up to the implementer of each new type so if you want,
|
|
|
|
you can count such references to the type object.)
|
|
|
|
*/
|
|
|
|
|
object.h special-build macro minefield: renamed all the new lexical
helper macros to something saner, and used them appropriately in other
files too, to reduce #ifdef blocks.
classobject.c, instance_dealloc(): One of my worst Python Memories is
trying to fix this routine a few years ago when COUNT_ALLOCS was defined
but Py_TRACE_REFS wasn't. The special-build code here is way too
complicated. Now it's much simpler. Difference: in a Py_TRACE_REFS
build, the instance is no longer in the doubly-linked list of live
objects while its __del__ method is executing, and that may be visible
via sys.getobjects() called from a __del__ method. Tough -- the object
is presumed dead while its __del__ is executing anyway, and not calling
_Py_NewReference() at the start allows enormous code simplification.
typeobject.c, call_finalizer(): The special-build instance_dealloc()
pain apparently spread to here too via cut-'n-paste, and this is much
simpler now too. In addition, I didn't understand why this routine
was calling _PyObject_GC_TRACK() after a resurrection, since there's no
plausible way _PyObject_GC_UNTRACK() could have been called on the
object by this point. I suspect it was left over from pasting the
instance_delloc() code. Instead asserted that the object is still
tracked. Caution: I suspect we don't have a test that actually
exercises the subtype_dealloc() __del__-resurrected-me code.
2002-07-11 03:23:50 -03:00
|
|
|
/* First define a pile of simple helper macros, one set per special
|
|
|
|
* build symbol. These either expand to the obvious things, or to
|
|
|
|
* nothing at all when the special mode isn't in effect. The main
|
|
|
|
* macros can later be defined just once then, yet expand to different
|
|
|
|
* things depending on which special build options are and aren't in effect.
|
|
|
|
* Trust me <wink>: while painful, this is 20x easier to understand than,
|
|
|
|
* e.g, defining _Py_NewReference five different times in a maze of nested
|
|
|
|
* #ifdefs (we used to do that -- it was impenetrable).
|
|
|
|
*/
|
2002-07-07 16:59:50 -03:00
|
|
|
#ifdef Py_REF_DEBUG
|
2006-03-04 15:58:13 -04:00
|
|
|
PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
|
2010-05-09 12:52:27 -03:00
|
|
|
int lineno, PyObject *op);
|
2006-04-21 07:40:58 -03:00
|
|
|
PyAPI_FUNC(PyObject *) _PyDict_Dummy(void);
|
|
|
|
PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
|
2010-05-09 12:52:27 -03:00
|
|
|
#define _Py_INC_REFTOTAL _Py_RefTotal++
|
|
|
|
#define _Py_DEC_REFTOTAL _Py_RefTotal--
|
|
|
|
#define _Py_REF_DEBUG_COMMA ,
|
|
|
|
#define _Py_CHECK_REFCNT(OP) \
|
|
|
|
{ if (((PyObject*)OP)->ob_refcnt < 0) \
|
|
|
|
_Py_NegativeRefcount(__FILE__, __LINE__, \
|
|
|
|
(PyObject *)(OP)); \
|
2002-07-08 23:57:01 -03:00
|
|
|
}
|
2002-07-07 16:59:50 -03:00
|
|
|
#else
|
object.h special-build macro minefield: renamed all the new lexical
helper macros to something saner, and used them appropriately in other
files too, to reduce #ifdef blocks.
classobject.c, instance_dealloc(): One of my worst Python Memories is
trying to fix this routine a few years ago when COUNT_ALLOCS was defined
but Py_TRACE_REFS wasn't. The special-build code here is way too
complicated. Now it's much simpler. Difference: in a Py_TRACE_REFS
build, the instance is no longer in the doubly-linked list of live
objects while its __del__ method is executing, and that may be visible
via sys.getobjects() called from a __del__ method. Tough -- the object
is presumed dead while its __del__ is executing anyway, and not calling
_Py_NewReference() at the start allows enormous code simplification.
typeobject.c, call_finalizer(): The special-build instance_dealloc()
pain apparently spread to here too via cut-'n-paste, and this is much
simpler now too. In addition, I didn't understand why this routine
was calling _PyObject_GC_TRACK() after a resurrection, since there's no
plausible way _PyObject_GC_UNTRACK() could have been called on the
object by this point. I suspect it was left over from pasting the
instance_delloc() code. Instead asserted that the object is still
tracked. Caution: I suspect we don't have a test that actually
exercises the subtype_dealloc() __del__-resurrected-me code.
2002-07-11 03:23:50 -03:00
|
|
|
#define _Py_INC_REFTOTAL
|
|
|
|
#define _Py_DEC_REFTOTAL
|
|
|
|
#define _Py_REF_DEBUG_COMMA
|
2010-05-09 12:52:27 -03:00
|
|
|
#define _Py_CHECK_REFCNT(OP) /* a semicolon */;
|
2002-07-10 03:34:15 -03:00
|
|
|
#endif /* Py_REF_DEBUG */
|
2002-07-07 16:59:50 -03:00
|
|
|
|
|
|
|
#ifdef COUNT_ALLOCS
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(void) inc_count(PyTypeObject *);
|
2006-04-21 07:40:58 -03:00
|
|
|
PyAPI_FUNC(void) dec_count(PyTypeObject *);
|
2010-05-09 12:52:27 -03:00
|
|
|
#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 ,
|
2002-07-07 16:59:50 -03:00
|
|
|
#else
|
object.h special-build macro minefield: renamed all the new lexical
helper macros to something saner, and used them appropriately in other
files too, to reduce #ifdef blocks.
classobject.c, instance_dealloc(): One of my worst Python Memories is
trying to fix this routine a few years ago when COUNT_ALLOCS was defined
but Py_TRACE_REFS wasn't. The special-build code here is way too
complicated. Now it's much simpler. Difference: in a Py_TRACE_REFS
build, the instance is no longer in the doubly-linked list of live
objects while its __del__ method is executing, and that may be visible
via sys.getobjects() called from a __del__ method. Tough -- the object
is presumed dead while its __del__ is executing anyway, and not calling
_Py_NewReference() at the start allows enormous code simplification.
typeobject.c, call_finalizer(): The special-build instance_dealloc()
pain apparently spread to here too via cut-'n-paste, and this is much
simpler now too. In addition, I didn't understand why this routine
was calling _PyObject_GC_TRACK() after a resurrection, since there's no
plausible way _PyObject_GC_UNTRACK() could have been called on the
object by this point. I suspect it was left over from pasting the
instance_delloc() code. Instead asserted that the object is still
tracked. Caution: I suspect we don't have a test that actually
exercises the subtype_dealloc() __del__-resurrected-me code.
2002-07-11 03:23:50 -03:00
|
|
|
#define _Py_INC_TPALLOCS(OP)
|
|
|
|
#define _Py_INC_TPFREES(OP)
|
|
|
|
#define _Py_DEC_TPFREES(OP)
|
|
|
|
#define _Py_COUNT_ALLOCS_COMMA
|
2002-07-10 03:34:15 -03:00
|
|
|
#endif /* COUNT_ALLOCS */
|
1990-10-14 09:07:46 -03:00
|
|
|
|
1996-08-12 18:31:32 -03:00
|
|
|
#ifdef Py_TRACE_REFS
|
2002-07-07 16:59:50 -03:00
|
|
|
/* Py_TRACE_REFS is such major surgery that we call external routines. */
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(void) _Py_NewReference(PyObject *);
|
|
|
|
PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);
|
|
|
|
PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
|
|
|
|
PyAPI_FUNC(void) _Py_PrintReferences(FILE *);
|
2003-04-17 16:52:29 -03:00
|
|
|
PyAPI_FUNC(void) _Py_PrintReferenceAddresses(FILE *);
|
2003-03-23 13:52:28 -04:00
|
|
|
PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2002-07-07 16:59:50 -03:00
|
|
|
#else
|
|
|
|
/* Without Py_TRACE_REFS, there's little enough to do that we expand code
|
|
|
|
* inline.
|
|
|
|
*/
|
2010-05-09 12:52:27 -03:00
|
|
|
#define _Py_NewReference(op) ( \
|
|
|
|
_Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA \
|
|
|
|
_Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
|
|
|
|
Py_REFCNT(op) = 1)
|
1993-10-11 09:54:31 -03:00
|
|
|
|
object.h special-build macro minefield: renamed all the new lexical
helper macros to something saner, and used them appropriately in other
files too, to reduce #ifdef blocks.
classobject.c, instance_dealloc(): One of my worst Python Memories is
trying to fix this routine a few years ago when COUNT_ALLOCS was defined
but Py_TRACE_REFS wasn't. The special-build code here is way too
complicated. Now it's much simpler. Difference: in a Py_TRACE_REFS
build, the instance is no longer in the doubly-linked list of live
objects while its __del__ method is executing, and that may be visible
via sys.getobjects() called from a __del__ method. Tough -- the object
is presumed dead while its __del__ is executing anyway, and not calling
_Py_NewReference() at the start allows enormous code simplification.
typeobject.c, call_finalizer(): The special-build instance_dealloc()
pain apparently spread to here too via cut-'n-paste, and this is much
simpler now too. In addition, I didn't understand why this routine
was calling _PyObject_GC_TRACK() after a resurrection, since there's no
plausible way _PyObject_GC_UNTRACK() could have been called on the
object by this point. I suspect it was left over from pasting the
instance_delloc() code. Instead asserted that the object is still
tracked. Caution: I suspect we don't have a test that actually
exercises the subtype_dealloc() __del__-resurrected-me code.
2002-07-11 03:23:50 -03:00
|
|
|
#define _Py_ForgetReference(op) _Py_INC_TPFREES(op)
|
1996-05-22 13:33:22 -03:00
|
|
|
|
2010-12-03 16:14:31 -04:00
|
|
|
#ifdef Py_LIMITED_API
|
|
|
|
PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
|
|
|
|
#else
|
2010-05-09 12:52:27 -03:00
|
|
|
#define _Py_Dealloc(op) ( \
|
|
|
|
_Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \
|
|
|
|
(*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))
|
2010-12-03 16:14:31 -04:00
|
|
|
#endif
|
1996-05-22 13:33:22 -03:00
|
|
|
#endif /* !Py_TRACE_REFS */
|
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
#define Py_INCREF(op) ( \
|
|
|
|
_Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
|
2013-05-27 18:46:14 -03:00
|
|
|
((PyObject *)(op))->ob_refcnt++)
|
2002-07-07 16:59:50 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
#define Py_DECREF(op) \
|
|
|
|
do { \
|
2013-05-27 18:46:14 -03:00
|
|
|
PyObject *_py_decref_tmp = (PyObject *)(op); \
|
2010-05-09 12:52:27 -03:00
|
|
|
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
|
2013-05-27 18:46:14 -03:00
|
|
|
--(_py_decref_tmp)->ob_refcnt != 0) \
|
|
|
|
_Py_CHECK_REFCNT(_py_decref_tmp) \
|
2010-05-09 12:52:27 -03:00
|
|
|
else \
|
2013-05-27 18:46:14 -03:00
|
|
|
_Py_Dealloc(_py_decref_tmp); \
|
2010-05-09 12:52:27 -03:00
|
|
|
} while (0)
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2006-04-21 07:40:58 -03:00
|
|
|
/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
|
2015-04-14 03:30:01 -03:00
|
|
|
* and tp_dealloc implementations.
|
2006-04-21 07:40:58 -03:00
|
|
|
*
|
|
|
|
* Note that "the obvious" code can be deadly:
|
|
|
|
*
|
|
|
|
* Py_XDECREF(op);
|
|
|
|
* op = NULL;
|
|
|
|
*
|
|
|
|
* Typically, `op` is something like self->containee, and `self` is done
|
|
|
|
* using its `containee` member. In the code sequence above, suppose
|
|
|
|
* `containee` is non-NULL with a refcount of 1. Its refcount falls to
|
|
|
|
* 0 on the first line, which can trigger an arbitrary amount of code,
|
|
|
|
* possibly including finalizers (like __del__ methods or weakref callbacks)
|
|
|
|
* coded in Python, which in turn can release the GIL and allow other threads
|
|
|
|
* to run, etc. Such code may even invoke methods of `self` again, or cause
|
|
|
|
* cyclic gc to trigger, but-- oops! --self->containee still points to the
|
|
|
|
* object being torn down, and it may be in an insane state while being torn
|
|
|
|
* down. This has in fact been a rich historic source of miserable (rare &
|
|
|
|
* hard-to-diagnose) segfaulting (and other) bugs.
|
|
|
|
*
|
|
|
|
* The safe way is:
|
|
|
|
*
|
|
|
|
* Py_CLEAR(op);
|
|
|
|
*
|
|
|
|
* That arranges to set `op` to NULL _before_ decref'ing, so that any code
|
|
|
|
* triggered as a side-effect of `op` getting torn down no longer believes
|
|
|
|
* `op` points to a valid object.
|
|
|
|
*
|
|
|
|
* There are cases where it's safe to use the naive code, but they're brittle.
|
|
|
|
* For example, if `op` points to a Python integer, you know that destroying
|
|
|
|
* one of those can't cause problems -- but in part that relies on that
|
|
|
|
* Python integers aren't currently weakly referencable. Best practice is
|
|
|
|
* to use Py_CLEAR() even if you can't think of a reason for why you need to.
|
|
|
|
*/
|
2010-05-09 12:52:27 -03:00
|
|
|
#define Py_CLEAR(op) \
|
|
|
|
do { \
|
2013-05-27 18:46:14 -03:00
|
|
|
PyObject *_py_tmp = (PyObject *)(op); \
|
|
|
|
if (_py_tmp != NULL) { \
|
2010-05-09 12:52:27 -03:00
|
|
|
(op) = NULL; \
|
|
|
|
Py_DECREF(_py_tmp); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2004-07-14 16:07:35 -03:00
|
|
|
|
1990-12-20 11:06:42 -04:00
|
|
|
/* Macros to use in case the object pointer may be NULL: */
|
2013-05-27 18:46:14 -03:00
|
|
|
#define Py_XINCREF(op) \
|
|
|
|
do { \
|
|
|
|
PyObject *_py_xincref_tmp = (PyObject *)(op); \
|
|
|
|
if (_py_xincref_tmp != NULL) \
|
|
|
|
Py_INCREF(_py_xincref_tmp); \
|
2013-11-06 17:41:44 -04:00
|
|
|
} while (0)
|
2013-05-27 18:46:14 -03:00
|
|
|
|
|
|
|
#define Py_XDECREF(op) \
|
|
|
|
do { \
|
|
|
|
PyObject *_py_xdecref_tmp = (PyObject *)(op); \
|
|
|
|
if (_py_xdecref_tmp != NULL) \
|
|
|
|
Py_DECREF(_py_xdecref_tmp); \
|
|
|
|
} while (0)
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2004-04-22 14:23:49 -03:00
|
|
|
/*
|
|
|
|
These are provided as conveniences to Python runtime embedders, so that
|
|
|
|
they can have object code that is not dependent on Python compilation flags.
|
|
|
|
*/
|
|
|
|
PyAPI_FUNC(void) Py_IncRef(PyObject *);
|
|
|
|
PyAPI_FUNC(void) Py_DecRef(PyObject *);
|
|
|
|
|
2013-11-30 21:55:48 -04:00
|
|
|
PyAPI_DATA(PyTypeObject) _PyNone_Type;
|
|
|
|
PyAPI_DATA(PyTypeObject) _PyNotImplemented_Type;
|
2013-11-30 20:06:39 -04:00
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/*
|
1995-01-12 07:45:45 -04:00
|
|
|
_Py_NoneStruct is an object of undefined type which can be used in contexts
|
1990-10-14 09:07:46 -03:00
|
|
|
where NULL (nil) is not suitable (since NULL often means 'error').
|
|
|
|
|
1995-01-12 07:45:45 -04:00
|
|
|
Don't forget to apply Py_INCREF() when returning this value!!!
|
1990-10-14 09:07:46 -03:00
|
|
|
*/
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
|
1995-01-12 07:45:45 -04:00
|
|
|
#define Py_None (&_Py_NoneStruct)
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2003-10-19 18:19:40 -03:00
|
|
|
/* Macro for returning Py_None from a function */
|
2004-07-21 22:46:43 -03:00
|
|
|
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
|
2003-10-19 18:19:40 -03:00
|
|
|
|
2001-01-03 21:31:50 -04:00
|
|
|
/*
|
|
|
|
Py_NotImplemented is a singleton used to signal that an operation is
|
|
|
|
not implemented for a given type combination.
|
|
|
|
*/
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
|
2001-01-03 21:31:50 -04:00
|
|
|
#define Py_NotImplemented (&_Py_NotImplementedStruct)
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2011-08-10 22:05:21 -03:00
|
|
|
/* Macro for returning Py_NotImplemented from a function */
|
|
|
|
#define Py_RETURN_NOTIMPLEMENTED \
|
|
|
|
return Py_INCREF(Py_NotImplemented), Py_NotImplemented
|
|
|
|
|
2001-01-17 11:20:39 -04:00
|
|
|
/* Rich comparison opcodes */
|
|
|
|
#define Py_LT 0
|
|
|
|
#define Py_LE 1
|
|
|
|
#define Py_EQ 2
|
|
|
|
#define Py_NE 3
|
|
|
|
#define Py_GT 4
|
|
|
|
#define Py_GE 5
|
|
|
|
|
2004-09-22 23:39:37 -03:00
|
|
|
/* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
|
|
|
|
* Defined in object.c.
|
|
|
|
*/
|
|
|
|
PyAPI_DATA(int) _Py_SwappedOp[];
|
|
|
|
|
1994-08-01 08:34:53 -03:00
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/*
|
|
|
|
More conventions
|
|
|
|
================
|
|
|
|
|
|
|
|
Argument Checking
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
Functions that take objects as arguments normally don't check for nil
|
|
|
|
arguments, but they do check the type of the argument, and return an
|
|
|
|
error if the function doesn't apply to the type.
|
|
|
|
|
|
|
|
Failure Modes
|
|
|
|
-------------
|
|
|
|
|
|
|
|
Functions may fail for a variety of reasons, including running out of
|
1990-12-20 11:06:42 -04:00
|
|
|
memory. This is communicated to the caller in two ways: an error string
|
|
|
|
is set (see errors.h), and the function result differs: functions that
|
|
|
|
normally return a pointer return NULL for failure, functions returning
|
|
|
|
an integer return -1 (which could be a legal return value too!), and
|
|
|
|
other functions return 0 for success and -1 for failure.
|
2002-07-07 16:59:50 -03:00
|
|
|
Callers should always check for errors before using the result. If
|
|
|
|
an error was set, the caller must either explicitly clear it, or pass
|
|
|
|
the error on to its caller.
|
1990-10-14 09:07:46 -03:00
|
|
|
|
|
|
|
Reference Counts
|
|
|
|
----------------
|
|
|
|
|
|
|
|
It takes a while to get used to the proper usage of reference counts.
|
|
|
|
|
|
|
|
Functions that create an object set the reference count to 1; such new
|
1995-01-12 07:45:45 -04:00
|
|
|
objects must be stored somewhere or destroyed again with Py_DECREF().
|
2003-11-09 12:38:39 -04:00
|
|
|
Some functions that 'store' objects, such as PyTuple_SetItem() and
|
|
|
|
PyList_SetItem(),
|
1990-10-14 09:07:46 -03:00
|
|
|
don't increment the reference count of the object, since the most
|
|
|
|
frequent use is to store a fresh object. Functions that 'retrieve'
|
2003-11-09 12:38:39 -04:00
|
|
|
objects, such as PyTuple_GetItem() and PyDict_GetItemString(), also
|
1995-01-12 07:45:45 -04:00
|
|
|
don't increment
|
1990-10-14 09:07:46 -03:00
|
|
|
the reference count, since most frequently the object is only looked at
|
|
|
|
quickly. Thus, to retrieve an object and store it again, the caller
|
1995-01-12 07:45:45 -04:00
|
|
|
must call Py_INCREF() explicitly.
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2003-11-09 12:38:39 -04:00
|
|
|
NOTE: functions that 'consume' a reference count, like
|
|
|
|
PyList_SetItem(), consume the reference even if the object wasn't
|
|
|
|
successfully stored, to simplify error handling.
|
1990-10-14 09:07:46 -03:00
|
|
|
|
|
|
|
It seems attractive to make other functions that take an object as
|
2003-11-09 12:38:39 -04:00
|
|
|
argument consume a reference count; however, this may quickly get
|
1990-10-14 09:07:46 -03:00
|
|
|
confusing (even the current practice is already confusing). Consider
|
1995-01-12 07:45:45 -04:00
|
|
|
it carefully, it may save lots of calls to Py_INCREF() and Py_DECREF() at
|
1990-10-14 09:07:46 -03:00
|
|
|
times.
|
|
|
|
*/
|
1993-07-28 06:05:47 -03:00
|
|
|
|
2000-03-13 12:01:29 -04:00
|
|
|
|
2002-07-07 02:13:56 -03:00
|
|
|
/* Trashcan mechanism, thanks to Christian Tismer.
|
2000-03-13 12:01:29 -04:00
|
|
|
|
2002-07-07 02:13:56 -03:00
|
|
|
When deallocating a container object, it's possible to trigger an unbounded
|
|
|
|
chain of deallocations, as each Py_DECREF in turn drops the refcount on "the
|
|
|
|
next" object in the chain to 0. This can easily lead to stack faults, and
|
|
|
|
especially in threads (which typically have less stack space to work with).
|
2000-03-13 12:01:29 -04:00
|
|
|
|
2002-07-07 02:13:56 -03:00
|
|
|
A container object that participates in cyclic gc can avoid this by
|
|
|
|
bracketing the body of its tp_dealloc function with a pair of macros:
|
|
|
|
|
|
|
|
static void
|
|
|
|
mytype_dealloc(mytype *p)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
... declarations go here ...
|
2002-07-07 02:13:56 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
PyObject_GC_UnTrack(p); // must untrack first
|
|
|
|
Py_TRASHCAN_SAFE_BEGIN(p)
|
|
|
|
... The body of the deallocator goes here, including all calls ...
|
|
|
|
... to Py_DECREF on contained objects. ...
|
|
|
|
Py_TRASHCAN_SAFE_END(p)
|
2002-07-07 02:13:56 -03:00
|
|
|
}
|
|
|
|
|
2002-08-07 17:53:05 -03:00
|
|
|
CAUTION: Never return from the middle of the body! If the body needs to
|
|
|
|
"get out early", put a label immediately before the Py_TRASHCAN_SAFE_END
|
|
|
|
call, and goto it. Else the call-depth counter (see below) will stay
|
|
|
|
above 0 forever, and the trashcan will never get emptied.
|
|
|
|
|
2002-07-07 02:13:56 -03:00
|
|
|
How it works: The BEGIN macro increments a call-depth counter. So long
|
|
|
|
as this counter is small, the body of the deallocator is run directly without
|
|
|
|
further ado. But if the counter gets large, it instead adds p to a list of
|
|
|
|
objects to be deallocated later, skips the body of the deallocator, and
|
|
|
|
resumes execution after the END macro. The tp_dealloc routine then returns
|
|
|
|
without deallocating anything (and so unbounded call-stack depth is avoided).
|
|
|
|
|
|
|
|
When the call stack finishes unwinding again, code generated by the END macro
|
|
|
|
notices this, and calls another routine to deallocate all the objects that
|
|
|
|
may have been added to the list of deferred deallocations. In effect, a
|
|
|
|
chain of N deallocations is broken into N / PyTrash_UNWIND_LEVEL pieces,
|
|
|
|
with the call stack never exceeding a depth of PyTrash_UNWIND_LEVEL.
|
|
|
|
*/
|
2000-03-13 12:01:29 -04:00
|
|
|
|
2012-09-05 19:59:49 -03:00
|
|
|
/* This is the old private API, invoked by the macros before 3.2.4.
|
2012-09-05 20:17:42 -03:00
|
|
|
Kept for binary compatibility of extensions using the stable ABI. */
|
2002-07-29 10:42:14 -03:00
|
|
|
PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*);
|
|
|
|
PyAPI_FUNC(void) _PyTrash_destroy_chain(void);
|
|
|
|
PyAPI_DATA(int) _PyTrash_delete_nesting;
|
|
|
|
PyAPI_DATA(PyObject *) _PyTrash_delete_later;
|
2000-03-13 12:01:29 -04:00
|
|
|
|
2012-09-05 19:59:49 -03:00
|
|
|
/* The new thread-safe private API, invoked by the macros below. */
|
|
|
|
PyAPI_FUNC(void) _PyTrash_thread_deposit_object(PyObject*);
|
|
|
|
PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void);
|
|
|
|
|
2002-07-07 02:13:56 -03:00
|
|
|
#define PyTrash_UNWIND_LEVEL 50
|
2000-03-13 12:01:29 -04:00
|
|
|
|
2002-07-07 02:13:56 -03:00
|
|
|
#define Py_TRASHCAN_SAFE_BEGIN(op) \
|
2012-09-05 19:59:49 -03:00
|
|
|
do { \
|
|
|
|
PyThreadState *_tstate = PyThreadState_GET(); \
|
|
|
|
if (_tstate->trash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
|
|
|
|
++_tstate->trash_delete_nesting;
|
|
|
|
/* The body of the deallocator is here. */
|
2002-07-07 02:13:56 -03:00
|
|
|
#define Py_TRASHCAN_SAFE_END(op) \
|
2012-09-05 19:59:49 -03:00
|
|
|
--_tstate->trash_delete_nesting; \
|
|
|
|
if (_tstate->trash_delete_later && _tstate->trash_delete_nesting <= 0) \
|
|
|
|
_PyTrash_thread_destroy_chain(); \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
_PyTrash_thread_deposit_object((PyObject*)op); \
|
|
|
|
} while (0);
|
2000-04-24 12:40:53 -03:00
|
|
|
|
2012-06-22 15:55:41 -03:00
|
|
|
#ifndef Py_LIMITED_API
|
|
|
|
PyAPI_FUNC(void)
|
|
|
|
_PyDebugAllocatorStats(FILE *out, const char *block_name, int num_blocks,
|
|
|
|
size_t sizeof_block);
|
|
|
|
PyAPI_FUNC(void)
|
|
|
|
_PyObject_DebugTypeStats(FILE *out);
|
|
|
|
#endif /* ifndef Py_LIMITED_API */
|
|
|
|
|
1993-07-28 06:05:47 -03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* !Py_OBJECT_H */
|