Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Support weakly-referencing to all kinds of objects #1694

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Member

ryoqun commented May 2, 2012

Current WeakRef implementation doesn't support to reference to nil and false.

The reason for nil is that it can't know whether referenced object is nil or it
is garbage-collected and set to nil. The reason for false is that there is an
incorrect assumption that referenced objects can't be evaluated to false.

By adding a new field to C++ WeakRef class to record whether referenced object
is immediate or reference, WeakRef truly supports all kinds of objects.

Personally, I think the increase of WeakRef's size is well justified by the realized consistency in this case.

FYI, MRI's WeakRef doesn't support to referencing to immediates at all. So, as an alternative design decision, we can follow it.

Support weakly-referencing to all kinds of objects
Current WeakRef implementation doesn't support to reference to nil and false.

The reason for nil is that it can't know whether referenced object is nil or it
is garbage-collected and set to nil. The reason for false is that there is an
incorrect assumption that referenced objects can't be evaluated to false.

By adding a new field to C++ WeakRef class to record whether referenced object
is immediate or reference, WeakRef truly supports all kinds of objects.

This pull request passes (merged 8103af4 into c57090a).

Owner

brixen commented May 12, 2012

This behavior isn't consistent with MRI. If MRI adds the ability to create WeakRefs for immediates, we can as well. Please consider filing an issue with MRI.

@brixen brixen closed this May 12, 2012

Member

ryoqun commented May 13, 2012

@brixen I see! Thanks for looking at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment