msoucy / dproto

D Protocol Buffer mixins to create structures at compile time
Boost Software License 1.0
37 stars 16 forks source link

fixes issue #115 and also pre-existing bug with sint64 and sint32 #131

Closed timotheecour closed 6 years ago

timotheecour commented 6 years ago

@msoucy @redstar

fixes issue #115 and also pre-existing bug with sint64 and sint32

Supersedes https://github.com/msoucy/dproto/pull/116 and https://github.com/msoucy/dproto/pull/130; incorporates idea from @redstar in pull #130 for backward compatibility with older dmd.

Root cause of 115 is that the used base data type for reading an integer is always ulong. Converting a (huge) value to a signed, possible shorter data type results in the onversion exception.

Solution is to use the correct type. This eliminates almost all calls to the std.conv.to function.

For sint32/sint64, this was related to an overload never being called because of dmd overload resolution rules regarding const vs mutable; cf https://forum.dlang.org/thread/sinvexzpgmhcyvyufejd@forum.dlang.org [functions allowed to overload on const int vs int vs immutable int? + spec is not accurate]