Skip to content

Commit 0eacfd2

Browse files
authored
Fix Python module portability issues, especially on linux 32 (#27085)
Fixes a number of portability issues nightly testing revealed, especially on linux 32. However, some issues are also caused by different versions of Python. - [x] `start_test test/library/packages/Python/correctness/arrays/` on MacOS with Python 3.13 - [x] `start_test test/library/packages/Python/correctness/arrays/` on linux32 with Python 3.11 [Reviewed by @lydia-duncan]
2 parents a6ed387 + 29c4226 commit 0eacfd2

File tree

8 files changed

+17
-14
lines changed

8 files changed

+17
-14
lines changed

modules/packages/Python.chpl

+2-1
Original file line numberDiff line numberDiff line change
@@ -3269,7 +3269,8 @@ module Python {
32693269
throw new ChapelException("Index out of bounds");
32703270
}
32713271

3272-
var ptr_ = (this.view.buf:c_intptr + offset): c_ptr(void): c_ptr(eltType);
3272+
var ptr_ =
3273+
(this.view.buf:c_intptr + offset:c_intptr): c_ptr(void): c_ptr(eltType);
32733274
return ptr_.deref();
32743275
}
32753276

test/library/packages/Python/correctness/arrays/memoryView.chpl

+1-5
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,9 @@ proc main() {
7171
var lst = memView.call(owned PyList, 'tolist');
7272
writeln("tolist: ", lst);
7373

74-
var pyArray = interp.fromPython(
75-
owned PyArray(real(32), 3),
76-
arrRef.getPyObject()
77-
);
74+
var pyArray = arrRef.value(owned PyArray(real(32), 3));
7875
var result = pyArray.these();
7976
writeln("Round tripped array:\n", result);
80-
8177
}
8278

8379
}

test/library/packages/Python/correctness/arrays/ndArrayMemoryView.chpl

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ writeln(memview.get('strides'));
1818
writeln(memview.get('ndim'));
1919
try {
2020
var pyArr = new PyArray(real, 2, interp, buf.getPyObject(), isOwned=false);
21-
} catch e: BufferError {
22-
writeln(e);
21+
} catch e {
22+
writeln(e.message());
2323
writeln("This is expected because the buffer is not writable");
24-
} catch {
25-
writeln("Unexpected error");
2624
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(3, 4)
22
(32, 8)
33
2
4-
BufferError: Object is not writable.
4+
Object is not writable.
55
This is expected because the buffer is not writable

test/library/packages/Python/correctness/arrays/usePythonArray.chpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use Python;
1+
use Python, CTypes;
22

33
proc main() {
44
var interp = new Interpreter();
55
var mod = interp.importModule("usePythonArray");
66
var doit = mod.get('doit');
77

88

9-
var pyRes = doit(owned PyArray(int, 1), 10, 11, 12, 13);
9+
var pyRes = doit(owned PyArray(c_long, 1), 10, 11, 12, 13);
1010
var res = pyRes.array();
1111
write("arr: ", res);
1212
write(" dom: ", res.domain);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ "$CHPL_TARGET_PLATFORM" == "linux32" ]]; then
4+
echo " # usePythonArray.linux32.good"
5+
else
6+
echo " # usePythonArray.good"
7+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
arr: 10 11 12 13 dom: {0..3} eltType: int(32)

util/config/embed-python.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ PYTHON_LDVERSION=$($chpl_python -c "import sysconfig; print(sysconfig.get_config
1717
DISABLE_WARNINGS=""
1818
# some older python's don't use `#ifndef` when they should
1919
# so we disable redefinition warnings for clean testing
20-
DISABLE_WARNINGS+="--ccflags -Wno-macro-redefined"
20+
DISABLE_WARNINGS="$DISABLE_WARNINGS --ccflags -Wno-macro-redefined"
2121

2222
echo "--ccflags -isystem$PYTHON_INCLUDE_DIR -L$PYTHON_LIB_DIR --ldflags -Wl,-rpath,$PYTHON_LIB_DIR -lpython$PYTHON_LDVERSION $DISABLE_WARNINGS"

0 commit comments

Comments
 (0)