locking the gun automatically in a safety condition when the magazine is empty or removed