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

Use WeakMap and abolish CastedCData #412

Open
sj-i opened this issue Jan 18, 2024 · 0 comments
Open

Use WeakMap and abolish CastedCData #412

sj-i opened this issue Jan 18, 2024 · 0 comments
Labels
cleanup Improve cleanness of the code enhancement New feature or request

Comments

@sj-i
Copy link
Member

sj-i commented Jan 18, 2024

The use of CastedCData is to keep the refcount of \FFI\CData objects.

However, this solution is clearly ugly and causes confusing use-after-free.

Another solution is using \WeakMap. If we use partial \FFI\CData objects as keys to their root \FFI\CData object in a \WeakMap, we can guarantee that the root object will survive while at least one reference count of the partial objects remains.

There was a bug in php-src that prevented \WeakMap from being used with FFI extension objects, but a fix has already been released, so it's time to move to \WeakMap.

@sj-i sj-i added enhancement New feature or request cleanup Improve cleanness of the code labels Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Improve cleanness of the code enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant