-
Notifications
You must be signed in to change notification settings - Fork 31
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
TypeManager.pointer_attribute cannot be safely used in nested CustomType. #480
Comments
That's not entirely accurate. The memory allocated for test = Test()
test2 = test.test2
test2.size = 1
# Here test2.size is still held by test2._allocated_pointers...
del test2
# ...now size is being deallocated because test2 went out of scope. So, the problem is not really Source.Python/addons/source-python/packages/source-python/memory/manager.py Lines 446 to 450 in f129713
If class Test(CustomType, metaclass=manager):
_size = 12
test2 = cached_property(manager.instance_attribute("Test2", 4)) Because now |
I know, that is exactly what I was explaining in the comment I wrote.
First, cached_property accepts getter and setter, not The fundamental problem is that the _allocated_pointers and _pointer_values of CustomType are managing Python objects that should not be managed. Even if we use cached_property or some other method, there is no guarantee that the original Test2 can manage other objects in the first place (i.e. Test2 cannot contain Python objects since they can be created by make_object() at any time). I wrote about the fundamental problem in #490, so I'll close this one. |
|
It seems I was testing with an old binary, my bad. But as noted above, cached_property is not a solution to this problem. |
This is partially related to #472 and #474 though.
The values set in the
TypeManager.pointer_attribute
are managed byCustomType._allocated_pointers
orCustomType._pointer_values
, but if the original CustomType is managed by another object, they will be deallocated instantly. This means that pointer manipulation is not possible on nested CustomTypes.My advice is we should stop using
TypeManager.pointer_attribute
. This feature has not been tested for a long time(#391) and should only be used in situations where you have full control over the memory of the values you are setting. (i.e. only non-native_type that you can manage yourself.) I found this out the hard way.The text was updated successfully, but these errors were encountered: