タプルオブジェクト (tuple object)¶
-
PyTypeObject PyTuple_Type¶
- Part of the Stable ABI.
この
PyTypeObject
のインスタンスは Python のタプル型を表現します; Python レイヤにおけるtuple
と同じオブジェクトです。
-
PyObject *PyTuple_New(Py_ssize_t len)¶
- Return value: New reference. Part of the Stable ABI.
サイズが len の新たなタプルオブジェクトを返します。失敗すると
NULL
を返します。
-
PyObject *PyTuple_Pack(Py_ssize_t n, ...)¶
- Return value: New reference. Part of the Stable ABI.
サイズが n の新たなタプルオブジェクトを返します。失敗すると
NULL
を返します。タプルの値は後続の n 個の Python オブジェクトを指す C 引数になります。PyTuple_Pack(2, a, b)
はPy_BuildValue("(OO)", a, b)
と同じです。
-
Py_ssize_t PyTuple_Size(PyObject *p)¶
- Part of the Stable ABI.
タプルオブジェクトへのポインタを引数にとり、そのタプルのサイズを返します。
-
Py_ssize_t PyTuple_GET_SIZE(PyObject *p)¶
タプル p のサイズを返しますが、p は非
NULL
でなくてはならず、タプルオブジェクトを指していなければなりません; この関数はエラーチェックを行いません。
-
PyObject *PyTuple_GetItem(PyObject *p, Py_ssize_t pos)¶
- Return value: Borrowed reference. Part of the Stable ABI.
p の指すタプルオブジェクト内の、位置 pos にあるオブジェクトを返します。 pos が負であるか範囲を超えている場合、
NULL
を返してIndexError
例外をセットします。
-
PyObject *PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)¶
- Return value: Borrowed reference.
PyTuple_GetItem()
に似ていますが、引数に対するエラーチェックを行いません。
-
PyObject *PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)¶
- Return value: New reference. Part of the Stable ABI.
Return the slice of the tuple pointed to by p between low and high, or
NULL
on failure. This is the equivalent of the Python expressionp[low:high]
. Indexing from the end of the list is not supported.
-
int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)¶
- Part of the Stable ABI.
p の指すタプルオブジェクト内の、位置 pos にあるオブジェクトへの参照を入れます。成功すれば
0
を返します。 pos が範囲を超えている場合、-1
を返してIndexError
例外をセットします。注釈
この関数は o への参照を "盗み取り" ます。また、変更先のインデクスにすでに別の要素が入っている場合、その要素に対する参照を放棄します。
-
void PyTuple_SET_ITEM(PyObject *p, Py_ssize_t pos, PyObject *o)¶
PyTuple_SetItem()
に似ていますが、エラーチェックを行わず、新たなタプルに値を入れるとき 以外には使ってはなりません 。注釈
この関数は o への参照を "盗み取り" ます。また、
PyTuple_SetItem()
と違って、要素の置き換えが生じても置き換えられるオブジェクトへの参照を放棄 しません ; その結果、タプル中の位置 pos で参照されていたオブジェクトがメモリリークを引き起こします。
-
int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize)¶
タプルをリサイズする際に使えます。 newsize はタプルの新たな長さです。タプルは変更不能なオブジェクト ということになっている ので、この関数はこのオブジェクトに対してただ一つしか参照がない時以外には使ってはなりません。タプルがコード中の他の部分ですでに参照されている場合には、この関数を 使ってはなりません 。タプルは常に指定サイズの末尾まで伸縮します。成功した場合には
0
を返します。クライアントコードは、*p
の値が呼び出し前と同じになると期待してはなりません。*p
が置き換えられた場合、オリジナルの*p
は破壊されます。失敗すると-1
を返し、*p
をNULL
に設定して、MemoryError
またはSystemError
を送出します。
Struct Sequence オブジェクト¶
struct sequence オブジェクトは namedtuple()
オブジェクトと等価なC オブジェクトです。 つまり、その要素に属性を通してアクセスすることができるシーケンスです。 struct sequence を生成するには、まず特定のstruct sequence 型を生成しなければなりません。
-
PyTypeObject *PyStructSequence_NewType(PyStructSequence_Desc *desc)¶
- Return value: New reference. Part of the Stable ABI.
後述の desc 中のデータから新しい struct sequence 型を生成します。返される型のインスタンスは
PyStructSequence_New()
で生成できます。
-
void PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)¶
struct sequence 型である type を desc をもとにその場で初期化します。
-
int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)¶
PyStructSequence_InitType
と同じですが、成功した場合には0
を、失敗した場合には-1
を返します。バージョン 3.4 で追加.
-
type PyStructSequence_Desc¶
- Part of the Stable ABI (including all members).
生成するstruct sequence 型のメタデータを保持します。
-
const char *name¶
Name of the struct sequence type.
-
const char *doc¶
Pointer to docstring for the type or
NULL
to omit.
-
PyStructSequence_Field *fields¶
Pointer to
NULL
-terminated array with field names of the new type.
-
int n_in_sequence¶
Number of fields visible to the Python side (if used as tuple).
-
const char *name¶
-
type PyStructSequence_Field¶
- Part of the Stable ABI (including all members).
Describes a field of a struct sequence. As a struct sequence is modeled as a tuple, all fields are typed as PyObject*. The index in the
fields
array of thePyStructSequence_Desc
determines which field of the struct sequence is described.-
const char *name¶
Name for the field or
NULL
to end the list of named fields, set toPyStructSequence_UnnamedField
to leave unnamed.
-
const char *doc¶
Field docstring or
NULL
to omit.
-
const char *name¶
-
const char *const PyStructSequence_UnnamedField¶
- Part of the Stable ABI since version 3.11.
フィールド名を名前がないままするための特殊な値。
バージョン 3.9 で変更: 型が
char *
から変更されました。
-
PyObject *PyStructSequence_New(PyTypeObject *type)¶
- Return value: New reference. Part of the Stable ABI.
type のインスタンスを生成します。 type は
PyStructSequence_NewType()
によって事前に生成していなければなりません。
-
PyObject *PyStructSequence_GetItem(PyObject *p, Py_ssize_t pos)¶
- Return value: Borrowed reference. Part of the Stable ABI.
p の指すstruct sequence内の、位置 pos にあるオブジェクトを返します。境界チェックを行いません。
-
PyObject *PyStructSequence_GET_ITEM(PyObject *p, Py_ssize_t pos)¶
- Return value: Borrowed reference.
PyStructSequence_GetItem()
と同等のマクロです。
-
void PyStructSequence_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)¶
- Part of the Stable ABI.
struct sequence p の pos の位置にあるフィールドに値 o を設定します。
PyTuple_SET_ITEM()
のように、生成したてのインスタンスに対してのみ使用すべきです。注釈
この関数は o への参照を "盗み取り" ます。
-
void PyStructSequence_SET_ITEM(PyObject *p, Py_ssize_t *pos, PyObject *o)¶
Similar to
PyStructSequence_SetItem()
, but implemented as a static inlined function.注釈
この関数は o への参照を "盗み取り" ます。