Make appdataptr_from functions safe