I'd like to use the numpy c-api to write a datatype that's a tree structure, with pointers to children. I initially thought this possible without being a flexible datatype, since I don't need a variable number of direct children, and I'm fine with copying them. However, I'm not sure there's a way around calling malloc to allocate them - the number of indirect children isn't fixed. This strikes me as counter to the philosophy of the existing datatype api; I've used it a few times, and I don't believe there's any descr function called on deallocation in PyArray_ArrFuncs. Is it even possible to write any recursive datatype with variable indirect children in the current api? How about the experimental one, with parametric datatypes?
I wrote a small proof-of-concept that makes the malloc calls without freeing the memory and it works fine, but that of course can't scale. Any workarounds?