Skip to content

Conversation

@ivaylo-matov
Copy link

What does this implement/fix? Explain your changes.

Merged from pythonnet master to support pythonnet 3.13

Does this close any currently open issues?

Task related to DYN-8247

Any other comments?

  • merged from pythonnet master
  • docs.yml removed
  • bumped up version to 3.2.0-dev

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Ensure you have signed the .NET Foundation CLA
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

@twastvedt

filmor and others added 30 commits May 5, 2024 20:42
* Use non-BOM encodings

The documentation of the used `PyUnicode_DecodeUTF16` states that not passing `*byteorder` or passing a 0 results in the first two bytes, if
they are the BOM (U+FEFF, zero-width no-break space), to be interpreted and skipped, which is incorrect when we convert a known "non BOM" string, which all strings from C# are.
* Expose an API for users to specify their own formatter

Adds post-serialization and pre-deserialization hooks for additional
customization.

* Add API for capsuling data when serializing

* Add NoopFormatter and fall back to it if BinaryFormatter is not available

---------

Co-authored-by: Benedikt Reinartz <filmor@gmail.com>
When nulling the GC handles on shutdown the reference count of all objects pointed to by the IntPtr in the `CLRObject.reflectedObjects` are zero.
This caused an exception in some scenarios because `Runtime.PyObject_TYPE(reflectedClrObject)` is called while the reference counter is at zero.

After `TypeManager.RemoveTypes();` is called in the `Runtime.Shutdown()` method, reference count decrements to zero do not invoke `ClassBase.tp_clear` for managed objects anymore which normally is responsible for removing references from `CLRObject.reflectedObjects`. Collecting objects referenced in `CLRObject.reflectedObjects` only after leads to an unstable state in which the reference count for these object addresses is zero while still maintaining them to be used for further pseudo-cleanup. In that time, the memory could have been reclaimed already which leads to the exception.
Otherwise, collecting all at this earlier point results in corrupt memory for derived types.
* Use non-BOM encodings

* Copy potential BOM to the output of PyString_FromString

The documentation of the used `PyUnicode_DecodeUTF16` states that not
passing `*byteorder` or passing a 0 results in the first two bytes, if
they are the BOM (U+FEFF, zero-width no-break space), to be interpreted
and skipped, which is incorrect when we convert a known "non BOM"
string, which all strings from C# are.

* Default to UTF8 for StrPtr
…or some other internal errors (pythonnet#2409)

* not all events have Add method

fixes pythonnet#2405

* give users some idea of why we might be unable to reflect .NET types to Python for them

* mentioned event Add method crash fix in changelog
Otherwise if you have a Python object that needs to temporarily create a .NET object in its destructor (for instance write log summary to a file), its destructor will fail if it happens to be freed on the second iteration of loop breaking.
…on-gc

Fix access violation exception on shutdown
Was only used in the console and might not be available in some
embedding scenarios.
Verified them locally, but there is an issue with the Github workflow
image that can hopefully be resolved later by using a full venv
instead of relying on the system environment.
@ivaylo-matov
Copy link
Author

ivaylo-matov commented Sep 23, 2025

Locally I can build only if I unload PerformanceTests and then build it separately. Same for dynamo_py branch.
All tests pass when I point to python313.dll.

Copy link

@twastvedt twastvedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming this is mostly just a clean merge, looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants