This is the follow up of our discussion about a "pointer being freed was not allocated".
Looking at the code I realized that the problem is simply related to the fact that the expected result is and empty gtf_data.
I have tried to explain clearly the sequence of actions below.
In [1]: from gtftk.utils import get_example_file
...: from gtftk.gtf_interface import GTF
...: a_file = get_example_file("simple", "gtf")[1]
...: # Let's create a GTF
...: gtf = GTF(a_file)
...: # The pointer to the GTF_DATA is
...: gtf._data
...:
...: # Now we ask for a new pointer and this is what we get.
...: # The pointer points to 2 transcripts ['G0007T001', 'G0007T002']
...: ptr_1 = gtf._dll.select_by_key(gtf._data, 'transcript_id', ",".join(['G0007T001', 'G0007T002']), 0)
...: ptr_1
...:
Out[1]: <cdata 'GTF_DATA *' 0x7fb90724b150>
In [2]: ptr_1.size
Out[2]: 6
In [3]: # We pass this pointer to the the _clone method just
...: # to embed this pointer in a GTF object.
...: # This pointer has the same address as the previous one
...: # since the gtf2 object (an instance of GTF class) is just a container
...: gtf_2 = gtf._clone(ptr_1)
...: gtf_2._data
...:
Out[3]: <cdata 'GTF_DATA *' 0x7fb90724b150>
In [4]: # The GTF instance is funtional and we can call it with several methods
...: # For instance we can see that it contains the 2 expected transcripts
...: gtf_2.get_tx_ids(nr=True)
Out[4]: ['G0007T001', 'G0007T002']
In [5]:
In [5]: # We could select exons also
...: gtf_2.select_by_key("feature", "exon").extract_data("exon_id", as_list=True)
...:
Out[5]: ['G0007T002E001', 'G0007T001E001']
In [6]: # Now we pass this pointer to another function of the
...: # dynamic library. if we pass it to a function that is expected to return something,
...: # everything is OK.
...: # Here we will delete the exons
...: ptr_2 = gtf_2._dll.select_by_key(gtf_2._data, "feature", "exon", 1)
...: ptr_2.size
...:
Out[6]: 4
In [7]: # Now if we ask for something that is non existing
...: ptr_2 = gtf_2._dll.select_by_key(gtf_2._data, "feature", "gene", 0)
python(52707,0x7fff70ef4000) malloc: *** error for object 0x10df80002: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
I think this shows that this is not related to any issue in _clone or whatever on the C side. This is just the fact that we don't know maybe how to deal with an empty result. Tell me
This is the follow up of our discussion about a "pointer being freed was not allocated".
Looking at the code I realized that the problem is simply related to the fact that the expected result is and empty gtf_data.
I have tried to explain clearly the sequence of actions below.
I think this shows that this is not related to any issue in _clone or whatever on the C side. This is just the fact that we don't know maybe how to deal with an empty result. Tell me