fix __setattr__ for double underscore attributes
minor C code simplification