Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
ae30a813
Kaydet (Commit)
ae30a813
authored
Eki 12, 2013
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Closes #13833: document PyStructSequence C-API functions.
üst
c96ef1f0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
+100
-0
tuple.rst
Doc/c-api/tuple.rst
+100
-0
No files found.
Doc/c-api/tuple.rst
Dosyayı görüntüle @
ae30a813
...
...
@@ -108,3 +108,103 @@ Tuple Objects
.. c:function:: int PyTuple_ClearFreeList()
Clear the free list. Return the total number of freed items.
Struct Sequence Objects
-----------------------
Struct sequence objects are the C equivalent of :func:`~collections.namedtuple`
objects, i.e. a sequence whose items can also be accessed through attributes.
To create a struct sequence, you first have to create a specific struct sequence
type.
.. c:function:: PyTypeObject* PyStructSequence_NewType(PyStructSequence_Desc *desc)
Create a new struct sequence type from the data in *desc*, described below. Instances
of the resulting type can be created with :c:func:`PyStructSequence_New`.
.. c:function:: void PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
Initializes a struct sequence type *type* from *desc* in place.
.. c:type:: PyStructSequence_Desc
Contains the meta information of a struct sequence type to create.
+-------------------+------------------------------+------------------------------------+
| Field | C Type | Meaning |
+===================+==============================+====================================+
| ``name`` | ``char *`` | name of the struct sequence type |
+-------------------+------------------------------+------------------------------------+
| ``doc`` | ``char *`` | pointer to docstring for the type |
| | | or NULL to omit |
+-------------------+------------------------------+------------------------------------+
| ``fields`` | ``PyStructSequence_Field *`` | pointer to *NULL*-terminated array |
| | | with field names of the new type |
+-------------------+------------------------------+------------------------------------+
| ``n_in_sequence`` | ``int`` | number of fields visible to the |
| | | Python side (if used as tuple) |
+-------------------+------------------------------+------------------------------------+
.. c:type:: PyStructSequence_Field
Describes a field of a struct sequence. As a struct sequence is modeled as a
tuple, all fields are typed as :c:type:`PyObject\*`. The index in the
:attr:`fields` array of the :c:type:`PyStructSequence_Desc` determines which
field of the struct sequence is described.
+-----------+---------------+--------------------------------------+
| Field | C Type | Meaning |
+===========+===============+======================================+
| ``name`` | ``char *`` | name for the field or *NULL* to end |
| | | the list of named fields, set to |
| | | PyStructSequence_UnnamedField to |
| | | leave unnamed |
+-----------+---------------+--------------------------------------+
| ``doc`` | ``char *`` | field docstring or *NULL* to omit |
+-----------+---------------+--------------------------------------+
.. c:var:: char* PyStructSequence_UnnamedField
Special value for a field name to leave it unnamed.
.. c:function:: PyObject* PyStructSequence_New(PyTypeObject *type)
Creates an instance of *type*, which must have been created with
:c:func:`PyStructSequence_NewType`.
.. c:function:: PyObject* PyStructSequence_GetItem(PyObject *p, Py_ssize_t pos)
Return the object at position *pos* in the struct sequence pointed to by *p*.
No bounds checking is performed.
.. c:function:: PyObject* PyStructSequence_GET_ITEM(PyObject *p, Py_ssize_t pos)
Macro equivalent of :c:func:`PyStructSequence_GetItem`.
.. c:function:: void PyStructSequence_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
Sets the field at index *pos* of the struct sequence *p* to value *o*. Like
:c:func:`PyTuple_SET_ITEM`, this should only be used to fill in brand new
instances.
.. note::
This function "steals" a reference to *o*.
.. c:function:: PyObject* PyStructSequence_SET_ITEM(PyObject *p, Py_ssize_t *pos, PyObject *o)
Macro equivalent of :c:func:`PyStructSequence_SetItem`.
.. note::
This function "steals" a reference to *o*.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment