FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[pull] master from pythonnet:master by pull[bot] · Pull Request #69 · ehtick/pythonnet · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (2) .md  (1) .rst  (1) .txt  (1) .yml  (1) All 5 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:

env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
# Apply to every Mono host, including pytest and the .NET Python test runner.
MONO_THREADS_SUSPEND: preemptive # https://github.com/mono/mono/issues/21466
steps:
- name: Checkout code
uses: actions/checkout@v7
Expand Down Expand Up @@ -84,8 +86,6 @@ jobs:
- name: Embedding tests (Mono/.NET Framework)
if: always()
run: dotnet test --runtime any-${{ matrix.os.platform }} --framework net472 --logger "console;verbosity=detailed" src/embed_tests/
env:
MONO_THREADS_SUSPEND: preemptive # https://github.com/mono/mono/issues/21466

- name: Embedding tests (.NET Core)
if: always()
Expand All @@ -97,7 +97,7 @@ jobs:

- name: Python Tests (Mono)
if: always()
run: pytest --runtime mono
run: uv run pytest --runtime mono -v -o faulthandler_timeout=60

- name: Python Tests (.NET Framework)
if: ${{ matrix.os.category == 'windows' }}
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].

### Added

### Changed

### Fixed


## 3.2.0 - 2026-09-29

### Added

- Support for Python 3.15 (#2729)
- Support for free-threaded Python 3.14 (`Py_GIL_DISABLED`) (#2721)
- Threading documentation covering GIL ownership, managed threads, and
Expand All @@ -28,6 +37,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
- Fix method binding initialization when methods are first accessed (#2721)
- Fix wheel and NuGet preview package builds
- Python exception raised on conversion failure (#2741)
- Introduce additional pre-checks in `PyBuffer_GetPointer` to prevent memory
corruption (#2745)

## 3.1.0 - 2026-05-23

Expand Down
14 changes: 14 additions & 0 deletions doc/source/threading.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ Forgetting this is the most common pythonnet threading bug. Symptoms range
from immediate segfaults to subtle refcount corruption that crashes much
later.

Mono thread suspension
----------------------

On Linux and macOS, Mono's cooperative/hybrid thread suspension can hang
when Python and managed threads interact. If affected, set
``MONO_THREADS_SUSPEND=preemptive`` before starting the process, as described
in `mono/mono#21466 <https://github.com/mono/mono/issues/21466>`_.
CI uses this workaround for both embedding and Python-hosted tests.

To run the Mono Python tests with per-test output and a Python thread
stack dump if a test takes longer than 60 seconds::

MONO_THREADS_SUSPEND=preemptive uv run pytest --runtime mono -v -o faulthandler_timeout=60

Reference counting and finalizers
---------------------------------

Expand Down
47 changes: 43 additions & 4 deletions src/embed_tests/TestPyBuffer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;

using NUnit.Framework;

using Python.Runtime;
using Python.Runtime.Codecs;

namespace Python.EmbeddingTest {
namespace Python.EmbeddingTest
{
class TestPyBuffer
{
[OneTimeSetUp]
Expand Down Expand Up @@ -58,13 +61,49 @@ public void TestBufferRead()
}

string result = new UTF8Encoding().GetString(managedArray);
Assert.That(result == " " + bufferTestString.Substring(1), Is.True);
Assert.That(result, Is.EqualTo($" {bufferTestString.Substring(1)}"));
}

[Test]
public void GetPointer()
{
// create 3D NumPy array
int[] shape = [10, 10, 10];
using PyObject ndArray = np.zeros(shape);

using PyBuffer buf = ndArray.GetBuffer(PyBUF.STRIDES);

var ptr = buf.GetPointer([0, 0, 0]);

Assert.That(ptr, Is.Not.EqualTo(IntPtr.Zero));

var ptrEnd = buf.GetPointer([9, 9, 9]);
Assert.That(ptrEnd, Is.Not.EqualTo(IntPtr.Zero));

Assert.Throws<ArgumentNullException>(() => buf.GetPointer(null!));

Assert.Throws<ArgumentOutOfRangeException>(() => buf.GetPointer([0, 0]));
Assert.Throws<ArgumentOutOfRangeException>(() => buf.GetPointer([0, 0, 0, 0]));

Assert.Throws<ArgumentOutOfRangeException>(() => buf.GetPointer([-1, 0, 0]));
Assert.Throws<ArgumentOutOfRangeException>(() => buf.GetPointer([0, -1, 0]));
Assert.Throws<ArgumentOutOfRangeException>(() => buf.GetPointer([0, 0, -1]));

Assert.Throws<ArgumentOutOfRangeException>(() => buf.GetPointer([10, 0, 0]));
Assert.Throws<ArgumentOutOfRangeException>(() => buf.GetPointer([0, 10, 0]));
Assert.Throws<ArgumentOutOfRangeException>(() => buf.GetPointer([0, 0, 10]));

using PyBuffer buf2 = ndArray.GetBuffer(PyBUF.ND);

Assert.Throws<InvalidOperationException>(
() => buf2.GetPointer([0, 0, 0])
);
}

[Test]
public void ArrayHasBuffer()
{
var array = new[,] {{1, 2}, {3,4}};
var array = new[,] { { 1, 2 }, { 3, 4 } };
var memoryView = PythonEngine.Eval("memoryview");
var mem = memoryView.Invoke(array.ToPython());
Assert.That(mem[(0, 0).ToPython()].As<int>(), Is.EqualTo(1));
Expand Down Expand Up @@ -113,7 +152,7 @@ public void Finalization()
[Test]
public void MultidimensionalNumPyArray()
{
var ndarray = np.arange(24).reshape(1,2,3,4).T;
var ndarray = np.arange(24).reshape(1, 2, 3, 4).T;
PyObject ndim = ndarray.ndim;
PyObject shape = ndarray.shape;
PyObject strides = ndarray.strides;
Expand Down
29 changes: 28 additions & 1 deletion src/runtime/PythonTypes/PyBuffer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,37 @@ public bool IsContiguous(BufferOrderStyle order)
/// </summary>
public IntPtr GetPointer(long[] indices)
{
if (indices is null) throw new ArgumentNullException(nameof(indices));
if (indices is null)
throw new ArgumentNullException(nameof(indices));

if (Strides is null)
throw new InvalidOperationException($"{nameof(GetPointer)} requires {nameof(Strides)} to be filled");

if (indices.Length != Dimensions)
throw new ArgumentOutOfRangeException($"{nameof(indices)} must be exactly {Dimensions} long");

if (Dimensions == 0 && Shape is null)
throw new InvalidOperationException($"{nameof(GetPointer)} requires {nameof(Shape)} to be filled for dimensional buffers");

ThrowIfDisposed();

if (Runtime.PyVersion < new Version(3, 7))
throw new NotSupportedException("GetPointer requires at least Python 3.7");

var indicesArr = new nint[Dimensions];

for (var i = 0; i < Dimensions; i++)
{
indicesArr[i] = checked((nint)indices[i]);

if (indicesArr[i] < 0 || indicesArr[i] >= Shape![i])
{
throw new ArgumentOutOfRangeException(
$"Index {i} has a value of {indicesArr[i]} not in [0, {Shape![i]})"
);
}
}

return Runtime.PyBuffer_GetPointer(ref _view, indices.Select(x => checked((nint)x)).ToArray());
}

Expand Down
2 changes: 1 addition & 1 deletion version.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.0-rc2
3.3.0-dev
Loading

Back | FazBrowse Home | New Git URL