Skip to content

Commit 904ff74

Browse files
committed
Implement C API function '_PySet_NextEntry'
1 parent 6e74a37 commit 904ff74

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

graalpython/com.oracle.graal.python.cext/src/setobject.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ int PySet_Contains(PyObject *anyset, PyObject *key) {
6969
return UPCALL_CEXT_I(_jls_PySet_Contains, native_to_java(anyset), native_to_java(key));
7070
}
7171

72+
UPCALL_ID(PySet_NextEntry);
73+
int _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash) {
74+
PyObject *tresult = UPCALL_CEXT_O(_jls_PySet_NextEntry, native_to_java(set), *pos);
75+
if (tresult == NULL) {
76+
*key = NULL;
77+
*hash = 0;
78+
return 0;
79+
}
80+
(*pos)++;
81+
*key = PyTuple_GetItem(tresult, 0);
82+
*hash = PyLong_AsSsize_t(PyTuple_GetItem(tresult, 1));
83+
return 1;
84+
}
85+
7286
UPCALL_ID(PySet_Pop);
7387
PyObject * PySet_Pop(PyObject *set) {
7488
return UPCALL_CEXT_O(_jls_PySet_Pop, native_to_java(set));

graalpython/lib-graalpython/python_cext.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,19 @@ def PySet_Contains(anyset, item):
245245
return item in anyset
246246

247247

248+
@may_raise
249+
def PySet_NextEntry(anyset, pos):
250+
curPos = 0
251+
max = len(anyset)
252+
if pos >= max:
253+
return native_null
254+
for key in anyset:
255+
if curPos == pos:
256+
return key, hash(key)
257+
curPos = curPos + 1
258+
return native_null
259+
260+
248261
@may_raise
249262
def PySet_Pop(anyset):
250263
if not isinstance(anyset, set):

0 commit comments

Comments
 (0)