Skip to content

Use WeakMap and abolish CastedCData #412

@sj-i

Description

@sj-i

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cleanupImprove cleanness of the codeenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions