src/newcore/Include/tupleobject.h
author Vijayan <ts.vijayan@nokia.com>
Tue, 16 Feb 2010 10:07:05 +0530
changeset 0 ca70ae20a155
permissions -rw-r--r--
Base Python2.0 code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
     1
/* Portions Copyright (c) 2008 Nokia Corporation */
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
     2
/* Tuple object interface */
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
     3
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
     4
#ifndef Py_TUPLEOBJECT_H
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
     5
#define Py_TUPLEOBJECT_H
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
     6
#ifdef __cplusplus
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
     7
extern "C" {
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
     8
#endif
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
     9
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    10
/*
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    11
Another generally useful object type is a tuple of object pointers.
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    12
For Python, this is an immutable type.  C code can change the tuple items
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    13
(but not their number), and even use tuples are general-purpose arrays of
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    14
object references, but in general only brand new tuples should be mutated,
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    15
not ones that might already have been exposed to Python code.
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    16
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    17
*** WARNING *** PyTuple_SetItem does not increment the new item's reference
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    18
count, but does decrement the reference count of the item it replaces,
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    19
if not nil.  It does *decrement* the reference count if it is *not*
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    20
inserted in the tuple.  Similarly, PyTuple_GetItem does not increment the
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    21
returned item's reference count.
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    22
*/
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    23
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    24
typedef struct {
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    25
    PyObject_VAR_HEAD
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    26
    PyObject *ob_item[1];
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    27
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    28
    /* ob_item contains space for 'ob_size' elements.
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    29
     * Items must normally not be NULL, except during construction when
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    30
     * the tuple is not yet visible outside the function that builds it.
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    31
     */
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    32
} PyTupleObject;
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    33
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    34
PyAPI_DATA(PyTypeObject, PyTuple_Type);
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    35
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    36
#define PyTuple_Check(op) PyObject_TypeCheck(op, &PyTuple_Type)
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    37
#define PyTuple_CheckExact(op) ((op)->ob_type == &PyTuple_Type)
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    38
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    39
PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size);
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    40
PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *);
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    41
PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t);
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    42
PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    43
PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    44
PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t);
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    45
PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    46
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    47
/* Macro, trading safety for speed */
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    48
#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    49
#define PyTuple_GET_SIZE(op)    (((PyTupleObject *)(op))->ob_size)
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    50
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    51
/* Macro, *only* to be used to fill in brand new tuples */
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    52
#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    53
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    54
#ifdef __cplusplus
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    55
}
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    56
#endif
ca70ae20a155 Base Python2.0 code
Vijayan <ts.vijayan@nokia.com>
parents:
diff changeset
    57
#endif /* !Py_TUPLEOBJECT_H */