diff --git a/.github/workflows/package-test.yaml b/.github/workflows/package-test.yaml index 1bb57dd72..088356911 100644 --- a/.github/workflows/package-test.yaml +++ b/.github/workflows/package-test.yaml @@ -2,9 +2,9 @@ name: verify package can build on: push: - branches: [develop] + branches: [ develop ] pull_request: - branches: [develop] + branches: [ develop ] env: CARGO_TERM_COLOR: always @@ -14,7 +14,7 @@ env: jobs: ubuntu: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/runas.yml b/.github/workflows/runas.yml index fc8e137a4..f8064be7f 100644 --- a/.github/workflows/runas.yml +++ b/.github/workflows/runas.yml @@ -2,9 +2,9 @@ name: cargo pgrx test --runas on: push: - branches: [develop] + branches: [ develop ] pull_request: - branches: [develop] + branches: [ develop ] env: CARGO_TERM_COLOR: always @@ -12,7 +12,7 @@ env: jobs: ubuntu: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f1ddec851..f9e16464c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,7 +20,7 @@ env: jobs: lintck: name: rustfmt, clippy, et al. - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: "!contains(github.event.head_commit.message, 'nogha')" env: RUSTC_WRAPPER: sccache @@ -97,7 +97,7 @@ jobs: pgrx_tests: name: Linux tests & examples needs: lintck - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: "!contains(github.event.head_commit.message, 'nogha')" env: RUSTC_WRAPPER: sccache @@ -363,7 +363,7 @@ jobs: cargo_pgrx_init: name: cargo pgrx init - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: "!contains(github.event.head_commit.message, 'nogha')" env: RUSTC_WRAPPER: sccache diff --git a/.github/workflows/will-it-blend-develop.yml b/.github/workflows/will-it-blend-develop.yml index d3984dac4..876bd396e 100644 --- a/.github/workflows/will-it-blend-develop.yml +++ b/.github/workflows/will-it-blend-develop.yml @@ -15,7 +15,7 @@ env: jobs: distro_tests: name: Distro tests - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false # We want all of them to run, even if one fails matrix: @@ -36,7 +36,7 @@ jobs: cargo_unlocked_tests: name: Cargo unlocked tests - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false # We want all of them to run, even if one fails matrix: diff --git a/pgrx-tests/src/tests/range_tests.rs b/pgrx-tests/src/tests/range_tests.rs index 3c3afa563..eb482d409 100644 --- a/pgrx-tests/src/tests/range_tests.rs +++ b/pgrx-tests/src/tests/range_tests.rs @@ -141,6 +141,14 @@ mod tests { assert_eq!(matched, Ok(Some(true))); } + #[pg_test] + fn test_empty_anynumeric_range() { + let matched = Spi::get_one::>( + "SELECT accept_range_numeric('[10.5, 10.5)'::numrange)", + ); + assert_eq!(matched, Ok(Some(Range::empty()))); + } + #[pg_test] fn test_accept_range_date() { let matched = diff --git a/pgrx/src/datum/range.rs b/pgrx/src/datum/range.rs index d04af708a..9fc3f95fb 100644 --- a/pgrx/src/datum/range.rs +++ b/pgrx/src/datum/range.rs @@ -348,10 +348,18 @@ where &mut is_empty, ); - // SAFETY: The lower_bound/upper_bound RangeBound value's .val will be a valid Datum of the T type - // If the range is_empty or either bound is infinite then .val = (Datum) 0 - let lower = RangeBound::from_pg(lower_bound); - let upper = RangeBound::from_pg(upper_bound); + let range = if is_empty { + // empty ranges cannot go through `RangeBound::from_pg()` as the bound's `.val` + // Datum will be zero, and for a pass-by-reference range type, that's an instant segfault + Range::empty() + } else { + // SAFETY: The lower_bound/upper_bound RangeBound value's .val will be a valid Datum of the T type + // If the range is_empty or either bound is infinite then .val = (Datum) 0, which we handled above + let lower = RangeBound::from_pg(lower_bound); + let upper = RangeBound::from_pg(upper_bound); + + Range { inner: Some((lower, upper)) } + }; if !std::ptr::eq(ptr, range_type.cast()) { // SAFETY: range_type was allocated by Postgres in the call to @@ -359,7 +367,7 @@ where pg_sys::pfree(range_type.cast()); } - Some(Range { inner: if is_empty { None } else { Some((lower, upper)) } }) + Some(range) } } }