I produced some patches that use this approach. Even with this approach, still not sure about the best API.
Kaushal Modi