Skip to content

Commit

Permalink
Merge pull request #476 from Sachaa-Thanasius/feature/add_hpy_iter
Browse files Browse the repository at this point in the history
Add HPyIter_(Check|Next) and HPy_GetIter
  • Loading branch information
steve-s authored Mar 1, 2024
2 parents ef1eef1 + 0506ca2 commit 95c51b9
Show file tree
Hide file tree
Showing 16 changed files with 348 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/api-reference/function-index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ HPy Core API Function Index
* :c:func:`HPyGlobal_Load`
* :c:func:`HPyGlobal_Store`
* :c:func:`HPyImport_ImportModule`
* :c:func:`HPyIter_Check`
* :c:func:`HPyIter_Next`
* :c:func:`HPyListBuilder_Build`
* :c:func:`HPyListBuilder_Cancel`
* :c:func:`HPyListBuilder_New`
Expand Down Expand Up @@ -131,6 +133,7 @@ HPy Core API Function Index
* :c:func:`HPy_GetItem`
* :c:func:`HPy_GetItem_i`
* :c:func:`HPy_GetItem_s`
* :c:func:`HPy_GetIter`
* :c:func:`HPy_GetSlice`
* :c:func:`HPy_HasAttr`
* :c:func:`HPy_HasAttr_s`
Expand Down
3 changes: 3 additions & 0 deletions docs/porting-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ with the code for the :term:`CPython ABI` mode, so it is guaranteed to be correc
`PyFloat_AsDouble <https://docs.python.org/3/c-api/float.html#c.PyFloat_AsDouble>`_ :c:func:`HPyFloat_AsDouble`
`PyFloat_FromDouble <https://docs.python.org/3/c-api/float.html#c.PyFloat_FromDouble>`_ :c:func:`HPyFloat_FromDouble`
`PyImport_ImportModule <https://docs.python.org/3/c-api/import.html#c.PyImport_ImportModule>`_ :c:func:`HPyImport_ImportModule`
`PyIter_Check <https://docs.python.org/3/c-api/iter.html#c.PyIter_Check>`_ :c:func:`HPyIter_Check`
`PyIter_Next <https://docs.python.org/3/c-api/iter.html#c.PyIter_Next>`_ :c:func:`HPyIter_Next`
`PyList_Append <https://docs.python.org/3/c-api/list.html#c.PyList_Append>`_ :c:func:`HPyList_Append`
`PyList_Check <https://docs.python.org/3/c-api/list.html#c.PyList_Check>`_ :c:func:`HPyList_Check`
`PyList_Insert <https://docs.python.org/3/c-api/list.html#c.PyList_Insert>`_ :c:func:`HPyList_Insert`
Expand Down Expand Up @@ -252,6 +254,7 @@ with the code for the :term:`CPython ABI` mode, so it is guaranteed to be correc
`PyObject_GetAttr <https://docs.python.org/3/c-api/object.html#c.PyObject_GetAttr>`_ :c:func:`HPy_GetAttr`
`PyObject_GetAttrString <https://docs.python.org/3/c-api/object.html#c.PyObject_GetAttrString>`_ :c:func:`HPy_GetAttr_s`
`PyObject_GetItem <https://docs.python.org/3/c-api/object.html#c.PyObject_GetItem>`_ :c:func:`HPy_GetItem`
`PyObject_GetIter <https://docs.python.org/3/c-api/object.html#c.PyObject_GetIter>`_ :c:func:`HPy_GetIter`
`PyObject_HasAttr <https://docs.python.org/3/c-api/object.html#c.PyObject_HasAttr>`_ :c:func:`HPy_HasAttr`
`PyObject_HasAttrString <https://docs.python.org/3/c-api/object.html#c.PyObject_HasAttrString>`_ :c:func:`HPy_HasAttr_s`
`PyObject_Hash <https://docs.python.org/3/c-api/object.html#c.PyObject_Hash>`_ :c:func:`HPy_Hash`
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.

36 changes: 36 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 @@ -29,6 +29,7 @@
'HPy_HasAttr_s': 'PyObject_HasAttrString',
'HPy_SetAttr': 'PyObject_SetAttr',
'HPy_SetAttr_s': 'PyObject_SetAttrString',
'HPy_GetIter': 'PyObject_GetIter',
'HPy_GetItem': 'PyObject_GetItem',
'HPy_GetItem_i': None,
'HPy_GetItem_s': None,
Expand Down Expand Up @@ -107,6 +108,8 @@
'HPy_RichCompare': 'PyObject_RichCompare',
'HPy_RichCompareBool': 'PyObject_RichCompareBool',
'HPy_Hash': 'PyObject_Hash',
'HPyIter_Next': 'PyIter_Next',
'HPyIter_Check': 'PyIter_Check',
'HPyListBuilder_New': None,
'HPyListBuilder_Set': None,
'HPyListBuilder_Build': None,
Expand Down
49 changes: 49 additions & 0 deletions hpy/tools/autogen/public_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,55 @@ HPy HPy_Call(HPyContext *ctx, HPy callable, const HPy *args, size_t nargs, HPy k
HPy_ID(262)
HPy HPy_CallMethod(HPyContext *ctx, HPy name, const HPy *args, size_t nargs, HPy kwnames);

/**
* Return a new iterator for iterable object ``obj``. This is the equivalent
* of the Python expression ``iter(obj)``.
*
* :param ctx:
* The execution context.
* :param obj:
* An iterable Python object (must not be ``HPy_NULL``). If the object is
* not iterable, a ``TypeError`` will be raised.
*
* :returns:
* The new iterator, ``obj`` itself if it is already an iterator, or
* ``HPy_NULL`` on failure.
*/
HPy_ID(269)
HPy HPy_GetIter(HPyContext *ctx, HPy obj);

/**
* Return the next value from iterator ``obj``.
*
* :param ctx:
* The execution context.
* :param obj:
* An iterator Python object (must not be ``HPy_NULL``). This can be
* verified with ``HPy_IterCheck``. Otherwise, the behavior is undefined.
*
* :returns:
* The new value in iterator ``obj``, or ``HPy_NULL`` on failure. If the
* iterator was exhausted normally, an exception will not be set. In
* case of some other error, one will be set.
*/
HPy_ID(270)
HPy HPyIter_Next(HPyContext *ctx, HPy obj);

/**
* Tests if an object is an instance of a Python iterator.
*
* :param ctx:
* The execution context.
* :param obj:
* A handle to an arbitrary object (must not be ``HPy_NULL``).
*
* :returns:
* Non-zero if object ``obj`` provides the ``Iterator`` protocol, and ``0``
* otherwise.
*/
HPy_ID(271)
int HPyIter_Check(HPyContext *ctx, HPy obj);

/* pyerrors.h */
HPy_ID(136)
void HPy_FatalError(HPyContext *ctx, const char *message);
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.

39 changes: 39 additions & 0 deletions hpy/trace/src/autogen_trace_wrappers.c

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

3 changes: 3 additions & 0 deletions hpy/universal/src/autogen_ctx_def.h

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

15 changes: 15 additions & 0 deletions hpy/universal/src/autogen_ctx_impl.h

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

Loading

0 comments on commit 95c51b9

Please sign in to comment.