Skip to content

TypeManager.pointer_attribute cannot be safely used in nested CustomType. #480

Closed as not planned
@CookStar

Description

@CookStar

This is partially related to #472 and #474 though.

The values set in the TypeManager.pointer_attribute are managed by CustomType._allocated_pointers or CustomType._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.

from memory.manager import CustomType
from memory.manager import TypeManager

manager = TypeManager()

class Test(CustomType, metaclass=manager):
    _size = 12

    test2 = manager.instance_attribute("Test2", 4)

class Test2(CustomType, metaclass=manager):
    _size = 8
    size = manager.pointer_attribute(Type.INT, 0)
    other_test = manager.pointer_attribute("Test", 4)

test = Test()
test.test2.size = 1 # BROKEN!, the memory of size is already deallocated.
test.test2.other_test = Test() # BROKEN!, the memory of Test is already deallocated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions