Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo attr.h, detail/class.h changes made under PR #3923 #4142

Closed
wants to merge 1 commit into from

Conversation

rwgk
Copy link
Collaborator

@rwgk rwgk commented Aug 17, 2022

Description

See python/cpython#92678 for background.

Suggested changelog entry:

Copy link
Collaborator

@Skylion007 Skylion007 left a comment

Choose a reason for hiding this comment

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

Looks good to me. These issues the original behavior/legacy API was restored in the 3.11 release candidate.

@rwgk
Copy link
Collaborator Author

rwgk commented Aug 18, 2022

Thanks @Skylion007! Leaving this in draft mode for the minute, waiting for feedback here: python/cpython#96046 (comment)

@Skylion007
Copy link
Collaborator

I was worried GC was not implemented properly with our use of the new API (see #4092), but it sounds like that the upstream CPython has been updated so it is fine now?

@rwgk
Copy link
Collaborator Author

rwgk commented Aug 19, 2022

I was worried GC was not implemented properly with our use of the new API (see #4092), but it sounds like that the upstream CPython has been updated so it is fine now?

Who could give us authoritative advice what to do here?

A: Merge this PR (because the old way of doing things evidently works again with Python 3.11, thanks to @markshannon), wait for the Python 3.11.0 final release, but then soon after start testing against 3.12 (maybe brining back what this PR removes, as a starting point)?

B: Drop this PR because all required changes were made in Python 3.11 in the meantime?

C: Change this PR to make more/different adjustments for 3.11?

@Fidget-Spinner (b/o #4092)

@vstinner @tiran (b/o python/cpython#96046)

@markshannon @pablogsal (b/o python/cpython#92678)

@vstinner
Copy link
Contributor

I suggest you waiting until python/cpython#96047 is merged, and then test pybind11 again on a Python containing this change.

@rwgk
Copy link
Collaborator Author

rwgk commented Aug 22, 2022

I suggest you waiting until python/cpython#96047 is merged, and then test pybind11 again on a Python containing this change.

Looks like it's working!
All details below. The command at the very bottom runs to completion (no more segfault).
This is using the pybind11 v2.10.0 release.

@vstinner should I just close this PR?


I tested with this https://github.com/python/cpython commit:

commit 4f7f83b5bdd61f01a5ad49fb4df61cab3607ab99 (HEAD -> 3.11, origin/3.11)
git archive --format=tar.gz -o $HOME/cpython-3.11-4f7f83b5bdd61f01a5ad49fb4df61cab3607ab99.tar.gz --prefix=cpython-3.11-4f7f83b5bdd61f01a5ad49fb4df61cab3607ab99/ 3.11

Dockerfile

FROM fedora:36
RUN dnf -y install gcc
RUN dnf -y install g++
RUN dnf -y install gdb
RUN dnf -y install libffi-devel
RUN dnf -y install openssl-devel
RUN dnf -y install sqlite-devel
RUN dnf -y install git
RUN dnf -y install vim
RUN dnf -y install qpdf-devel

In the running docker container:

tar zxvf /ghome/cpython-3.11-4f7f83b5bdd61f01a5ad49fb4df61cab3607ab99.tar.gz
cd cpython-3.11-4f7f83b5bdd61f01a5ad49fb4df61cab3607ab99/
./configure --prefix=/Python-3.11-4f7f83b5bdd61f01a5ad49fb4df61cab3607ab99
make install -j 16
cd ..
/Python-3.11-4f7f83b5bdd61f01a5ad49fb4df61cab3607ab99/bin/python3.11 -m venv env
source /env/bin/activate
python -m pip install --upgrade pip
python -m pip install pytest
python -m pip install IPython
python -m pip install sphinx sphinx_issues sphinx_design sphinx_rtd_theme
git clone https://github.com/pikepdf/pikepdf
cd pikepdf/
python -m pip install .
cd docs/
/env/bin/sphinx-build . ../html

rwgk pushed a commit to rwgk/pybind11_scons that referenced this pull request Aug 22, 2022
@rwgk
Copy link
Collaborator Author

rwgk commented Aug 23, 2022

FWIW, I ran a super-simple leak check: while True loop and top command. See diff below. It's all a bit make-shift, but I do NOT have any evidence that there is a leak (using cpython 3.11 @ commit 4f7f83b5bdd61f01a5ad49fb4df61cab3607ab99, pybind11 master).

This adds to my belief that we can keep using Py_TPFLAGS_MANAGED_DICT with Python 3.11, as released with pybind11 v2.10.0, which seems nice for continuity.

diff --git a/tests/test_multiple_inheritance.py b/tests/test_multiple_inheritance.py
index 3a1d88d7..4ad67569 100644
--- a/tests/test_multiple_inheritance.py
+++ b/tests/test_multiple_inheritance.py
@@ -261,13 +261,24 @@ def test_mi_static_properties():
         assert d.static_value == 0


-# Requires PyPy 6+
-def test_mi_dynamic_attributes():
+@pytest.mark.parametrize("vanilla_type", (m.VanillaDictMix1, m.VanillaDictMix2))
+def test_mi_dynamic_attr_simple(vanilla_type):
     """Mixing bases with and without dynamic attribute support"""
-
-    for d in (m.VanillaDictMix1(), m.VanillaDictMix2()):
+    while True:
+        d = vanilla_type()
         d.dynamic = 1
         assert d.dynamic == 1
+        break
+
+
+@pytest.mark.parametrize("vanilla_type", (m.VanillaDictMix1, m.VanillaDictMix2))
+def test_mi_dynamic_attr_ref_cycle(vanilla_type):
+    """Mixing bases with and without dynamic attribute support"""
+    while True:
+        d = vanilla_type()
+        d.ref_cycle = d
+        assert d.ref_cycle is d
+        #break


 def test_mi_unaligned_base():

@henryiii
Copy link
Collaborator

What's the status of this?

@rwgk
Copy link
Collaborator Author

rwgk commented Oct 20, 2022

What's the status of this?

I believe we don't need this, I just kept it around because it's not clear to me.

From memory, it was initially needed because of a change A in Python, but then it triggered a bug B in Python, then there was a rollback of change A so it is no longer needed, but also the triggered bug B is fixed, so we can keep it anyway.

That's all I know. It may be an oversimplification or even misrepresentation. I don't have time to dig into Python 3.11 and 3.12 to truly understand the situation and how it evolved.

Last activity here was 2 months ago: Closing, I figure we're fine.

@rwgk rwgk closed this Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python dev Working on development versions of Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants