Skip to content

Movement reassigns object pointers #37

@DilettanteProjects

Description

@DilettanteProjects

I'm pretty out of my depth here, so forgive me if the error is in my thinking, but here's the issue:

When using the movement operator to change the value an object pointer points to, this works exactly once, and then "unattaches" from the memory address it originally was assigned to track.

Expected behavior:

a = [1]
obj_ptr = _&a

obj_ptr <<= [9]
print(a)        # [9]
obj_ptr <<= [8]
print(a)        # [8]

Actual behavior:

a = [1]
obj_ptr = _&a

obj_ptr <<= [9]
print(a)        # [9]
obj_ptr <<= [8]
print(a)        # [9] !

Looking further into it, it appears that the pointer does not in fact consistently point to the same address?:

a = [1]
obj_ptr = _&a
print(obj_ptr)  # Pointer(0x7f6501710740) <- Original address of 'a'

obj_ptr <<= [9]
print(a)        # [9]
print(obj_ptr)  # Pointer(0x7f6501841c80) <- Address the pointer points to has changed
obj_ptr <<= [8]
print(a)        # [9] 
print(obj_ptr)  # Pointer(0x7f6501841d80) <- Address the pointer points to has *not* changed?
print(_&a)      # Pointer(0x7f6501710740) <- 'a' is still at original address

Again, maybe this is a fault in my comprehension. If I understand correctly, a pointer should stick to pointing to the same address right? Or is this due to a peculiarity with the way python tracks variables?

And I'm not sure if it's relevant, but when I quit out of the REPL or the execution of the script finishes when reproducing this problem, I get a Segmentation fault from the garbage collector:

Fatal Python error: Segmentation fault

Current thread 0x00007f6502628440 (most recent call first):
  Garbage-collecting
  <no Python frame>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions