Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7.x test #1798

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: codspeed-benchmarks

on:
push:
branches:
- "main"
pull_request:
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup rust toolchain, cache and cargo-codspeed binary
uses: moonrepo/setup-rust@v0
with:
channel: stable
cache-target: release
bins: cargo-codspeed

- name: Build the benchmark target(s)
run: cargo codspeed build -p benchmarks

- name: Run the benchmarks
uses: CodSpeedHQ/action@v3
with:
run: cargo codspeed run -p benchmarks
token: ${{ secrets.CODSPEED_TOKEN }}
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@

### Changed

## 7.1.3 - 2023-01-15

### Thanks

- @Shadow53

### Fixed

- panic in `many` and `count` combinators when the output type is zero sized

## 7.1.2 - 2023-01-01

### Thanks
Expand Down Expand Up @@ -1475,7 +1485,8 @@ Considering the number of changes since the last release, this version can conta

## Compare code

* [unreleased](https://github.com/Geal/nom/compare/7.1.2...HEAD)
* [unreleased](https://github.com/Geal/nom/compare/7.1.3...HEAD)
* [7.1.2](https://github.com/Geal/nom/compare/7.1.2...7.1.3)
* [7.1.2](https://github.com/Geal/nom/compare/7.1.1...7.1.2)
* [7.1.1](https://github.com/Geal/nom/compare/7.1.0...7.1.1)
* [7.1.0](https://github.com/Geal/nom/compare/7.0.0...7.1.0)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "nom"
version = "7.1.2"
version = "7.1.4-test"
authors = [ "[email protected]" ]
description = "A byte-oriented, zero-copy, parser combinators library"
license = "MIT"
Expand Down
6 changes: 4 additions & 2 deletions src/multi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ where
return Err(Err::Failure(E::from_error_kind(input, ErrorKind::ManyMN)));
}

let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES / crate::lib::std::mem::size_of::<O>();
let max_initial_capacity =
MAX_INITIAL_CAPACITY_BYTES / crate::lib::std::mem::size_of::<O>().max(1);
let mut res = crate::lib::std::vec::Vec::with_capacity(min.min(max_initial_capacity));
for count in 0..max {
let len = input.input_len();
Expand Down Expand Up @@ -573,7 +574,8 @@ where
{
move |i: I| {
let mut input = i.clone();
let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES / crate::lib::std::mem::size_of::<O>();
let max_initial_capacity =
MAX_INITIAL_CAPACITY_BYTES / crate::lib::std::mem::size_of::<O>().max(1);
let mut res = crate::lib::std::vec::Vec::with_capacity(count.min(max_initial_capacity));

for _ in 0..count {
Expand Down
11 changes: 11 additions & 0 deletions tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,14 @@ fn issue_1459_clamp_capacity() {
let mut parser = count::<_, _, (), _>(char('a'), usize::MAX);
assert_eq!(parser("a"), Err(nom::Err::Error(())));
}

#[test]
fn issue_1617_count_parser_returning_zero_size() {
use nom::{bytes::complete::tag, combinator::map, error::Error, multi::count};

// previously, `count()` panicked if the parser had type `O = ()`
let parser = map(tag::<_, _, Error<&str>>("abc"), |_| ());
// shouldn't panic
let result = count(parser, 3)("abcabcabcdef").expect("parsing should succeed");
assert_eq!(result, ("def", vec![(), (), ()]));
}
Loading