On Mon, Sep 28, 2015 at 12:35:31PM -0400, Laine Stump wrote: > On 09/17/2015 11:37 AM, Michal Privoznik wrote: > >It's used as enum everywhere, so why store its value in an int? > > There are a lot of these. I *think* the only reason this was done anywhere > in the first place was because the size of an enum isn't guaranteed to be > the same across different platforms, so you can't use an enum type in any > wire protocol (e.g. libvirt client to server), and somehow this usage leaked > over into the internal-only data structures; after that the general "that > works! Copy it!" cargo cult generation of new code meant that we now have > lots of instances of this (there may also be cases where someone chose to > use -1 to indicate "not specified" rather than 0/the first enum value). > > Or it could be there's some other reason for using int instead of an enum > type in the internal config objects that I've forgotten. IIRC, it was because enum fields can be unsigned & we use -1 as the error code for virEnumFromString(). So if you have enum foo; if ((foo = virEnumFromString("blah")) < 0) ...error handling... your error handling would not get run, as the -1 would get turned into a high positive value. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list