Skip to content

Commit 95c51b9

Browse files
authored
Merge pull request #476 from Sachaa-Thanasius/feature/add_hpy_iter
Add HPyIter_(Check|Next) and HPy_GetIter
2 parents ef1eef1 + 0506ca2 commit 95c51b9

16 files changed

+348
-4
lines changed

docs/api-reference/function-index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ HPy Core API Function Index
4848
* :c:func:`HPyGlobal_Load`
4949
* :c:func:`HPyGlobal_Store`
5050
* :c:func:`HPyImport_ImportModule`
51+
* :c:func:`HPyIter_Check`
52+
* :c:func:`HPyIter_Next`
5153
* :c:func:`HPyListBuilder_Build`
5254
* :c:func:`HPyListBuilder_Cancel`
5355
* :c:func:`HPyListBuilder_New`
@@ -131,6 +133,7 @@ HPy Core API Function Index
131133
* :c:func:`HPy_GetItem`
132134
* :c:func:`HPy_GetItem_i`
133135
* :c:func:`HPy_GetItem_s`
136+
* :c:func:`HPy_GetIter`
134137
* :c:func:`HPy_GetSlice`
135138
* :c:func:`HPy_HasAttr`
136139
* :c:func:`HPy_HasAttr_s`

docs/porting-guide.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ with the code for the :term:`CPython ABI` mode, so it is guaranteed to be correc
190190
`PyFloat_AsDouble <https://docs.python.org/3/c-api/float.html#c.PyFloat_AsDouble>`_ :c:func:`HPyFloat_AsDouble`
191191
`PyFloat_FromDouble <https://docs.python.org/3/c-api/float.html#c.PyFloat_FromDouble>`_ :c:func:`HPyFloat_FromDouble`
192192
`PyImport_ImportModule <https://docs.python.org/3/c-api/import.html#c.PyImport_ImportModule>`_ :c:func:`HPyImport_ImportModule`
193+
`PyIter_Check <https://docs.python.org/3/c-api/iter.html#c.PyIter_Check>`_ :c:func:`HPyIter_Check`
194+
`PyIter_Next <https://docs.python.org/3/c-api/iter.html#c.PyIter_Next>`_ :c:func:`HPyIter_Next`
193195
`PyList_Append <https://docs.python.org/3/c-api/list.html#c.PyList_Append>`_ :c:func:`HPyList_Append`
194196
`PyList_Check <https://docs.python.org/3/c-api/list.html#c.PyList_Check>`_ :c:func:`HPyList_Check`
195197
`PyList_Insert <https://docs.python.org/3/c-api/list.html#c.PyList_Insert>`_ :c:func:`HPyList_Insert`
@@ -252,6 +254,7 @@ with the code for the :term:`CPython ABI` mode, so it is guaranteed to be correc
252254
`PyObject_GetAttr <https://docs.python.org/3/c-api/object.html#c.PyObject_GetAttr>`_ :c:func:`HPy_GetAttr`
253255
`PyObject_GetAttrString <https://docs.python.org/3/c-api/object.html#c.PyObject_GetAttrString>`_ :c:func:`HPy_GetAttr_s`
254256
`PyObject_GetItem <https://docs.python.org/3/c-api/object.html#c.PyObject_GetItem>`_ :c:func:`HPy_GetItem`
257+
`PyObject_GetIter <https://docs.python.org/3/c-api/object.html#c.PyObject_GetIter>`_ :c:func:`HPy_GetIter`
255258
`PyObject_HasAttr <https://docs.python.org/3/c-api/object.html#c.PyObject_HasAttr>`_ :c:func:`HPy_HasAttr`
256259
`PyObject_HasAttrString <https://docs.python.org/3/c-api/object.html#c.PyObject_HasAttrString>`_ :c:func:`HPy_HasAttr_s`
257260
`PyObject_Hash <https://docs.python.org/3/c-api/object.html#c.PyObject_Hash>`_ :c:func:`HPy_Hash`

hpy/debug/src/autogen_debug_ctx_init.h

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/debug/src/autogen_debug_wrappers.c

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/devel/include/hpy/cpython/autogen_api_impl.h

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/devel/include/hpy/universal/autogen_ctx.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/devel/include/hpy/universal/autogen_trampolines.h

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/tools/autogen/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
'HPy_HasAttr_s': 'PyObject_HasAttrString',
3030
'HPy_SetAttr': 'PyObject_SetAttr',
3131
'HPy_SetAttr_s': 'PyObject_SetAttrString',
32+
'HPy_GetIter': 'PyObject_GetIter',
3233
'HPy_GetItem': 'PyObject_GetItem',
3334
'HPy_GetItem_i': None,
3435
'HPy_GetItem_s': None,
@@ -107,6 +108,8 @@
107108
'HPy_RichCompare': 'PyObject_RichCompare',
108109
'HPy_RichCompareBool': 'PyObject_RichCompareBool',
109110
'HPy_Hash': 'PyObject_Hash',
111+
'HPyIter_Next': 'PyIter_Next',
112+
'HPyIter_Check': 'PyIter_Check',
110113
'HPyListBuilder_New': None,
111114
'HPyListBuilder_Set': None,
112115
'HPyListBuilder_Build': None,

hpy/tools/autogen/public_api.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,55 @@ HPy HPy_Call(HPyContext *ctx, HPy callable, const HPy *args, size_t nargs, HPy k
307307
HPy_ID(262)
308308
HPy HPy_CallMethod(HPyContext *ctx, HPy name, const HPy *args, size_t nargs, HPy kwnames);
309309

310+
/**
311+
* Return a new iterator for iterable object ``obj``. This is the equivalent
312+
* of the Python expression ``iter(obj)``.
313+
*
314+
* :param ctx:
315+
* The execution context.
316+
* :param obj:
317+
* An iterable Python object (must not be ``HPy_NULL``). If the object is
318+
* not iterable, a ``TypeError`` will be raised.
319+
*
320+
* :returns:
321+
* The new iterator, ``obj`` itself if it is already an iterator, or
322+
* ``HPy_NULL`` on failure.
323+
*/
324+
HPy_ID(269)
325+
HPy HPy_GetIter(HPyContext *ctx, HPy obj);
326+
327+
/**
328+
* Return the next value from iterator ``obj``.
329+
*
330+
* :param ctx:
331+
* The execution context.
332+
* :param obj:
333+
* An iterator Python object (must not be ``HPy_NULL``). This can be
334+
* verified with ``HPy_IterCheck``. Otherwise, the behavior is undefined.
335+
*
336+
* :returns:
337+
* The new value in iterator ``obj``, or ``HPy_NULL`` on failure. If the
338+
* iterator was exhausted normally, an exception will not be set. In
339+
* case of some other error, one will be set.
340+
*/
341+
HPy_ID(270)
342+
HPy HPyIter_Next(HPyContext *ctx, HPy obj);
343+
344+
/**
345+
* Tests if an object is an instance of a Python iterator.
346+
*
347+
* :param ctx:
348+
* The execution context.
349+
* :param obj:
350+
* A handle to an arbitrary object (must not be ``HPy_NULL``).
351+
*
352+
* :returns:
353+
* Non-zero if object ``obj`` provides the ``Iterator`` protocol, and ``0``
354+
* otherwise.
355+
*/
356+
HPy_ID(271)
357+
int HPyIter_Check(HPyContext *ctx, HPy obj);
358+
310359
/* pyerrors.h */
311360
HPy_ID(136)
312361
void HPy_FatalError(HPyContext *ctx, const char *message);

hpy/trace/src/autogen_trace_ctx_init.h

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/trace/src/autogen_trace_func_table.c

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/trace/src/autogen_trace_wrappers.c

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/universal/src/autogen_ctx_def.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpy/universal/src/autogen_ctx_impl.h

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)