Bleh, finally fixed all the segfaults. I wasn't retaining a reference to the function returned by generate, so it was getting garbage collected...