You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[question]: macro to disable floating point support #284
We are interested in using JSON in our Bareflank Hypervisor for both comms and configuration files, and would love to use this implementation. Kernel / Hypervisor code however should not use double / float as these data types can generate exceptions that cannot be handled well inside the kernel.
It appears that you already support signed / unsigned integers. Would you be interested in a patch that disables (likely via a macro of some sort) double / float completely to support people interested in using this library in non-userspace code?
Did you see this paragraph in the README which could be relevant?
As the exact type of a number is not defined in the JSON specification, this library tries to choose the best fitting C++ number type automatically. As a result, the type double may be used to store numbers which may yield floating-point exceptions in certain rare situations if floating-point exceptions have been unmasked in the calling code. These exceptions are not caused by the library and need to be fixed in the calling code, such as by re-masking the exceptions prior to calling library functions.
How would you deactivate floating-point support? Did you try setting number_float_t to a different type? If possible, I would like to avoid getting to the #ifdef-hell...
The perfect solution would prevent float / double types / instructions from being compiled into the code. The reality is, so long as the code is not executed, it's fine. I did not try setting number_float_t to a different type, but my guess is it would collide with your existing unsigned / signed ints. The question is, When a JSON string is read, and it sees a "42" and not a "42.0" does it use ints and not floats from start to finish? So long as floats and doubles are never used, it should be fine.
You're right - setting number_float_t to an integer type yields collisions. So far, I do not see a simple solution to exclude any floating-point numbers from the class.
I think the best thing to do is probably close the ticket. A couple of days ago I grabbed the source and gutted anything with "float" or "double". It only took about 5 mins, and the resulting code worked great. Based on those results, this implementation is perfect for what we need it for, but the only way I know to implement this more generically is to use #defines which I would agree would clutter what you have for a very small use case. For now, my plan is to maintain a fork with the modifications in our repo. I'm watching this repo, so anytime you roll a release, I'll make the mods, and push to our repo, and let you know if anything you guys change breaks what we are doing. But yeah, I wrote the https://github.com/QtMark/qmjson code, and I really like what you have done with this C++ only implementation so we will use it for sure.
Activity
nlohmann commentedon Jul 22, 2016
Hi @rianquinn, this sounds interesting!
Did you see this paragraph in the README which could be relevant?
How would you deactivate floating-point support? Did you try setting
number_float_tto a different type? If possible, I would like to avoid getting to the#ifdef-hell...rianquinn commentedon Jul 22, 2016
The perfect solution would prevent float / double types / instructions from being compiled into the code. The reality is, so long as the code is not executed, it's fine. I did not try setting number_float_t to a different type, but my guess is it would collide with your existing unsigned / signed ints. The question is, When a JSON string is read, and it sees a "42" and not a "42.0" does it use ints and not floats from start to finish? So long as floats and doubles are never used, it should be fine.
nlohmann commentedon Jul 22, 2016
You're right - setting
number_float_tto an integer type yields collisions. So far, I do not see a simple solution to exclude any floating-point numbers from the class.nlohmann commentedon Aug 10, 2016
Any idea how to proceed on this?
rianquinn commentedon Aug 10, 2016
I think the best thing to do is probably close the ticket. A couple of days ago I grabbed the source and gutted anything with "float" or "double". It only took about 5 mins, and the resulting code worked great. Based on those results, this implementation is perfect for what we need it for, but the only way I know to implement this more generically is to use #defines which I would agree would clutter what you have for a very small use case. For now, my plan is to maintain a fork with the modifications in our repo. I'm watching this repo, so anytime you roll a release, I'll make the mods, and push to our repo, and let you know if anything you guys change breaks what we are doing. But yeah, I wrote the https://github.com/QtMark/qmjson code, and I really like what you have done with this C++ only implementation so we will use it for sure.
nlohmann commentedon Aug 10, 2016
This is fine with me. Thanks for the quick response, and maybe we find way to cope with your usecase in a general way!