skystrife / cpptoml Goto Github PK
View Code? Open in Web Editor NEWcpptoml is a header-only library for parsing TOML
License: MIT License
cpptoml is a header-only library for parsing TOML
License: MIT License
Is there a known design/functionality complication why those can't be fixed? Or are they simply that prominent to warn people and otherwise are simply open for me to take a swing at if I have time?
It is somewhat annoying to write cpptoml::toml_group
and so on. Why should "toml" be repeated? IMHO the classes should be renamed so that we could just use cpptoml::group
.
There are some warnings when compiling a program which includes cpptoml.h and tries to parse a file.
GCC version is 7.1.1
The warnings can be silenced by temporarily disabling the warning:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
#include "cpptoml.h"
#pragma GCC diagnostic pop
Here is an example of the warnings produced by gcc:
In file included from ../main.cpp:18:0:
../cpptoml.h:404:7: warning: ‘class cpptoml::base’ has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]
class base : public std::enable_shared_from_this<base>
^~~~
../cpptoml.h: In instantiation of ‘class cpptoml::value<long int>’:
../cpptoml.h:571:56: required from here
../cpptoml.h:492:7: warning: base class ‘class cpptoml::base’ has accessible non-virtual destructor [-Wnon-virtual-dtor]
class value : public base
^~~~~
../cpptoml.h:492:7: warning: ‘class cpptoml::value<long int>’ has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]
../cpptoml.h:612:7: warning: base class ‘class cpptoml::base’ has accessible non-virtual destructor [-Wnon-virtual-dtor]
The full warning list can be found at https://gist.github.com/trilader/9bd5b53ce61c6fe43979aa9ad5b6cead
GCC documentation for this warning
-Wnon-virtual-dtor (C++ and Objective-C++ only)
Warn when a class has virtual functions and an accessible non-virtual destructor itself or in an accessible polymorphic base class, in which case it is possible but unsafe to delete an instance of a derived class through a pointer to the class itself or base class. This warning is automatically enabled if -Weffc++ is specified.
Do we support toml-lang/toml#297? If not, we should,
I'm having trouble compiling some code that uses cpptoml with clang (g++ 4.8.4 works fine).
The offending code is this:
auto dt = cpptoml::make_value<cpptoml::datetime>(generateDateTime());
cpptoml::datetime generateDateTime() {
// Generate current date-time
std::time_t raw_time;
struct tm * time_info;
char buffer[100];
std::time(&raw_time);
time_info = std::localtime(&raw_time);
cpptoml::datetime dt;
dt.year = time_info->tm_year + 1900;
dt.month = time_info->tm_mon + 1;
dt.day = time_info->tm_mday;
dt.hour = time_info->tm_hour;
dt.minute = time_info->tm_min;
dt.second = time_info->tm_sec;
return dt;
}
and the compiler error I'm getting is the following:
/home/jon/Public/Oat/debug/cpptoml/src/cpptoml/include/cpptoml.h:339:51: error: no matching function for call to 'forward'
make_shared_enabler(T&& val) : value_type(std::forward<T>(val))
^~~~~~~~~~~~~~~
/home/jon/Public/Oat/debug/cpptoml/src/cpptoml/include/cpptoml.h:337:12: note: in instantiation of member function 'cpptoml::make_value(cpptoml::datetime &&)::make_shared_enabler::make_shared_enabler' requested here
struct make_shared_enabler : public value_type
^
/home/jon/Public/Oat/src/calibrator/Saver.cpp:146:24: note: in instantiation of function template specialization 'cpptoml::make_value<cpptoml::datetime>' requested here
auto dt = cpptoml::make_value<cpptoml::datetime>(generateDateTime());
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/move.h:76:5: note: candidate function [with _Tp = double] not viable: no known conversion from 'cpptoml::datetime' to
'typename std::remove_reference<double>::type &' (aka 'double &') for 1st argument
forward(typename std::remove_reference<_Tp>::type& __t) noexcept
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/move.h:87:5: note: candidate function [with _Tp = double] not viable: no known conversion from 'cpptoml::datetime' to 'typename std::remove_reference<double>::type'
(aka 'double') for 1st argument
forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
^
1 warning and 1 error generated
Any ideas?
Lovely to see toml 0.5 support. I just carried this over to my RcppTOML but I ran into two regressions, both Date related.
First, Tom's own example.toml
no longer parses. The line
dob = 1979-05-27T07:32:00-08:00 # First class dates
fails, but passes once the comment is removed:
dob = 1979-05-27T07:32:00-08:00
Similarly, I have a file example4.toml
and it now falls over
bla = [ 1979-05-27T07:32:00Z, 1979-05-28T07:32:00Z ]
but the dates pass individually. The spec is silent about whether arrays of dates are allowed or not, but they worked in the past and I don't see why they should be excluded.
root->insert("my_name", 1.0f);
./coefficient.cpp:12:11: error: no matching member function for call to 'insert'
root->insert(name, value);
~~~~~~^~~~~~
.coddle/libs_src/cpptoml/cpptoml.h:1515:10: note: candidate function not viable: no known conversion
from 'float' to 'const std::shared_ptr<base>' for 2nd argument
void insert(const std::string& key, const std::shared_ptr<base>& value)
^
.coddle/libs_src/cpptoml/cpptoml.h:1525:10: note: candidate template ignored: substitution failure
[with T = float &]: ambiguous partial specializations of 'value_traits<float &, void>'
void insert(const std::string& key, T&& val,
^
1 error generated.
$ clang --version
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Workaround convert to double:
root->insert("my_name", 1.0);
I'm having trouble compiling some code that uses cpptoml with clang (g++ 4.8.4 works fine)
The offending code is this:
auto dt = cpptoml::make_value<cpptoml::datetime>(generateDateTime());
cpptoml::datetime generateDateTime() {
// Generate current date-time
std::time_t raw_time;
struct tm * time_info;
char buffer[100];
std::time(&raw_time);
time_info = std::localtime(&raw_time);
cpptoml::datetime dt;
dt.year = time_info->tm_year + 1900;
dt.month = time_info->tm_mon + 1;
dt.day = time_info->tm_mday;
dt.hour = time_info->tm_hour;
dt.minute = time_info->tm_min;
dt.second = time_info->tm_sec;
return dt;
}
and the compiler error I'm getting is the following:
/home/jon/Public/Oat/debug/cpptoml/src/cpptoml/include/cpptoml.h:339:51: error: no matching function for call to 'forward'
make_shared_enabler(T&& val) : value_type(std::forward<T>(val))
^~~~~~~~~~~~~~~
/home/jon/Public/Oat/debug/cpptoml/src/cpptoml/include/cpptoml.h:337:12: note: in instantiation of member function 'cpptoml::make_value(cpptoml::datetime &&)::make_shared_enabler::make_shared_enabler' requested here
struct make_shared_enabler : public value_type
^
/home/jon/Public/Oat/src/calibrator/Saver.cpp:146:24: note: in instantiation of function template specialization 'cpptoml::make_value<cpptoml::datetime>' requested here
auto dt = cpptoml::make_value<cpptoml::datetime>(generateDateTime());
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/move.h:76:5: note: candidate function [with _Tp = double] not viable: no known conversion from 'cpptoml::datetime' to
'typename std::remove_reference<double>::type &' (aka 'double &') for 1st argument
forward(typename std::remove_reference<_Tp>::type& __t) noexcept
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/move.h:87:5: note: candidate function [with _Tp = double] not viable: no known conversion from 'cpptoml::datetime' to 'typename std::remove_reference<double>::type'
(aka 'double') for 1st argument
forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
^
1 warning and 1 error generated
Any ideas?
I'm seeing compile errors when compiling the build_toml.cpp
example on macOS Sierra. Commenting out the sections operating on integers fixes the problem. Here's a snippet that fails:
#include <cpptoml.h>
#include <iostream>
int main(int argc, char* argv[]) {
std::shared_ptr<cpptoml::table> root = cpptoml::make_table();
root->insert("Integer", 1234L);
std::cout << (*root);
return 0;
}
Error with clang:
$ clang --version
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin16.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ make
clang -c -Wall -std=c++11 -g -I../../cpptoml/include main.cc -o main.o
main.cc:6:9: error: no matching member function for call to 'insert'
root->insert("Integer", 1234L);
~~~~~~^~~~~~
../../cpptoml/include/cpptoml.h:1070:10: note: candidate function not viable: no known conversion from 'long' to
'const std::shared_ptr<base>' for 2nd argument
void insert(const std::string& key, const std::shared_ptr<base>& value)
^
../../cpptoml/include/cpptoml.h:1080:10: note: candidate template ignored: substitution failure [with T = long]:
implicit instantiation of undefined template 'cpptoml::value_traits<long, false>'
void insert(const std::string& key, T&& val,
^
1 error generated.
make: *** [main.o] Error 1
And with gcc:
$ x86_64-apple-darwin16.0.0-g++-6 --version
x86_64-apple-darwin16.0.0-g++-6 (Homebrew gcc 6.2.0) 6.2.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ make
x86_64-apple-darwin16.0.0-g++-6 -c -Wall -std=c++11 -g -I../../cpptoml/include main.cc -o main.o
main.cc: In function 'int main(int, char**)':
main.cc:6:32: error: no matching function for call to 'cpptoml::table::insert(const char [8], long int)'
root->insert("Integer", 1234L);
^
In file included from main.cc:1:0:
../../cpptoml/include/cpptoml.h:1070:10: note: candidate: void cpptoml::table::insert(const string&, const std::shared_ptr<cpptoml::base>&)
void insert(const std::string& key, const std::shared_ptr<base>& value)
^~~~~~
../../cpptoml/include/cpptoml.h:1070:10: note: no known conversion for argument 2 from 'long int' to 'const std::shared_ptr<cpptoml::base>&'
../../cpptoml/include/cpptoml.h:1080:10: note: candidate: template<class T> void cpptoml::table::insert(const string&, T&&, typename cpptoml::value_traits<T>::type*)
void insert(const std::string& key, T&& val,
^~~~~~
../../cpptoml/include/cpptoml.h:1080:10: note: template argument deduction/substitution failed:
../../cpptoml/include/cpptoml.h: In substitution of 'template<class T> void cpptoml::table::insert(const string&, T&&, typename cpptoml::value_traits<T>::type*) [with T = long int]':
main.cc:6:32: required from here
../../cpptoml/include/cpptoml.h:1080:10: error: invalid use of incomplete type 'struct cpptoml::value_traits<long int, false>'
../../cpptoml/include/cpptoml.h:176:8: note: declaration of 'struct cpptoml::value_traits<long int, false>'
struct value_traits;
^~~~~~~~~~~~
make: *** [main.o] Error 1
My understanding of c++ templates is a little thin, so having some trouble interpreting these. Appreciate all the work you've done here!
I've recently moved from Windows to Fedora, and my code that used to run OK with MSVC now causes
Exception caught: config file parse error '---did you forget a '#'? at line 2cter '
when using g++ 6.3.1 (it still compiles cleanly though). The fact that the error message doesn't print correctly at the end is a little strange as well.
At first I thought it could be due to the different line endings between Windows and UNIX, but I re-wrote the config file in Fedora and the problem persists. I've attached the file in question; config.zip
I'm wondering if I'm using this wrong. This example program:
#include "cpptoml.h"
#include <iostream>
#include <strstream>
int main() {
std::strstream toml;
toml << "Int = 64\nBool = false";
auto parser = cpptoml::parser(toml);
auto table = parser.parse();
std::cout << *table << std::endl;
bool b = *table->get_as<bool>("Bool");
std::cout << "Bool = " << std::boolalpha << b << " # expect false"
<< std::endl;
}
outputs the following:
Bool = false
Int = 64
Bool = true # expect false
To reproduce, try parsing this single-line toml file:
key=
Note that this issue is only encountered in debug mode. When compiling in release mode the behaviour is the same as g++ in linux.
Tested under visual studio 2017.
I have a const table (parsed from a TOML file) and I would like to duplicate it in order to create a modifiable copy of the table.
Since the copy constructors are private, how would I go about doing this?
In general, I am building an app that uses a toml file as its config. I would like to be able to parse/load, duplicate, modify and then finally save the config from and to a file....
Any example of any project doing that with cpptoml?
I am working on adding cpptoml to the Hunter package management system. For that to work well it requires a release version that includes a CMakeLists.txt that includes an install target and CMake package configuration. The latest release package (0.4.0) lacks this, yet I see that HEAD does. Can you make a release for this?
hi
I use the master version to test parse this toml : https://github.com/toml-lang/toml/blob/master/examples/example-v0.4.0.toml
Error is : Failed to parse ../toml-master/examples/example-v0.4.0.toml: Malformed number (out of range: stod) at line 152
toml v0.4.0 is supported, ok?
Hi!
I get static_assertion error:
.../include/cpptoml.h:301: error: static assertion failed: invalid value type
static_assert(valid_value::value, "invalid value type");
^
when i try to compile following code:
auto cfg = cpptoml::parse_file(fname);
auto conn = cfg->get_table("connection");
std::string host = *conn->get_as<std::string>("host");
uint16_t port = *conn->get_as<uint16_t>("port");
What i am doing wrong?
This program:
#include <iostream>
#include "cpptoml.h"
int main() {
std::shared_ptr<cpptoml::table> root = cpptoml::make_table();
root->insert("Double", 12.3);
auto d = root->get_as<double>("Double");
std::cout << *d << std::endl;
}
is giving me this error from clang (also see similar error from g++):
$ make
clang -c -Wall -std=c++11 -g -I../../cpptoml/include main.cc -o main.o
In file included from main.cc:2:
../../cpptoml/include/cpptoml.h:1113:20: error: call to 'get_impl' is ambiguous
return get_impl<T>(get(key));
^~~~~~~~~~~
main.cc:5:20: note: in instantiation of function template specialization 'cpptoml::table::get_as<double>' requested here
auto d = config->get_as<double>("Double");
^
../../cpptoml/include/cpptoml.h:892:1: note: candidate function [with T = double]
get_impl(const std::shared_ptr<base>& elem)
^
../../cpptoml/include/cpptoml.h:939:1: note: candidate function [with T = double]
get_impl(const std::shared_ptr<base>& elem)
^
1 error generated.
make: *** [main.o] Error 1
I only am seeing it for get_as<double>
(or float).
When you try to output a toml table with
out_stream << my_toml_table;
All string values are invariably written with a single-line quotation.
Would it be possible to add options to force writing multiline strings?
I know it is possible to do it manually using the accept
method, but it would be nice to have a built-in feature.
I'm also available for submitting a PRs if you tell me how you want it done.
According to the Keys
section of the TOML "standard" (https://github.com/toml-lang/toml/blob/d3d6f32b73369a9bfd8411a143718f7a4a84ee2c/README.md#user-content-keys), keys with unquoted dots should be interpreted as nested tables. However, cpptoml recognizes them as quoted keys, yielding unexpected results.
Example input
foo.bar = "baz"
[happy]
birthday = "to you"
What cpptoml does
When parsing the above input and pushing the root table on an ostream
, the result is something like the following:
"foo.bar" = "baz"
[happy]
birthday = "to you"
What it should be doing
As far as I can tell (please correct me if I'm wrong), this is what should be recognized:
[foo]
bar = "baz"
[happy]
birthday = "to you"
It doesn't parse hex values. It fails with "Unidentified trailing character 'x'---did you forgot a '#'?"
Testcase:
# test.toml:
TestHex = 0x55
// main.cpp
auto config = cpptoml::parse_file("uc2ui.toml");
auto cfgTestHex = config->get_as<int64_t>("TestHex");
Compiling with visual studio 2015 32-bit, within a QT 5.10.0 framework
as e.g. used in redox toml files
🚫 Input TOML could not be parsed
Value must follow after a '=' at line 13
12: #binutils = {}
➤ 13: contain = {}
14: coreutils = {}
Simplest example:
[foo]
bar = {}
echo -e "[foo]\n bar = {}" | ./tomlutil -
🚫 Input TOML could not be parsed
Value must follow after a '=' at line 2
1: [foo]
➤ 2: bar = {}
When the application's locale has a decimal comma then all doubles will be parsed as integers.
Such a situation can arise, for example, when developing a GUI application, e.g. with Gtkmm.
There should be some added functions that simplify creating a TOML document in code (and subsequently writing it out).
Specifically there should be an lvalue version of table::insert() for simple items.
Additionally, having to create shared pointers for each type and insert them into tables is...cumbersome. There are two ways I can see of fixing this:
(1) is cleaner, but (2) will be more efficient. I don't have a good feeling on which is the right way to go.
Anyhow, once we hash out a design, I'm happy to add this stuff. Let's discuss.
How to fetch values from array, such as:
key1=["val1", "val2", "val3"]
key1 = [ ["txt1", "txt2", "txt3"], [1, 2, 3] ]
I compile my code base with as much warnings as possible and cpptoml reports a couple of variables shadowing:
In file included from src/main.cxx:35:
src/cpptoml.h:1940:42: warning:
declaration shadows a local variable [-Wshadow]
= [&](std::string::iterator& it, std::string::iterator& end) {
^
src/cpptoml.h:1929:51: note: previous
declaration is here
parse_multiline_string(std::string::iterator& it,
^
src/cpptoml.h:1940:69: warning:
declaration shadows a local variable [-Wshadow]
= [&](std::string::iterator& it, std::string::iterator& end) {
^
src/cpptoml.h:1930:51: note: previous
declaration is here
std::string::iterator& end, char delim)
I guess simply using a different variable name for the inner loops will fix this.
This is on c926989.
Hi,
I think the latest make_xxx()
function additions broke the windows build. I am getting a couple of errors in the following form in VS 2013.
Error 1 error C2664: 'std::shared_ptr<cpptoml::value<double>> cpptoml::make_value<double>(T &&)' : cannot convert argument 1 from 'int64_t' to 'double &&' d:\hog-pom\utils\cpptoml.h 364
I fell a little behind updating RcppTOML to the updated cpptoml but just did so. It turns out that I no longer pass all the regression tests I have, in particular I now fail to parse this line with
key2 = 1e1_000
at least on my teeny i386 laptop.
Could this be related to this commit of yours ?
I have environment that does not permit exceptions. I'd like to use your library, but I will need no exceptions.
As its stands I think the library uses exceptions and that means that I am better off with C based TOML library, unless you tell me that cpptoml throws in so few cases I can adopt the library.
Thank you
A new TOML v0.5.0 has been released:
https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.5.0.md
Changelog available here:
https://github.com/toml-lang/toml/releases/tag/v0.5.0
Doubles that are integers (i.e. 3.0) don't get a decimal point when written out by toml_writer which will cause the TOML to be invalid in the case where they were members of an array of doubles. A reasonable fix is below, though you may want to do some saving and restoring of ostream flags as well. I'd do it myself but I'm knee deep in something else. There is also another issue with the precision of doubles being written out...currently it's whatever the stream's current setting is. We may want to do something about that.
/**
* Write out a double.
*/
void write(const value<double>& v)
{
stream_ << std::showpoint;
write(v.get());
}
toml-lang/toml#437 says UTF-8 BOM must be allowed.
So I found this merge that seems to be related to fixing this: https://github.com/skystrife/cpptoml/pull/18/files
I load up this toml:
[graphics]
gamma = 1.1
I load this toml and save this toml doing:
auto file = cpptoml::parse_file("in.toml")
std::ofstream out("out.toml", std::ios::trunc | std::ios::out);
out << (*file);
out.close();
And it results in this toml being generated:
[graphics]
gamma = 1.1000000000000001
I'm trying to compile in Windows and I hit the following error:
cpptoml.h(570): error C2280: 'std::shared_ptr<cpptoml::value<double>> std::dynamic_pointer_cast<cpptoml::value<double>,cpptoml::base>(const std::shared_ptr<cpptoml::base> &) noexcept': attempting to reference a deleted function
Is there any solution?
Hi,
Not really an issue but I thought you might want to be aware that when using the windows api, you must use the following code:
#include <windows.h>
#undef max
#undef min
If you don't, it won't compile when using cpptoml and will throw warning when not using it.
Thanks.
tinytoml claims to support TOML 0.4.0, you might want to reflect that in your README
Hi, using
[services]
modules = [
"mdns",
]
[services.trigger]
# Possible options: "udp", "flic"
mode = "udp"
[services.trigger.udp]
port = 8875
[services.trigger.flic]
latency = "NormalLatency"
uuids = [
"aa:bb:cc:dd:ee:ff",
"11:22:33:44:55:66",
]
// Works:
auto services_t = file_conf->get_table("services");
for (const auto &val : *services_t->get_array_of<std::string>("modules")) {
services.modules.emplace_back(val); // works
}
// auto trigger_t = services_t->get_table("trigger");
// auto flic_t = trigger_t->get_table("flic");
// Doesn't work:
auto flic_t = file_conf->get_table_qualified("services.trigger.flic");
for (const auto &val : *flic_t->get_array_of<std::string>("uuids")) {
services.trigger.flic.uuids.emplace_back(val); // Cannot access memory at address 0x29
}
Am I missing something?
When parsing toml data that is supplied via istringstream that contains "\r\n", the getline behaviour is broken as the \r remains. A fix would probably be http://stackoverflow.com/questions/6089231/getting-std-ifstream-to-handle-lf-cr-and-crlf/6089413#6089413
happens with with visual studio 2015 on win10
Sorry to be rather pedantic, but the Visual C++ compiler emits the following warning for the re-declaration of 'v' in the void base::accept(Visitor&&, Args&&...)
template function between lines 2247-2263:
warning C4456: declaration of 'v' hides previous local declaration
Is there a reason why the code is structured in this way?
Thanks!
Platform:
Visual Studio 2013, x86 program
master branch (941227b)
1>cpptoml.h(161): error C2144: syntax error : 'int' should be preceded by ';'
1>cpptoml.h(161): error C2873: 'datetime' : symbol cannot be used in a using-declaration
1>cpptoml.h(161): error C2513: 'int' : no variable declared before '='
This snippet does not work properly all the time:
auto &&version = library->get_as<std::string>("version").value_or("master");
Sometimes it works sometimes it does not.
Workaround: do std::string instead auto &&, like this:
std::string version = library->get_as<std::string>("version").value_or("master");
You cannot return by reference here, because alternative may be rvalue:
Line 91 in 13fb18e
With some g++ (version 5.3.0) I got this warning:
/home/jmlemetayer/development/misc/cpptoml/include/cpptoml.h: In static member function ‘static std::__cxx11::string cpptoml::toml_writer::escape_string(const string&)’:
/home/jmlemetayer/development/misc/cpptoml/include/cpptoml.h:3063:26: warning: comparison is always true due to limited range of data type [-Wtype-limits]
else if (*it >= 0x0000 && *it <= 0x001f)
^
This is raised by this line:
Line 3063 in 2051836
cpptoml.h @ line 1474
template <>
inline typename array_of_trait<array>::return_type
table::get_qualified_array_of<array>(const std::string& key) const
{
if (auto v = get_array(key)) // why not get_array_qualified?
......
}
I'm currently working on a project which prohibits the use of RTTI. Is there any way in which we can avoid the dynamic_pointer_cast
calls, or are they inherent to the design of cpptoml?
I was following the usage notes in the README but I just couldn't get the value.
Here's my code:
in main.cpp
int main(int argc, char const *argv[]) {
cpptoml::table t = cpptoml::parse_file("config.toml");
cpptoml::option<float> rainrate = t->get_qualified_as<float>("rainRate");
cout<< rainrate <<endl;
(...)
in config.toml
## rain parameters ##
rainRate = 1.47 # mm/hr
[DiameterDistribution]
mean = 0.62818
stdev = 0.40985
(...)
even if I change the types into auto
, it still gives the error
cmake 3.11.1
gcc/g++ 6.4.0
Ubuntu 18.04
We have some use cases where an #include <>
-alike would be really handy. I looked over at the TOML repo and eg in #36 this is dismissed as against the minimalist design. I do have some sympathy for this rejection.
Yet this feature would be handy. Would you entertain the idea here to go 'slightly beyond' the spec, or do you think that is a bad idea?
I think I can also get to this from my RcppTOML package by potentially postprocessing the initial read, and responding to a particular token, and then merge. Better idea, maybe?
Just including cpptoml.h
compiles fine with VS2017 and VS2015 but not with VS2013 which is the one that I need for compatibility reasons.
Can you please fix that?
1>------ Build started: Project: Project2, Configuration: Debug x64 ------
1>Source.cpp
1>c:\users\d\source\repos\project2\project2\cpptoml.h(63): error C2797: 'cpptoml::option<std::vector<std::shared_ptr<cpptoml::array>,std::allocator<_Ty>>>::value_': list initialization inside member initializer list or non-static data member initializer is not implemented
1> with
1> [
1> _Ty=std::shared_ptr<cpptoml::array>
1> ]
1> c:\users\default.laptop-bgosj7n3\source\repos\project2\project2\cpptoml.h(62) : while compiling class template member function 'cpptoml::option<std::vector<std::shared_ptr<cpptoml::array>,std::allocator<_Ty>>>::option(T)'
1> with
1> [
1> _Ty=std::shared_ptr<cpptoml::array>
1>, T=std::vector<std::shared_ptr<cpptoml::array>,std::allocator<std::shared_ptr<cpptoml::array>>>
1> ]
1> c:\users\default.laptop-bgosj7n3\source\repos\project2\project2\cpptoml.h(893) : see reference to function template instantiation 'cpptoml::option<std::vector<std::shared_ptr<cpptoml::array>,std::allocator<_Ty>>>::option(T)' being compiled
1> with
1> [
1> _Ty=std::shared_ptr<cpptoml::array>
1>, T=std::vector<std::shared_ptr<cpptoml::array>,std::allocator<std::shared_ptr<cpptoml::array>>>
1> ]
1> c:\users\default.laptop-bgosj7n3\source\repos\project2\project2\cpptoml.h(894) : see reference to class template instantiation 'cpptoml::option<std::vector<std::shared_ptr<cpptoml::array>,std::allocator<_Ty>>>' being compiled
1> with
1> [
1> _Ty=std::shared_ptr<cpptoml::array>
1> ]
1>Done building project "Project2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Thanks and regards
Here's the input that triggers the problem:
heap_bof2.txt
Feed it into master(07a7b07) cpptoml-parser built with AddressSanitizer will crash the parser:
> cat heap_bof2 | cpptoml-parser
==12673==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300000002f at pc 0x0000005d69e1 bp 0x7fffd176a5c0 sp 0x7fffd176a5b8
READ of size 1 at 0x60300000002f thread T0
#0 0x5d69e0 in cpptoml::parser::consume_whitespace(__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&) (/home/grieve/scratch/fuzz_toml/cpptoml/build/cpptoml-parser+0x5d69e0)
#1 0x5e40cd in cpptoml::parser::parse_single_table(__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, cpptoml::table*&) (/home/grieve/scratch/cpptoml/build/cpptoml-parser+0x5e40cd)
#2 0x5d7bbc in cpptoml::parser::parse_table(__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, cpptoml::table*&) (/home/grieve/scratch/cpptoml/build/cpptoml-parser+0x5d7bbc)
#3 0x59786c in cpptoml::parser::parse() (/home/grieve/scratch/cpptoml/build/cpptoml-parser+0x59786c)
#4 0x58bb2a in main (/home/grieve/scratch/cpptoml/build/cpptoml-parser+0x58bb2a)
#5 0x7f4e66b414c9 in __libc_start_main (/usr/lib/libc.so.6+0x204c9)
#6 0x492eb9 in _start (/home/grieve/scratch/cpptoml/build/cpptoml-parser+0x492eb9)
0x60300000002f is located 0 bytes to the right of 31-byte region [0x603000000010,0x60300000002f)
allocated by thread T0 here:
#0 0x587260 in operator new(unsigned long) /home/grieve/LLVM/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:92
#1 0x7f4e67b3f0e9 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate(unsigned long, unsigned long, char const*, unsigned long) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:317
It is a malformed input, and the expected behavior is to reject the input instead of crashing.
ex:
some_property = 500.0 // value->as() fine
some_property = 500 // value->as() results in crash
while this is correct in toml spec, it puts the onus of type correctness on the toml file creator, which IMO, seems to ask too much of them. perhaps value->as() & value->as<int64_t>() should work for both integer and float property types?
The toml specifications is not allowing leading zeros even for the exponent of scientific numbers violating C99 standard. The result is an inconsistency between the toml writer which follows C99 and the toml reader.
A workaround is to force the writer to use a fixed floating field.
stream << std::fixed << std::setprecision(9);
A better solution would be to relax the standard and follow C99 which is widely used.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.