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

make pd_unbind safe (+ improve stack overflow protection) #849

Closed
wants to merge 2 commits into from

Conversation

Spacechild1
Copy link
Contributor

@Spacechild1 Spacechild1 commented Dec 26, 2019

a) make pd_unbind safe

Currently, it is unsafe to dynamically unbind symbols because some other object could be sending to them.

The solution is to simply make a copy of the bind list before iterating over it. A counter keeps track of the total number of items. We use stack allocation up to a certain limit and then switch to heap allocation to avoid a stack overflow.

To make copying as fast as possible, I changed the bind list implementation to a dynamically sized array instead of a linked list. (This is also better for cache coherency).

In a way, this not much different than how [list] has to output a copy of the stored list to prevent other objects to modify the list while iterating over it.

This PR would finally make it possible to safely implement dyamically settable [receive] objects (#604), and make existing similar objects safe, for example iemgui's [receive( method.


b) improve stack overflow protection

The current overflow protection only works for a single recursion path. For more than 1 path (e.g. several outlets feeding back to the same inlet), Pd would end up in an infinite loop. Once the stacklimit is reached, I set an overflow flag to prevent any further messaging until the stack got completely unwound.

@Spacechild1 Spacechild1 changed the title make pd_unbind safe and improve stack overflow protection - 2nd version make pd_unbind safe Aug 14, 2020
@Spacechild1 Spacechild1 changed the title make pd_unbind safe make pd_unbind safe (+ improve stack overflow protection) Aug 14, 2020
@Spacechild1 Spacechild1 added the subject:core things concerning the Pd-core label Aug 14, 2020
the current overflow protection only works for a *single* recursion path. for more than 1 path (e.g. several outlets feeding back to the same inlet), Pd would end up in an infinite loop.
once the stacklimit is reached, we set an overflow flag to prevent any further messaging until the stack got completely unwound.
Copy link
Contributor

@umlaeute umlaeute left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the build-failures and warnings :-)

src/m_pd.c Show resolved Hide resolved
… symbols

use arrays instead of intrinsic lists to optimize for copying and iterating. unbinding may be slightly slower, but it doesn't happen too often anyway.
@Spacechild1
Copy link
Contributor Author

Actually, I don't know why I grouped these 2 commits together in a single PR... Closing in favor of #1760 and #1759

@Spacechild1 Spacechild1 deleted the bind-fix5 branch October 17, 2022 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
subject:core things concerning the Pd-core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants