Skip to content

Commit

Permalink
Merge branch 'main' of github.com:jpsim/Yams into reference_coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
Adora Lynch committed Feb 24, 2025
2 parents b5cb613 + b4b8042 commit 9ccfc69
Show file tree
Hide file tree
Showing 17 changed files with 421 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ tasks:
bazel: 7.x
build_targets:
- '@yams//:Yams'
build_flags:
- "--repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1"
42 changes: 40 additions & 2 deletions .github/workflows/swiftpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,34 @@ jobs:
fi
env: { 'CODECOV_TOKEN': '${{ secrets.CODECOV_TOKEN }}' }

Xcode_Sequoia:
name: macOS 15 with Xcode ${{ matrix.xcode_version }}
strategy:
matrix:
xcode_version: ['15.4', '16.0', '16.2']
runs-on: macos-15
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode_version }}.app
steps:
- uses: actions/checkout@v4
- run: swift -version
- run: YAMS_DEFAULT_ENCODING=UTF16 swift test --parallel
- run: YAMS_DEFAULT_ENCODING=UTF8 swift test --parallel
- name: Code Coverage
if: matrix.xcode_version == '15.4'
run: |
swift test --enable-code-coverage
xcrun llvm-cov export -format="lcov" .build/debug/YamsPackageTests.xctest/Contents/MacOS/YamsPackageTests -instr-profile .build/debug/codecov/default.profdata > coverage.lcov
if [[ -n "${CODECOV_TOKEN}" ]]; then
bash <(curl -s https://codecov.io/bash) -f coverage.lcov
fi
env: { 'CODECOV_TOKEN': '${{ secrets.CODECOV_TOKEN }}' }

Linux:
name: Linux with Swift ${{ matrix.tag }}
strategy:
matrix:
tag: ['5.7', '5.8', '5.9', '5.10']
tag: ['5.7', '5.8', '5.9', '5.10', '6.0']
runs-on: ubuntu-latest
container:
image: swift:${{ matrix.tag }}
Expand All @@ -83,7 +106,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
swift_version: ['5.7.3', '5.8.1', '5.9.1', '5.10.1']
swift_version: ['5.7.3', '5.8.1', '5.9.1', '5.10.1', '6.0']
steps:
- uses: actions/checkout@v4
- uses: compnerd/gha-setup-swift@main
Expand All @@ -108,3 +131,18 @@ jobs:
run: swift build -v
- name: Test
run: swift test -v
Android:
name: Android with Swift ${{ matrix.tag }}
strategy:
matrix:
tag: ['6.0.3']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: skiptools/swift-android-action@v2
with:
swift-version: ${{ matrix.tag }}
# needed for tests that use fixturesDirectory
copy-files: Tests
test-env: TEST_WORKSPACE=1

36 changes: 36 additions & 0 deletions .github/workflows/xcodebuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,39 @@ jobs:
if: always()
run: set -o pipefail && xcodebuild ${{ matrix.xcode_flags }} build -sdk xrsimulator | xcbeautify --renderer github-actions
shell: bash
xcodebuild_Sequoia:
name: macOS 15 with Xcode ${{ matrix.xcode_version }}
strategy:
matrix:
xcode_version: ['15.4', '16.0', '16.2']
xcode_flags: ['-scheme Yams -project Yams.xcodeproj']
runs-on: macos-15
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode_version }}.app
steps:
- uses: actions/checkout@v4
- run: xcodebuild -version
- name: macOS with UTF16
if: always()
run: set -o pipefail && YAMS_DEFAULT_ENCODING=UTF16 xcodebuild ${{ matrix.xcode_flags }} test | xcbeautify --renderer github-actions
shell: bash
- name: macOS with UTF8
if: always()
run: set -o pipefail && YAMS_DEFAULT_ENCODING=UTF8 xcodebuild ${{ matrix.xcode_flags }} test | xcbeautify --renderer github-actions
shell: bash
- name: iPhone Simulator
if: always()
run: set -o pipefail && xcodebuild ${{ matrix.xcode_flags }} test -sdk iphonesimulator -destination "name=iPhone 16" | xcbeautify --renderer github-actions
shell: bash
- name: Apple TV Simulator
if: always()
run: set -o pipefail && xcodebuild ${{ matrix.xcode_flags }} test -sdk appletvsimulator -destination "name=Apple TV 4K (3rd generation)" | xcbeautify --renderer github-actions
shell: bash
- name: watchOS Simulator
if: always()
run: set -o pipefail && xcodebuild ${{ matrix.xcode_flags }} build -sdk watchsimulator | xcbeautify --renderer github-actions
shell: bash
- name: visionOS Simulator
if: always()
run: set -o pipefail && xcodebuild ${{ matrix.xcode_flags }} build -sdk xrsimulator | xcbeautify --renderer github-actions
shell: bash
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@

* None.

## 5.3.1

##### Breaking

* None.

##### Enhancements

* Add Android Support
[Marc Prud'hommeaux](https://github.com/marcprux)
[#437](https://github.com/jpsim/Yams/pull/437)

##### Bug Fixes

* Resolves an issue where Yams would sometimes produce an invalid Anchor/alias
pair when encoding single-value types.

## 5.3.0

##### Breaking
Expand All @@ -27,7 +44,7 @@
YamlAnchorCoding.
[Adora Lynch](https://github.com/lynchsft)
[#125](https://github.com/jpsim/Yams/issues/125)

* Yams is able to encode and decode Tags via YamlTagProviding
and YamlTagCoding.
[Adora Lynch](https://github.com/lynchsft)
Expand Down
8 changes: 3 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,26 @@ GEM
open4 (1.3.4)
public_suffix (4.0.7)
redcarpet (3.6.0)
rexml (3.2.9)
strscan
rexml (3.3.9)
rouge (4.3.0)
ruby-macho (2.5.1)
sassc (2.4.0)
ffi (~> 1.9)
sqlite3 (1.7.3)
mini_portile2 (~> 2.8.0)
strscan (3.1.0)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
xcinvoke (0.3.0)
liferaft (~> 0.0.6)
xcodeproj (1.24.0)
xcodeproj (1.25.1)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)
rexml (>= 3.3.6, < 4.0)

PLATFORMS
ruby
Expand Down
22 changes: 18 additions & 4 deletions Sources/CYaml/include/yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ typedef struct yaml_parser_s {
yaml_error_type_t error;
/** Error description. */
const char *problem;
/** The byte about which the problem occured. */
/** The byte about which the problem occurred. */
size_t problem_offset;
/** The problematic value (@c -1 is none). */
int problem_value;
Expand Down Expand Up @@ -1335,7 +1335,7 @@ yaml_parser_delete(yaml_parser_t *parser);
* Set a string input.
*
* Note that the @a input pointer must be valid while the @a parser object
* exists. The application is responsible for destroing @a input after
* exists. The application is responsible for destroying @a input after
* destroying the @a parser.
*
* @param[in,out] parser A parser object.
Expand Down Expand Up @@ -1456,6 +1456,20 @@ yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event);
YAML_DECLARE(int)
yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document);

/**
* Set the maximum depth of nesting.
*
* Default: 1000
*
* Each nesting level increases the stack and the number of previous
* starting events that the parser has to check.
*
* @param[in] max The maximum number of allowed nested events
*/

YAML_DECLARE(void)
yaml_set_max_nest_level(int max);

/** @} */

/**
Expand Down Expand Up @@ -1734,7 +1748,7 @@ typedef struct yaml_emitter_s {
size_t length;
/** Does the scalar contain line breaks? */
int multiline;
/** Can the scalar be expessed in the flow plain style? */
/** Can the scalar be expressed in the flow plain style? */
int flow_plain_allowed;
/** Can the scalar be expressed in the block plain style? */
int block_plain_allowed;
Expand Down Expand Up @@ -1950,7 +1964,7 @@ yaml_emitter_close(yaml_emitter_t *emitter);
/**
* Emit a YAML document.
*
* The documen object may be generated using the yaml_parser_load() function
* The document object may be generated using the yaml_parser_load() function
* or the yaml_document_initialize() function. The emitter takes the
* responsibility for the document object and destroys its content after
* it is emitted. The document object is destroyed even if the function fails.
Expand Down
41 changes: 41 additions & 0 deletions Sources/CYaml/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
* Public API declarations.
*/

int MAX_NESTING_LEVEL = 1000;

YAML_DECLARE(int)
yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event);

Expand All @@ -80,6 +82,10 @@ yaml_parser_set_parser_error_context(yaml_parser_t *parser,
const char *context, yaml_mark_t context_mark,
const char *problem, yaml_mark_t problem_mark);

static int
yaml_maximum_level_reached(yaml_parser_t *parser,
yaml_mark_t context_mark, yaml_mark_t problem_mark);

/*
* State functions.
*/
Expand Down Expand Up @@ -162,6 +168,12 @@ static int
yaml_parser_append_tag_directive(yaml_parser_t *parser,
yaml_tag_directive_t value, int allow_duplicates, yaml_mark_t mark);

YAML_DECLARE(void)
yaml_set_max_nest_level(int max)
{
MAX_NESTING_LEVEL = max;
}

/*
* Get the next event.
*/
Expand Down Expand Up @@ -217,6 +229,14 @@ yaml_parser_set_parser_error_context(yaml_parser_t *parser,
return 0;
}

static int
yaml_maximum_level_reached(yaml_parser_t *parser,
yaml_mark_t context_mark, yaml_mark_t problem_mark)
{
yaml_parser_set_parser_error_context(parser,
"while parsing", context_mark, "Maximum nesting level reached, set with yaml_set_max_nest_level())", problem_mark);
return 0;
}

/*
* State dispatcher.
Expand Down Expand Up @@ -657,27 +677,43 @@ yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event,
return 1;
}
else if (token->type == YAML_FLOW_SEQUENCE_START_TOKEN) {
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
goto error;
}
end_mark = token->end_mark;
parser->state = YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE;
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit,
YAML_FLOW_SEQUENCE_STYLE, start_mark, end_mark);
return 1;
}
else if (token->type == YAML_FLOW_MAPPING_START_TOKEN) {
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
goto error;
}
end_mark = token->end_mark;
parser->state = YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE;
MAPPING_START_EVENT_INIT(*event, anchor, tag, implicit,
YAML_FLOW_MAPPING_STYLE, start_mark, end_mark);
return 1;
}
else if (block && token->type == YAML_BLOCK_SEQUENCE_START_TOKEN) {
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
goto error;
}
end_mark = token->end_mark;
parser->state = YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE;
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit,
YAML_BLOCK_SEQUENCE_STYLE, start_mark, end_mark);
return 1;
}
else if (block && token->type == YAML_BLOCK_MAPPING_START_TOKEN) {
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
goto error;
}
end_mark = token->end_mark;
parser->state = YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE;
MAPPING_START_EVENT_INIT(*event, anchor, tag, implicit,
Expand Down Expand Up @@ -1022,6 +1058,11 @@ yaml_parser_parse_flow_sequence_entry_mapping_key(yaml_parser_t *parser,
return 0;
return yaml_parser_parse_node(parser, event, 0, 0);
}
else if (token->type == YAML_FLOW_SEQUENCE_END_TOKEN) {
yaml_mark_t mark = token->start_mark;
parser->state = YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE;
return yaml_parser_process_empty_scalar(parser, event, mark);
}
else {
yaml_mark_t mark = token->end_mark;
SKIP_TOKEN(parser);
Expand Down
4 changes: 2 additions & 2 deletions Sources/CYaml/src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
* The tokens BLOCK-SEQUENCE-START and BLOCK-MAPPING-START denote indentation
* increase that precedes a block collection (cf. the INDENT token in Python).
* The token BLOCK-END denote indentation decrease that ends a block collection
* (cf. the DEDENT token in Python). However YAML has some syntax pecularities
* (cf. the DEDENT token in Python). However YAML has some syntax peculiarities
* that makes detections of these tokens more complex.
*
* The tokens BLOCK-ENTRY, KEY, and VALUE are used to represent the indicators
Expand Down Expand Up @@ -3290,7 +3290,7 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,

/* Check if we are at the end of the scalar. */

/* Fix for crash unitialized value crash
/* Fix for crash uninitialized value crash
* Credit for the bug and input is to OSS Fuzz
* Credit for the fix to Alex Gaynor
*/
Expand Down
Loading

0 comments on commit 9ccfc69

Please sign in to comment.