Commit graph

136 commits

Author SHA1 Message Date
Andrew Kelley
6f0198cadb Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"
This reverts commit 0c99ba1eab, reversing
changes made to 5f92b070bf.

This caused a CI failure when it landed in master branch due to a
128-bit `@byteSwap` in std.mem.
2023-10-22 12:16:35 -07:00
Jacob Young
32e85d44eb x86_64: disable failing tests, enable test-std testing 2023-10-21 10:55:41 -04:00
Jacob Young
2e6e39a700 x86_64: fix bugs and disable erroring tests 2023-10-21 10:55:41 -04:00
Jonathan Marler
223f62acbd
std.json: add fmt function (#17055)
Adds std.json.fmt which returns a std.fmt Formatter that formats any
given value using std.json.stringify.
2023-09-13 18:24:59 -04:00
Techatrix
7827265ea8
json: respect max_value_len when parsing std.json.Value (#17107) 2023-09-11 17:00:06 -04:00
Gregory Anders
cab9da35bd std: enable FailingAllocator to fail on resize
Now that allocator.resize() is allowed to fail, programs may wish to
test code paths that handle resize() failure. The simplest way to do
this now is to replace the vtable of the testing allocator with one
that uses Allocator.noResize for the 'resize' function pointer.

An alternative way to support this testing capability is to augment the
FailingAllocator (which is already useful for testing allocation failure
scenarios) to intentionally fail on calls to resize(). To do this, add a
'resize_fail_index' parameter to the FailingAllocator that causes
resize() to fail after the given number of calls.
2023-09-06 19:06:32 +03:00
Ian Johnson
f3f554b9b8
std.json: avoid stale pointers when parsing Value (#16864)
Closes #16861

Using `alloc_if_needed` when parsing a `Value` allows receiving a token
which points to the buffer of the underlying `Reader`. This token will
no longer be valid after the `Reader`'s buffer is refilled, which will
happen with large values. Using `alloc_always` avoids this issue by
ensuring the returned tokens always own their data independently of the
underlying buffer.
2023-08-17 07:52:46 -04:00
Ryan Liptak
a155e35850
std.json: Fix decoding of UTF-16 surrogate pairs (#16830)
* std.unicode: Add more UTF-16 decoding functions

This mostly makes parts of Utf16LeIterator reusable

* std.json: Fix decoding of UTF-16 surrogate pairs

Before this commit, there were 524,288 codepoints that would get decoded improperly. After this commit, there are 0.

Fixes #16828
2023-08-15 09:11:59 -04:00
Philipp Lühmann
d34201c849
std.json: stringify enum literals (#16742) 2023-08-08 23:26:46 +00:00
Jonathan Marler
2046880de8 std.json: josh review fixes
* renamed enum_big_numbers_quoted option to enum_nonportable_numbers_as_strings
* updated stringify doc to mention the option

I also reversed the logic to determine whether an integer is nonportable,
it seemed easier to reason about.

I also took a stab at applying the new option to floats, but, I got stuck
at trying to print large floats, not sure if Zig supports that yet.
2023-08-06 09:25:21 -06:00
Jacob Young
1cce539ddc json.stringify: properly implement RFC8259 recommendation
The previous magic numbers used `1 << 52`, which did not account for the
implicit leading one in the floating point format.  The RFC is correct
when it uses an exponent of 53.  Technically these exclusive endpoints
are also representable, but everyone including the RFC seems to use them
exclusively.

Also, delete special case optimizations related to the type which have
already been implemented in the zig compiler to produce comptime values
for tautological runtime comparisons.
2023-08-06 00:35:10 -04:00
Jonathan Marler
7dacf77745 std.json: fix roundtrip stringify for large integers
std.json follows interoperability recommendations from RFC8259 to limit
JSON number values to those that fit inside an f64.  However, since Zig
supports arbitrarily large JSON numbers, this breaks roundtrip data
congruence.

To appease both use cases, I've added an option `emit_big_numbers_quoted`
to StringifyOptions.  It's disabled by default which preserves roundtrip
but can be enabled to favor interoperability.
2023-08-05 21:56:00 -06:00
Josh Wolfe
8f2af35eaa std.json: WriteStream.print instead of writePreformatted 2023-07-27 10:23:58 -07:00
Josh Wolfe
c72a9feabe
std.json: support parsing json at comptime using FixedBufferAllocator (#16488) 2023-07-22 18:52:26 -04:00
Josh Wolfe
2ad16248d7
std.json.WriteStream: eliminate dead memory in optimized modes (#16485) 2023-07-22 18:49:59 -04:00
Garrett
04c7b55de4
std.json: fix key allocation in HashMap for streaming json parsing (#16422) 2023-07-22 22:33:50 +00:00
Josh Wolfe
8924f81d8c
std.json: Unify stringify and writeStream (#16405) 2023-07-21 19:56:46 -04:00
antlilja
b463e429b8 Remove len parameter from splat in standard lib 2023-07-12 15:35:57 -07:00
Techatrix
3bf0b8eada explicitly specify error set of std.json.stringify 2023-07-10 10:50:57 -07:00
Josh Wolfe
874d2dd9f7
std.json: add generic hash map that parses/stringifies with arbitrary string keys (#16366)
* expose innerParseFromValue
2023-07-09 22:18:59 -04:00
Garrett
131bfe2f74
std.json: expose innerParse and add .allocate option (#16312) 2023-07-08 22:49:31 -04:00
Techatrix
89396ff02b
add jsonParseFromValue to std.json.Value (#16324) 2023-07-07 23:33:47 -04:00
Evin Yulo
ba6e5e65a0 json: give enums a default stringify implementation 2023-07-03 20:33:36 -07:00
yujiri8
b26fa4ec4b
add docstring to std.json.stringify (#16241) 2023-07-03 19:26:11 -04:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
Josh Wolfe
0f2339f55b
std: json.parseFromValue() (#15981) 2023-06-20 19:01:34 -04:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
Josh Wolfe
32cb9462ff
std: Support user-provided jsonParse method. Unify json.Parser and json.parse* (#15705) 2023-06-19 11:21:37 -04:00
Josh Wolfe
018b743c7a
std: Rewrite low-level json api to support streaming (#15602) 2023-05-13 14:31:53 -04:00
Andrew Kelley
6261c13731 update codebase to use @memset and @memcpy 2023-04-28 13:24:43 -07:00
Janne Hellsten
61236c2aa1
std: @Vector support for std.json.parse 2023-04-26 00:52:17 +03:00
Marcus Ramse
1e087d3a64 std.json: support tuples 2023-03-21 15:01:45 +02:00
Andrew Kelley
aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
John Schmidt
b1dd4b17d8 std.json: don't free struct default values
Closes https://github.com/ziglang/zig/issues/9509.
2023-02-04 20:51:15 +01:00
John Schmidt
b42caff2a2 std.json: avoid dangling pointers in ValueTree
Closes https://github.com/ziglang/zig/issues/5229.
2023-02-04 20:34:47 +01:00
John Schmidt
73c857415e std.json: fix parsing of structs with default value const pointers 2023-02-04 18:28:36 +01:00
Jon-Eric Cook
4c11684184
std.json: check output and source lengths in std.json 2023-01-28 16:26:36 +00:00
ominitay
889efddd1a std.json: Fix parsing of large numbers
Numbers greater than about 2^53 are encoded as strings in JSON.
std.json.parseInternal previously errored out in this condition.
2022-07-23 13:52:16 +03:00
Andrew Kelley
c9006d9479 std.json: move tests to json/test.zig file
This accomplishes two things:
 * Works around #8442 by putting stage1-specific logic in to disable all
   the std.json tests.
 * Slightly reduces installation size of zig since std lib files ending
   in "test.zig" are excluded from being installed.
2022-07-07 00:05:21 -07:00
May B
ea13437ac5
std.json: Support disabling indent (#11823)
Newline Delimited JSON (ndjson) expect compact json without newline inside its content
Add None to StringfyOptions.indent and move newline writeByte inside StringfyOptions.outputIndent
2022-06-29 11:53:01 +02:00
Lee Cannon
1093b09a98
allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
Lee Cannon
85de022c56
allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Matthew Borkowski
e902c19c0e
std/json: Fix premature closing brace being considered valid JSON
return error from StreamingParser when reading closing brace when expecting value for an object key
2021-05-13 11:11:28 +02:00
Veikka Tuominen
fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
xackus
a5007d819a std.meta: add isError 2021-04-11 16:26:29 +02:00
Lewis Gaul
7302b096bd
Tidy-up in json test module (#8431)
* Switch json testing 'roundTrip()' to use FixedBufferStream, improve error handling, remove comptime from param

* Add 'try' to calls to roundTrip() that can now return an error

* Remove comptime from params in json testing, replace expect(false) with letting error propagate

* Add 'try' to calls to ok() that can now return an error

Co-authored-by: Lewis Gaul <legaul@cisco.com>
2021-04-04 19:27:47 -04:00
Lewis Gaul
74fd7107e8
Switch std.json to use an ordered hashmap 2021-04-04 10:16:59 +02:00
daurnimator
d4af35b3fe HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02:00
Jay Petacat
a9b505fa77 Reduce use of deprecated IO types
Related: #4917
2021-01-07 23:48:58 -08:00