Tskit: Add tests for uninitialised Python objects

Created on 24 Oct 2020  路  3Comments  路  Source: tskit-dev/tskit

The Python C API can current segfault in quite a few places if a user deliberately creates an instance without calling __init__ using __new__. While this is a remote corner case, we should tie up this loose-end and avoid the segault. The way to do it is to make sure ClassName_check_state is called before accessing any of the memory of the embedded C object.

The test for doing this on the various objects can be adopted from test_uninitialised in msprime.

C API Python API bug

All 3 comments

@jeromekelleher Looking into this - I assume CompressedMatrix et al all need _check_state implemented. Looks like it to me.

@jeromekelleher Looking into this - I assume CompressedMatrix et al all need _check_state implemented. Looks like it to me.

Yep. I stopped doing the check_states a while ago for new code as I thought I was being overly paranoid. Turns out not.

TreeSequence has a NULL reference after initialisation, so instead of SystemError as in the other classes it raises ValueError when un-inited. This seems to make sense but thought it worth flagging.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeromekelleher picture jeromekelleher  路  9Comments

bhaller picture bhaller  路  5Comments

petrelharp picture petrelharp  路  8Comments

saurabhbelsare picture saurabhbelsare  路  8Comments

mufernando picture mufernando  路  6Comments