Skip to content
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

Call cycle causes infinite recursion #19

Open
mattip opened this issue Dec 9, 2023 · 3 comments
Open

Call cycle causes infinite recursion #19

mattip opened this issue Dec 9, 2023 · 3 comments

Comments

@mattip
Copy link

mattip commented Dec 9, 2023

array_iter_impl -> HPySeqIter_New -> look up __iter__ and call it -> array_iter_impl.

You can hit this by doing np.range(10).__iter__(). This was added in 3a7a0d2.

For some reason calling src_cycle = cycle(self.pool) in setting up the random.bit_generator is hitting this in PyPy but not in CPython. Maybe cycle is implemented slightly differently in CPython, and avoids calling self.pool.__iter__().

@mattip
Copy link
Author

mattip commented Dec 9, 2023

On CPython, it seems HPyDef_METH(array_iter, "__iter__", HPyFunc_NOARGS) does not push the __dict__ function into the tp_iter slot, so CPython does not hit this problem. Instead, the __new__ function for the c implementation of itertools.cycle will call PySeqIter_New(ndarray), which wraps the ndarray in a new iter object.

@mattip
Copy link
Author

mattip commented Dec 20, 2023

@fangerer any thoughts?

@fangerer
Copy link

@fangerer any thoughts?

Interesting, I thought CPython would also push the __iter__ member back to the tp_iterslot. See update_one_slot.
I guess we need to investigate in the debugger what path CPython takes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants