Skip to content

Commit

Permalink
Improve impl of ctx_GetItem_i
Browse files Browse the repository at this point in the history
  • Loading branch information
fangerer committed Jan 29, 2024
1 parent 304d1ce commit 8b2618f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hpy/devel/src/runtime/ctx_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ ctx_Is(HPyContext *ctx, HPy h_obj, HPy h_other)

_HPy_HIDDEN HPy
ctx_GetItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx) {
PyObject *py_obj = _h2py(obj);
if (PySequence_Check(py_obj)) {
return _py2h(PySequence_GetItem(py_obj, idx));
}
PyObject* key = PyLong_FromSsize_t(idx);
if (key == NULL)
return HPy_NULL;
HPy result = _py2h(PyObject_GetItem(_h2py(obj), key));
HPy result = _py2h(PyObject_GetItem(py_obj, key));
Py_DECREF(key);
return result;
}
Expand Down

0 comments on commit 8b2618f

Please sign in to comment.