Struct Sequences¶
Struct sequences are subclasses of tuple. Similar to the API for creating tuples, HPy provides an API to create struct sequences. This is a builder API such that the struct sequence is guaranteed not to be written after it is created.
Note
There is no specific getter function for struct sequences. Just use one of
HPy_GetItem(), HPy_GetItem_i(), or HPy_GetItem_s().
-
struct
HPyStructSequence_Field¶
[source] Describes a field of a struct sequence.
-
const char *
name¶
[source] Name (UTF-8 encoded) for the field or
NULLto end the list of named fields. Set the name toHPyStructSequence_UnnamedFieldto leave it unnamed.
-
const char *
-
struct
HPyStructSequence_Desc¶
[source] Contains the meta information of a struct sequence type to create. Struct sequences are subclasses of tuple. The index in the
fieldsarray of the descriptor determines which field of the struct sequence is described.-
HPyStructSequence_Field *
fields¶
[source] Pointer to
NULL-terminated array with field names of the new type (must not beNULL).
-
HPyStructSequence_Field *
-
extern const char *const
HPyStructSequence_UnnamedField¶
[source] A marker that can be used as struct sequence field name to indicate that a field should be anonymous (i.e. cannot be accessed by a name but only by numeric index).
-
HPy
HPyStructSequence_NewType(HPyContext *ctx, HPyStructSequence_Desc *desc)¶
[source] Create a new struct sequence type from a descriptor. Instances of the resulting type can be created with
HPyStructSequence_New().- Parameters
ctx – The execution context.
desc – The descriptor of the struct sequence type to create (must not be
NULL):
- Returns
A handle to the new struct sequence type or
HPy_NULLin case of errors.
-
HPy
HPyStructSequence_New(HPyContext *ctx, HPy type, HPy_ssize_t nargs, HPy *args)¶
[source] Creates a new instance of
typeinitializing it with the given arguments.Since struct sequences are immutable objects, they need to be initialized at instantiation. This function will create a fresh instance of the provided struct sequence type. The type must have been created with
HPyStructSequence_NewType().- Parameters
ctx – The execution context.
type – A struct sequence type (must not be
HPy_NULL). If the passed object is not a type, the behavior is undefined. If the given type is not appropriate, aTypeErrorwill be raised.nargs – The number of arguments in
args. If this argument is not exactly the number of fields of the struct sequence, aTypeErrorwill be raised.args – An array of HPy handles to Python objects to be used for initializing the struct sequence. If
nargs > 0then this argument must not beNULL.
- Returns
A new instance of
typeorHPy_NULLif an error occurred.