Refactor C extension code through a macro