Skip to content

Add HPy_(Get|Set|Del)Slice #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/api-reference/function-index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ HPy Core API Function Index
* :c:func:`HPy_DelItem`
* :c:func:`HPy_DelItem_i`
* :c:func:`HPy_DelItem_s`
* :c:func:`HPy_DelSlice`
* :c:func:`HPy_Divmod`
* :c:func:`HPy_Dup`
* :c:func:`HPy_EvalCode`
Expand All @@ -130,6 +131,7 @@ HPy Core API Function Index
* :c:func:`HPy_GetItem`
* :c:func:`HPy_GetItem_i`
* :c:func:`HPy_GetItem_s`
* :c:func:`HPy_GetSlice`
* :c:func:`HPy_HasAttr`
* :c:func:`HPy_HasAttr_s`
* :c:func:`HPy_Hash`
Expand Down Expand Up @@ -172,6 +174,7 @@ HPy Core API Function Index
* :c:func:`HPy_SetItem`
* :c:func:`HPy_SetItem_i`
* :c:func:`HPy_SetItem_s`
* :c:func:`HPy_SetSlice`
* :c:func:`HPy_Str`
* :c:func:`HPy_Subtract`
* :c:func:`HPy_TrueDivide`
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/hpy-object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ HPy Object
==========

.. autocmodule:: autogen/public_api.h
:members: HPy_IsTrue,HPy_GetAttr,HPy_GetAttr_s,HPy_HasAttr,HPy_HasAttr_s,HPy_SetAttr,HPy_SetAttr_s,HPy_GetItem,HPy_GetItem_s,HPy_GetItem_i,HPy_SetItem,HPy_SetItem_s,HPy_SetItem_i,HPy_DelItem,HPy_DelItem_s,HPy_DelItem_i,HPy_Type,HPy_TypeCheck,HPy_Is,HPy_Repr,HPy_Str,HPy_ASCII,HPy_Bytes,HPy_RichCompare,HPy_RichCompareBool,HPy_Hash,HPy_SetCallFunction
:members: HPy_IsTrue,HPy_GetAttr,HPy_GetAttr_s,HPy_HasAttr,HPy_HasAttr_s,HPy_SetAttr,HPy_SetAttr_s,HPy_GetItem,HPy_GetItem_s,HPy_GetItem_i,HPy_GetSlice,HPy_SetItem,HPy_SetItem_s,HPy_SetItem_i,HPy_SetSlice,HPy_DelItem,HPy_DelItem_s,HPy_DelItem_i,HPy_DelSlice,HPy_Type,HPy_TypeCheck,HPy_Is,HPy_Repr,HPy_Str,HPy_ASCII,HPy_Bytes,HPy_RichCompare,HPy_RichCompareBool,HPy_Hash,HPy_SetCallFunction
3 changes: 3 additions & 0 deletions docs/porting-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ with the code for the :term:`CPython ABI` mode, so it is guaranteed to be correc
`PyObject_Vectorcall <https://docs.python.org/3/c-api/call.html#c.PyObject_Vectorcall>`_ :c:func:`HPy_Call`
`PyObject_VectorcallMethod <https://docs.python.org/3/c-api/call.html#c.PyObject_VectorcallMethod>`_ :c:func:`HPy_CallMethod`
`PySequence_Contains <https://docs.python.org/3/c-api/sequence.html#c.PySequence_Contains>`_ :c:func:`HPy_Contains`
`PySequence_DelSlice <https://docs.python.org/3/c-api/sequence.html#c.PySequence_DelSlice>`_ :c:func:`HPy_DelSlice`
`PySequence_GetSlice <https://docs.python.org/3/c-api/sequence.html#c.PySequence_GetSlice>`_ :c:func:`HPy_GetSlice`
`PySequence_SetSlice <https://docs.python.org/3/c-api/sequence.html#c.PySequence_SetSlice>`_ :c:func:`HPy_SetSlice`
`PySlice_AdjustIndices <https://docs.python.org/3/c-api/slice.html#c.PySlice_AdjustIndices>`_ :c:func:`HPySlice_AdjustIndices`
`PySlice_Unpack <https://docs.python.org/3/c-api/slice.html#c.PySlice_Unpack>`_ :c:func:`HPySlice_Unpack`
`PyTuple_Check <https://docs.python.org/3/c-api/tuple.html#c.PyTuple_Check>`_ :c:func:`HPyTuple_Check`
Expand Down
6 changes: 6 additions & 0 deletions hpy/debug/src/autogen_debug_ctx_init.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions hpy/debug/src/autogen_debug_wrappers.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions hpy/devel/include/hpy/cpython/autogen_api_impl.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions hpy/devel/include/hpy/universal/autogen_ctx.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions hpy/devel/include/hpy/universal/autogen_trampolines.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions hpy/tools/autogen/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@
'HPy_GetItem': 'PyObject_GetItem',
'HPy_GetItem_i': None,
'HPy_GetItem_s': None,
'HPy_GetSlice': 'PySequence_GetSlice',
'HPy_SetItem': 'PyObject_SetItem',
'HPy_SetItem_i': None,
'HPy_SetItem_s': None,
'HPy_SetSlice': 'PySequence_SetSlice',
'HPy_DelItem': 'PyObject_DelItem',
'HPy_DelItem_i': None,
'HPy_DelItem_s': None,
'HPy_DelSlice': 'PySequence_DelSlice',
'HPy_Contains': 'PySequence_Contains',
'HPy_Length': 'PyObject_Length',
'HPy_CallTupleDict': None,
Expand Down
66 changes: 66 additions & 0 deletions hpy/tools/autogen/public_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,27 @@ HPy HPy_GetItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx);
HPy_ID(160)
HPy HPy_GetItem_s(HPyContext *ctx, HPy obj, const char *utf8_key);

/**
* Return the slice of sequence object ``obj`` between ``start`` and ``end``.
* This is the equivalent of the Python expression ``obj[start:end]``.
*
* :param ctx:
* The execution context.
* :param obj:
* A sliceable Python object (must not be ``HPy_NULL`` otherwise a
* ``SystemError`` will be raised). If the object is not sliceable, a
* ``TypeError`` will be raised.
* :param start:
* The start index (inclusive).
* :param end:
* The end index (exclusive).
*
* :returns:
* The requested slice or ``HPy_NULL`` on failure.
*/
HPy_ID(266)
HPy HPy_GetSlice(HPyContext *ctx, HPy obj, HPy_ssize_t start, HPy_ssize_t end);

HPy_ID(161)
int HPy_Contains(HPyContext *ctx, HPy container, HPy key);

Expand All @@ -429,13 +450,58 @@ int HPy_SetItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx, HPy value);
HPy_ID(164)
int HPy_SetItem_s(HPyContext *ctx, HPy obj, const char *utf8_key, HPy value);

/**
* Assign the sequence object ``value`` to the slice in sequence object ``obj``
* from ``start`` to ``end``. This is the equivalent of the Python statement
* ``obj[start:end] = value``.
*
* :param ctx:
* The execution context.
* :param obj:
* A sliceable Python object (must not be ``HPy_NULL`` otherwise a
* ``SystemError`` will be raised). If the object is not sliceable, a
* ``TypeError`` will be raised.
* :param start:
* The start index (inclusive).
* :param end:
* The end index (exclusive).
* :param value:
* The sequence object to assign (must not be ``HPy_NULL``).
*
* :returns:
* ``0`` on success; ``-1`` on failure
*/
HPy_ID(267)
int HPy_SetSlice(HPyContext *ctx, HPy obj, HPy_ssize_t start, HPy_ssize_t end, HPy value);

HPy_ID(235)
int HPy_DelItem(HPyContext *ctx, HPy obj, HPy key);
HPy_ID(236)
int HPy_DelItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx);
HPy_ID(237)
int HPy_DelItem_s(HPyContext *ctx, HPy obj, const char *utf8_key);

/**
* Delete the slice of sequence object ``obj`` between ``start`` and ``end``.
* This is the equivalent of the Python statement ``del obj[start:end]``.
*
* :param ctx:
* The execution context.
* :param obj:
* A sliceable Python object (must not be ``HPy_NULL`` otherwise a
* ``SystemError`` will be raised). If the object is not sliceable, a
* ``TypeError`` will be raised.
* :param start:
* The start index (inclusive).
* :param end:
* The end index (exclusive).
*
* :returns:
* ``0`` on success; ``-1`` on failure
*/
HPy_ID(268)
int HPy_DelSlice(HPyContext *ctx, HPy obj, HPy_ssize_t start, HPy_ssize_t end);

/**
* Returns the type of the given object ``obj``.
*
Expand Down
10 changes: 8 additions & 2 deletions hpy/trace/src/autogen_trace_ctx_init.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions hpy/trace/src/autogen_trace_func_table.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading