Skip to content

Commit

Permalink
assert, test, and CI misc
Browse files Browse the repository at this point in the history
  • Loading branch information
ijl committed Sep 7, 2023
1 parent 2e4124b commit 3320e85
Show file tree
Hide file tree
Showing 29 changed files with 183 additions and 97 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
matrix:
rust: [
{ version: "1.60" }, # MSRV
{ version: "nightly-2023-06-30" },
{ version: "nightly-2023-08-30" },
]
python: [
{ version: '3.11', abi: 'cp311-cp311' },
Expand Down Expand Up @@ -43,6 +43,9 @@ jobs:
- run: python -m pip install --user -r test/requirements.txt -r integration/requirements.txt

- run: pytest -s -rxX -v test
env:
PYTHONMALLOC: "debug"

- run: ./integration/run thread
- run: ./integration/run http
- run: ./integration/run init
14 changes: 10 additions & 4 deletions .github/workflows/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- run: python3 -m pip install --user -r test/requirements.txt -r integration/requirements.txt mypy

- run: pytest -s -rxX -v test
env:
PYTHONMALLOC: "debug"

- run: ./integration/run thread
- run: ./integration/run http
- run: ./integration/run init
Expand Down Expand Up @@ -69,8 +72,8 @@ jobs:
options: --user 0
steps:
- run: yum install -y clang lld
- run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2023-06-30 --profile minimal -y
- run: rustup component add rust-src --toolchain nightly-2023-06-30-x86_64-unknown-linux-gnu
- run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2023-08-30 --profile minimal -y
- run: rustup component add rust-src --toolchain nightly-2023-08-30-x86_64-unknown-linux-gnu
- uses: actions/checkout@v3

- name: build-std
Expand All @@ -91,6 +94,9 @@ jobs:
- run: python3 -m pip install --user -r test/requirements.txt -r integration/requirements.txt

- run: pytest -s -rxX -v test
env:
PYTHONMALLOC: "debug"

- run: ./integration/run thread
- run: ./integration/run http
- run: ./integration/run init
Expand Down Expand Up @@ -141,7 +147,7 @@ jobs:
RUSTFLAGS: "-C target-feature=-crt-static"
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
with:
rust-toolchain: nightly-2023-06-30
rust-toolchain: nightly-2023-08-30
rustup-components: rust-src
target: ${{ matrix.platform.target }}
manylinux: musllinux_1_1
Expand Down Expand Up @@ -230,7 +236,7 @@ jobs:
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
with:
target: ${{ matrix.target.target }}
rust-toolchain: nightly-2023-06-30
rust-toolchain: nightly-2023-08-30
rustup-components: rust-src
manylinux: auto
args: --release --strip --out=dist --features=no-panic,yyjson -i python${{ matrix.python.version }}
Expand Down
66 changes: 45 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ It benefits from also having a C build environment to compile a faster
deserialization backend. See this project's `manylinux_2_28` builds for an
example using clang and LTO.

The project's own CI tests against `nightly-2023-06-30` and stable 1.60. It
The project's own CI tests against `nightly-2023-08-30` and stable 1.60. It
is prudent to pin the nightly version because that channel can introduce
breaking changes.

Expand Down
2 changes: 2 additions & 0 deletions ci/azure-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ steps:
displayName: install universal2

- bash: pytest -s -rxX -v test
env:
PYTHONMALLOC: "debug"
displayName: pytest
- bash: ./integration/run thread
displayName: thread
Expand Down
2 changes: 1 addition & 1 deletion ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variables:
toolchain: nightly-2023-06-30
toolchain: nightly-2023-08-30

jobs:

Expand Down
2 changes: 2 additions & 0 deletions ci/azure-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ steps:
- script: python.exe -m pip install orjson --no-index --find-links=D:\a\1\s\target\wheels
displayName: install
- script: python.exe -m pytest -s -rxX -v test
env:
PYTHONMALLOC: "debug"
displayName: pytest
- script: python.exe integration\thread
displayName: thread
Expand Down
3 changes: 2 additions & 1 deletion integration/client
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import httpx
port = sys.argv[1]
url = f"http://127.0.0.1:{port}"

timeout = httpx.Timeout(5.0, connect_timeout=5.0)
timeout = httpx.Timeout(5.0)
client = httpx.AsyncClient(timeout=timeout)

stop_time = time.time() + 5
Expand All @@ -30,3 +30,4 @@ async def main():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.run(main())
loop.close()
2 changes: 1 addition & 1 deletion integration/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flask;sys_platform!="win"
gunicorn;sys_platform!="win"
httpx==0.14.3;sys_platform!="win"
httpx==0.24.1;sys_platform!="win"
2 changes: 2 additions & 0 deletions integration/run
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ _dir="$(dirname "${BASH_SOURCE[0]}")"

to_run="${@:-thread http init}"

export PYTHONMALLOC="debug"

if [[ $to_run == *"thread"* ]]; then
"${_dir}"/thread
fi
Expand Down
2 changes: 1 addition & 1 deletion script/develop
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export CFLAGS="-O2 -fno-plt -flto=thin"
export LDFLAGS="${CFLAGS} -fuse-ld=lld -Wl,--as-needed"
export RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=lld"

maturin build --release "$@"
maturin build "$@"

pip install --force target/wheels/*.whl
2 changes: 1 addition & 1 deletion script/pytest
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh -e

pytest -s -rxX --random-order test
PYTHONMALLOC="debug" pytest -s -rxX --random-order test
2 changes: 1 addition & 1 deletion src/deserialize/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ impl CachedKey {
ptr: ptr as *mut c_void,
}
}

pub fn get(&mut self) -> *mut pyo3_ffi::PyObject {
let ptr = self.ptr as *mut pyo3_ffi::PyObject;
debug_assert!(ffi!(Py_REFCNT(ptr)) >= 1);
ffi!(Py_INCREF(ptr));
ptr
}
Expand Down
1 change: 1 addition & 0 deletions src/deserialize/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::ptr::NonNull;
pub fn deserialize(
ptr: *mut pyo3_ffi::PyObject,
) -> Result<NonNull<pyo3_ffi::PyObject>, DeserializeError<'static>> {
debug_assert!(ffi!(Py_REFCNT(ptr)) >= 1);
let buffer = read_input_to_buf(ptr)?;

if unlikely!(buffer.len() == 2) {
Expand Down
6 changes: 4 additions & 2 deletions src/deserialize/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ impl<'de> Visitor<'de> for JsonValue {
str_hash!(pykey),
)
};
py_decref_without_destroy!(pykey);
py_decref_without_destroy!(pyval.as_ptr());
debug_assert!(ffi!(Py_REFCNT(pykey)) >= 2);
reverse_pydict_incref!(pykey);
debug_assert!(ffi!(Py_REFCNT(pyval.as_ptr())) >= 2);
reverse_pydict_incref!(pyval.as_ptr());
}
Ok(nonnull!(dict_ptr))
}
Expand Down
2 changes: 2 additions & 0 deletions src/deserialize/pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub fn get_unicode_key(key_str: &str) -> *mut pyo3_ffi::PyObject {
);
pykey = entry.get();
}
debug_assert!(ffi!(Py_REFCNT(pykey)) >= 1);
debug_assert!(unsafe { (*pykey.cast::<pyo3_ffi::PyASCIIObject>()).hash != -1 });
pykey
}

Expand Down
1 change: 1 addition & 0 deletions src/deserialize/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub fn read_input_to_buf(
buffer = unsafe { std::slice::from_raw_parts(as_str.as_ptr(), as_str.len()) };
} else if unlikely!(is_type!(obj_type_ptr, MEMORYVIEW_TYPE)) {
let membuf = unsafe { PyMemoryView_GET_BUFFER(ptr) };
debug_assert!(ffi!(Py_REFCNT(membuf as *mut pyo3_ffi::PyObject)) >= 1);
if unsafe { pyo3_ffi::PyBuffer_IsContiguous(membuf, b'C' as c_char) == 0 } {
return Err(DeserializeError::invalid(Cow::Borrowed(
"Input type memoryview must be a C contiguous buffer",
Expand Down
4 changes: 2 additions & 2 deletions src/deserialize/yyjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ fn parse_yy_object(elem: *mut yyjson_val) -> NonNull<pyo3_ffi::PyObject> {
let _ = unsafe {
pyo3_ffi::_PyDict_SetItem_KnownHash(dict, pykey, pyval, str_hash!(pykey))
};
py_decref_without_destroy!(pykey);
py_decref_without_destroy!(pyval);
reverse_pydict_incref!(pykey);
reverse_pydict_incref!(pyval);
}
nonnull!(dict)
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ fn raise_loads_exception(err: deserialize::DeserializeError) -> *mut PyObject {
PyTuple_SET_ITEM(args, 1, doc);
PyTuple_SET_ITEM(args, 2, pos);
PyErr_SetObject(typeref::JsonDecodeError, args);
debug_assert!(ffi!(Py_REFCNT(args)) == 2);
Py_DECREF(args);
};
null_mut()
Expand All @@ -231,6 +232,7 @@ fn raise_dumps_exception_fixed(msg: &str) -> *mut PyObject {
let err_msg =
PyUnicode_FromStringAndSize(msg.as_ptr() as *const c_char, msg.len() as isize);
PyErr_SetObject(typeref::JsonEncodeError, err_msg);
debug_assert!(ffi!(Py_REFCNT(err_msg)) == 2);
Py_DECREF(err_msg);
};
null_mut()
Expand All @@ -247,6 +249,7 @@ fn raise_dumps_exception_dynamic(err: &String) -> *mut PyObject {
let err_msg =
PyUnicode_FromStringAndSize(err.as_ptr() as *const c_char, err.len() as isize);
PyErr_SetObject(typeref::JsonEncodeError, err_msg);
debug_assert!(ffi!(Py_REFCNT(err_msg)) == 2);
Py_DECREF(err_msg);

if !cause_exc.is_null() {
Expand All @@ -272,6 +275,7 @@ fn raise_dumps_exception_dynamic(err: &String) -> *mut PyObject {
let err_msg =
PyUnicode_FromStringAndSize(err.as_ptr() as *const c_char, err.len() as isize);
PyErr_SetObject(typeref::JsonEncodeError, err_msg);
debug_assert!(ffi!(Py_REFCNT(err_msg)) == 2);
Py_DECREF(err_msg);
let mut tp: *mut PyObject = null_mut();
let mut val: *mut PyObject = null_mut();
Expand Down
Loading

0 comments on commit 3320e85

Please sign in to comment.