From: Baptiste L. <bap...@gm...> - 2011-05-23 11:51:03
|
I think you put your finger on something missing in the API. I propose making the following changes: 1) isUInt() returns true only asUInt() can succeed. Similar changes for isInt(). I think this contract should be generalized. e.g. asUInt() should succeed if the value is a positive signed int Value. 2) Adds new member functions: isUInt64() that returns true only if asUInt64() can succeed. and isInt64()... If I understood your problem correctly, this should solve your backward compatibility issue. Is that correct? What do you think of this proposal? Baptiste. 2011/5/23 Aaron Jacobs <ja...@go...> > Hi all, > > I'm working on updating Google's internal version of jsoncpp from an > ancient > commit to the most recent version (SVN rev 192), but having some trouble. I > think I've run into a backwards incompatible change that makes it nearly > impossible for us to upgrade. > > In particular, there's jsoncpp-using code that looks something like this: > > Json::Value value = ... > unsigned int value = > value.isUInt() ? value.asUInt() : > (value.isDouble() ? value.asDouble() : kError); > > That is, the code uses the isFoo methods to decide which asFoo method to > call. > The problem is that at SVN rev 192, values parsed as integers greater than > 2^32 will return true for isUInt(), but have an assertion failure for > asUInt(): > > value_.uint_ <= maxUInt > "unsigned integer out of UInt range" > > You can see this by parsing the string "31121983701778432", for example. > > As far as I can tell, there's no way for me to update to the latest version > of > jsoncpp without either changing the code above or breaking it (introducing > incorrectness or a crasher bug into production). Updating the code is not > an > option for me since there is too much of it. > > Do you have any advice? In particular, am I missing something in the > Json::Value API? > > Thanks, > Aaron > |