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.
@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.