[CDRIVER-1544] libbson headers cannot be consumed from C++ due to direct use of _Decimal128 Created: 14/Sep/16 Updated: 19/Oct/16 Resolved: 20/Sep/16 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | None |
| Affects Version/s: | 1.5.0 |
| Fix Version/s: | 1.5.0 |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | Andrew Morrow (Inactive) | Assignee: | Hannes Magnusson |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
C++ doesn't offer a _Decimal128 type. The libbson 1.5.0-rc0 headers directly make use of this type, which means that the headers cannot be consumed by C++. |
| Comments |
| Comment by Hannes Magnusson [ 20/Sep/16 ] |
|
No idea why the commit doesn't show up here. But here it is: https://github.com/mongodb/libbson/commit/4d3351c40e486f042403e9e677d8450fc4ed353e |
| Comment by Hannes Magnusson [ 14/Sep/16 ] |
|
We should probably just remove these functions. Our bson_decimal_t emulates BID, and can be casted to the native _Decimal128 type if it is BID encoded. They aren't really all that benefitial. If your _Decimal128 type is BID encoded, then you can do the cast yourself. I suppose in the future we should add bson_decimal128_to_dpd and bson_decimal128_to_bid instead. |
| Comment by Andrew Morrow (Inactive) [ 14/Sep/16 ] |
|
This is actually worse than we originally thought. It should be legal to compile the C driver with GCC (in which case the configure check will determine that _Decimal128 is available), but consume the headers for that built version of the driver with clang (also in C mode), in which case, _Decimal128 is perhaps not available. Or, for that matter, an older GCC than offers _Decimal128. I think that the conversion functions need to default invisible and opt in by a consumer preprocessor definition, like LIBBSON_ENABLE__DECIMAL128_UTILITIES, which will expose those functions, iff the driver was built with Decimal support. Basically, you can't emit these functions on the basis of the configure check. |
| Comment by Mira Carey [ 14/Sep/16 ] |
|
The smart thing here is probably just to exclude the inline conversion functions ifdef __cplusplus C++ will want the non-standard std::decimal::decimal128, which is a class wrapped around a float _attribute_((mode(TD))). So there isn't a one to one correspondence. There's the same underlying scalar type (and the C++ class can be constructed from the scalar), but I'm not sure it's worth the trouble for you. |