Skip to content

Commit

Permalink
Merge branch 'master' into SNOW-1763421-fix-failing-mac-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jszczerbinski authored Oct 29, 2024
2 parents 2c24d0d + ab9ca1d commit ab5d1aa
Show file tree
Hide file tree
Showing 14 changed files with 1,806 additions and 1 deletion.
1 change: 1 addition & 0 deletions ci/build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ download_build_component aws "$SCRIPTS_DIR/build_awssdk.sh" "$target"
download_build_component azure "$SCRIPTS_DIR/build_azuresdk.sh" "$target"
download_build_component cmocka "$SCRIPTS_DIR/build_cmocka.sh" "$target"
download_build_component arrow "$SCRIPTS_DIR/build_arrow.sh" "$target"
download_build_component picojson "$SCRIPTS_DIR/build_picojson.sh" "$target"

# very tight diskspace limit on github runners, clear deps folder with all .o files
if [[ -n "$GITHUB_ACTIONS" ]]; then
Expand Down
3 changes: 3 additions & 0 deletions ci/build_win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set aws_build_script="%scriptdir%..\scripts\build_awssdk.bat"
set azure_build_script="%scriptdir%..\scripts\build_azuresdk.bat"
set cmocka_build_script="%scriptdir%..\scripts\build_cmocka.bat"
set arrow_build_script="%scriptdir%..\scripts\build_arrow.bat"
set picojson_build_script="%scriptdir%..\scripts\build_picojson.bat"
set libsnowflakeclient_build_script="%scriptdir%..\scripts\build_libsnowflakeclient.bat"

set upload_artifact_script="%scriptdir%container\upload_artifact.bat"
Expand Down Expand Up @@ -59,6 +60,8 @@ goto :EOF
if %ERRORLEVEL% NEQ 0 goto :error
call :download_build_component arrow "%arrow_build_script%" "%dynamic_runtime%"
if %ERRORLEVEL% NEQ 0 goto :error
call :download_build_component picojson "%picojson_build_script%" "%dynamic_runtime%"
if %ERRORLEVEL% NEQ 0 goto :error
if defined GITHUB_ACTIONS (
rd /S /Q %scriptdir%\..\deps
)
Expand Down
4 changes: 4 additions & 0 deletions deps/picojson/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*~
a.out
test-core
test-core-int64
25 changes: 25 additions & 0 deletions deps/picojson/Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Revision history for picojson

1.3.0 2015-02-25 13:05:00+0900
- `make check` is now synonym of `make test` (#62)
- operator= is now safe when part of LHS is being assigned, as well as exception-safe (#66)

1.2.1 2014-12-16 15:33:00+0900
- bundle the contents of `picotest/` (#61)

1.2.0 2014-12-15 16:20:00+0900
- `make install` to install picojson.h (#58)
- two-argument `picojson::parse()` for ease-of-use (#57)

1.1.1 2014-06-25 10:35:00+0900
- tweaks to suppress compiler errors / warning (#38 #39)
- clarify the licenses of the files in exmaple/ (#42)

1.1 2014-06-16 12:57:00+0900
- added experimental support for int64 type (#34)
- by default, throw std::runtime_error instead of using assert for runtime errors (#33)
- refine compatibility regarding the use of isinf/isnan (#29, #36)
- remove `.get<int>()` (#35)

1.0 2014-06-05 12:54:00+0900
- initial release with a version number
25 changes: 25 additions & 0 deletions deps/picojson/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright 2009-2010 Cybozu Labs, Inc.
Copyright 2011-2014 Kazuho Oku
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
26 changes: 26 additions & 0 deletions deps/picojson/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
prefix=/usr/local
includedir=$(prefix)/include

check: test

test: test-core test-core-int64
./test-core
./test-core-int64

test-core: test.cc picotest/picotest.c picotest/picotest.h
$(CXX) -Wall test.cc picotest/picotest.c -o $@

test-core-int64: test.cc picotest/picotest.c picotest/picotest.h
$(CXX) -Wall -DPICOJSON_USE_INT64 test.cc picotest/picotest.c -o $@

clean:
rm -f test-core test-core-int64

install:
install -d $(DESTDIR)$(includedir)
install -p -m 0644 picojson.h $(DESTDIR)$(includedir)

uninstall:
rm -f $(DESTDIR)$(includedir)/picojson.h

.PHONY: test check clean install uninstall
195 changes: 195 additions & 0 deletions deps/picojson/README.mkdn
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# PicoJSON - a C++ JSON parser / serializer

Copyright &copy; 2009-2010 Cybozu Labs, Inc.
Copyright &copy; 2011-2015 Kazuho Oku

Licensed under [2-clause BSD license](http://opensource.org/licenses/BSD-2-Clause)

## Version

1.3.0 [![Build Status](https://travis-ci.org/kazuho/picojson.svg?branch=rel/1.3.0)](https://travis-ci.org/kazuho/picojson)

## Introduction

PicoJSON is a tiny JSON parser / serializer for C++ with following properties:

- header-file only
- no external dependencies (only uses standard C++ libraries)
- STL-frendly (arrays are represented by using std::vector, objects are std::map)
- provides both pull interface and streaming (event-based) interface

## Reading JSON using the pull interface

There are several ways to use the pull (DOM-like) interface of picojson.

The easiest way is to use the two-argument `parse` function.

```
std::string json = "[ \"hello JSON\" ]";
picojson::value v;
std::string err = picojson::parse(v, json);
if (! err.empty()) {
std:cerr << err << std::endl;
}
```

Four-argument `parse` function accepts a pair of iterators, and returns the end position of the input.

```
const char* json = "{\"a\":1}";
picojson::value v;
std::string err;
const char* json_end = picojson::parse(v, json, json + strlen(json), &err);
if (! err.empty()) {
std::cerr << err << std::endl;
}
```

```
std::istream_iterator input(std::cin);
picojson::value v;
std::string err;
input = picojson::parse(v, input, std::istream_iterator(), &err);
if (! err.empty()) {
std::cerr << err << std::endl;
}
```

It is also possible to use the `>>` operator to parse the input, however this interface is not thread-safe.

```
picosjon::value v;
std::cin >> v;
std::string err = picojson::get_last_error();
```

## Accessing the values

Values of a JSON object is represented as instances of picojson::value class.

<pre>
namespace picojson {

class value {
...

public:

typedef std::vector&lt;value&gt; array;
typedef std::map&lt;std::string, value&gt; object;

value(); // create a null object
explicit value(bool b); // create a boolean object
explicit value(double n); // create a number object
explicit value(const std::string& s); // create a string object
explicit value(const array& a); // create an array object
explicit value(const object& o); // create an "object"

bool is&lt;picojson::null&gt;() const; // check if the object is "null"

bool is&lt;bool&gt;() const; // check if the object is a boolean
const bool& get&lt;bool&gt;() const; // const accessor (usable only if the object is a boolean)
bool& get&lt;bool&gt;(); // non-const accessor (usable only if the object is a boolean)

bool is&lt;double&gt;() const; // check if the object is a number
const double& get&lt;double&gt;() const; // const accessor (usable only if the object is a number)
double& get&lt;double&gt;(); // non-const accessor (usable only if the object is a number)

bool is&lt;std::string&gt;() const; // check if the object is a string
const std::string& get&lt;std::string&gt;() const;
// const accessor (usable only if the object is a string)
std::string& get&lt;std::string&gt;(); // non-const accessor (usable only if the object is a string)

bool is&lt;array&gt;() const; // check if the object is an array
const array& get&lt;array&gt;() const; // const accessor (usable only if the object is an array)
array& get&lt;array&gt;(); // non-const accessor (usable only if the object is an array)

bool is&lt;object&gt;() const; // check if the object is an "object"
const object& get&lt;object&gt;() const; // const accessor (usable only if the object is an object)
object& get&lt;object&gt;(); // non-const accessor (usable only if the object is an array)

bool evaluate_as_boolean() const; // evaluates the object as a boolean

std::string serialize() const; // returns the object in JSON representation
template<typename Iter> void serialize(Iter os) const;
// serializes the object in JSON representation through an output iterator

std::string to_str() const; // returns the object in string (for casual use)

};

}
</pre>

The code below parses a JSON string and prints the contents of the object.

<pre>
picojson::value v;

// parse the input
std::cin &gt;&gt; v;
std::string err = picojson::get_last_error();
if (! err.empty()) {
std::cerr &lt;&lt; err &lt;&lt; std::endl;
exit(1);
}

// check if the type of the value is "object"
if (! v.is&lt;picojson::object&gt;()) {
std::cerr &lt;&lt; "JSON is not an object" &lt;&lt; std::endl;
exit(2);
}

// obtain a const reference to the map, and print the contents
const picojson::value::object& obj = v.get&lt;picojson::object&gt;();
for (picojson::value::object::const_iterator i = obj.begin();
i != obj.end();
++i) {
std::cout &lt;&lt; i-&gt;first &lt;&lt; ': ' &lt;&lt; i-&gt;second.to_str() &lt;&lt; std::endl;
}
</pre>

Please note that the type check is mandatory; do not forget to check the type of the object by calling is&lt;type&gt;() before accessing the value by calling get&lt;type&gt;().

## Reading JSON using the streaming (event-driven) interface

Please refer to the implementation of picojson::default_parse_context and picojson::null_parse_context. There is also an example (examples/streaming.cc) .

## Serializing to JSON

Instances of the picojson::value class can be serialized in three ways, to ostream, to std::string, or to an output iterator.

<pre>
picojson::value v;
...
std::cout &lt;&lt; v;
</pre>

<pre>
picojson::value v;
...
std::string json = v.serialize();
</pre>

<pre>
picojson::value v;
...
v.serialize(std::ostream_iterator(std::cout));
</pre>

## Experimental support for int64_t

Experimental suport for int64_t becomes available if the code is compiled with preprocessor macro `PICOJSON_USE_INT64`.

Turning on the feature will cause following changes to picojson:
- new constructor `picojson::value(int64_t)` is defined
- `is<int64_t>()` and `get<int64_t>()` become available
- numerics in JSON within the bounds of int64_t and not using `.` nor `e`/`E` are considered as int64 type
- the values are also avaliable as `double`s as well (i.e. all values which are `.is<int64_t>() == true` are also `.is<double>() == true`)
- int64 values are converted to double once `get<double>()` is called

Enabling the feature should not cause compatibility problem with code that do not use the feature.

## Further reading

Examples can be found in the <i>examples</i> directory, and on the [Wiki](https://github.com/kazuho/picojson/wiki). Please add your favorite examples to the Wiki.
Loading

0 comments on commit ab5d1aa

Please sign in to comment.