Skip to content

Commit

Permalink
fix: segfault when creating tuple for slicing (#37)
Browse files Browse the repository at this point in the history
* fix: segfault when creating tuple for slicing

* windows ci

* x
  • Loading branch information
DjDeveloperr authored Jul 3, 2023
1 parent c3ae19b commit 9a66b87
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:
with:
deno-version: v1.x

- name: Setup Python 3.10 (Windows)
- name: Setup Python (Windows)
uses: actions/setup-python@v2
if: ${{ matrix.os == 'windows-latest' }}
with:
python-version: '3.10'
python-version: '3.11'

- name: Install NumPy
run: python3 -m pip install numpy
Expand Down
22 changes: 2 additions & 20 deletions src/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,26 +957,8 @@ function isSlice(value: unknown): boolean {
*/
function toSlice(sliceList: string): PyObject {
if (sliceList.includes(",")) {
const pySlicesHandle = sliceList.split(",")
.map(toSlice)
.map((pyObject) => pyObject.handle);

const pyTuple_Pack = new Deno.UnsafeFnPointer(
// TODO: this isn't really a `bigint`, but Deno's type definitions
// haven't been updated to support `number` yet
py.PyTuple_Pack!,
{
parameters: ["i32", ...pySlicesHandle.map(() => "pointer" as const)],
result: "pointer",
} as const,
);

// SAFETY: idk how to make TS understand this sort of function
const pyTupleHandle = (pyTuple_Pack as any).call(
pySlicesHandle.length,
...pySlicesHandle,
);
return new PyObject(pyTupleHandle);
const pySlicesHandle = sliceList.split(",").map(toSlice);
return python.tuple(pySlicesHandle)[ProxiedPyObject];
} else if (/^\s*-?\d+\s*$/.test(sliceList)) {
return PyObject.from(parseInt(sliceList));
} else if (/^\s*\.\.\.\s*$/.test(sliceList)) {
Expand Down

0 comments on commit 9a66b87

Please sign in to comment.