Skip to content

prevent premature deletion #64

@maxbachmann

Description

@maxbachmann

The readme mentions:

Be careful using the attributes of the Result object - especially on Result instances constructed on the fly. For example, calling parasail.sw_trace("asdf", "asdf", 11, 1, parasail.blosum62).cigar.seq returns a numpy.ndarray that wraps a pointer to memory that is invalid because the Cigar is deallocated before the seq statement. You can avoid this problem by assigning Result instances to variables as in the example above.

This is really bad, since this is generally a very unexpected behaviour. The behavior can be prevented by adding another level of abstraction around pointers. Currently you have e.g. the following implementation:

class Result:
    def __init__(self, pointer, ...):
        self.pointer = pointer
    def __del__(self):
        _lib.parasail_result_free(self.pointer)
   def test(self):
       return object_depending_on_pointer(self.pointer)

this should be changed to something like this:

class _ResultPointer:
    def __init__(self, pointer, ...):
        self.pointer = pointer

    def __del__(self):
        _lib.parasail_result_free(self.pointer)

class Result:
    def __init__(self, pointer, ...):
        self.pointer = _ResultPointer(pointer)

   def test(self):
       return object_depending_on_pointer(self.pointer)

this abstraction around the pointer ensures that the memory will not be freed to early.

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