Skip to content

Commit

Permalink
backport patch to fix PyPy
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed May 18, 2023
1 parent 92b4b1a commit ff7c09e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 6 deletions.
2 changes: 2 additions & 0 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ source:
- patches/0004-use-C-17-everywhere.patch
- patches/0005-set-PROTOBUF_USE_DLLS-clean-up-other-symbols-on-win.patch
- patches/0006-explicitly-link-to-abseil_dll-on-windows.patch
# backport 69a4876d69eeee37aab121f6f4908bec7b35b271 to fix PyPy support
- patches/0007-restore-pypy-support-broken-when-adding-3.11-support.patch

build:
number: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From cbe7b53095c6acf29abb65aee4b825f3235babf9 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <[email protected]>
Date: Sun, 4 Sep 2022 18:14:41 +0200
Subject: [PATCH 1/6] do not link msvc runtime statically
Subject: [PATCH 1/7] do not link msvc runtime statically

---
python/setup.py | 4 ----
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From db8c830280ee0cf0a853d24a2e634728e224813b Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <[email protected]>
Date: Sun, 4 Sep 2022 18:42:34 +0200
Subject: [PATCH 2/6] fix paths for include & lib directories
Subject: [PATCH 2/7] fix paths for include & lib directories

---
python/setup.py | 14 ++++++++++++--
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From e893d9d92207989b1cc917564518545dd5615143 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <[email protected]>
Date: Sun, 4 Sep 2022 19:42:16 +0200
Subject: [PATCH 3/6] adapt to name of protobuf lib on windows
Subject: [PATCH 3/7] adapt to name of protobuf lib on windows

---
python/setup.py | 3 ++-
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0004-use-C-17-everywhere.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From f5c19b6bcb953106ffa3852f930f9906d9577490 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <[email protected]>
Date: Thu, 18 May 2023 17:14:37 +1100
Subject: [PATCH 4/6] use C++17 everywhere
Subject: [PATCH 4/7] use C++17 everywhere

---
python/setup.py | 4 +++-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 1d7c0d7885178f0cfd9caab881559cfbdd2013e0 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <[email protected]>
Date: Thu, 18 May 2023 18:49:27 +1100
Subject: [PATCH 5/6] set PROTOBUF_USE_DLLS; clean up other symbols on win
Subject: [PATCH 5/7] set PROTOBUF_USE_DLLS; clean up other symbols on win

---
python/setup.py | 7 ++-----
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 6261ee512478a6ba826243b368dd7d35527f5b14 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <[email protected]>
Date: Thu, 18 May 2023 19:20:35 +1100
Subject: [PATCH 6/6] explicitly link to abseil_dll on windows
Subject: [PATCH 6/7] explicitly link to abseil_dll on windows

---
python/setup.py | 2 +-
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
From d448c644c0bd8986819fb8e7b86bd5a223e0aae2 Mon Sep 17 00:00:00 2001
From: Eric Salo <[email protected]>
Date: Thu, 13 Apr 2023 10:38:15 -0700
Subject: [PATCH 7/7] restore pypy support broken when adding 3.11 support
(from GH)

This is a copy of https://github.com/protocolbuffers/protobuf/pull/12431
but with the ifdef logic reversed. The original PR could not kick off our
CI tests because it wasn't branched directly from repo main.

Thanks to Tom Gillespie for the original PR.

PiperOrigin-RevId: 524041105
---
python/google/protobuf/pyext/descriptor.cc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc
index de9a24807..d09c218b6 100644
--- a/python/google/protobuf/pyext/descriptor.cc
+++ b/python/google/protobuf/pyext/descriptor.cc
@@ -125,7 +125,9 @@ PyObject* PyString_FromCppString(const std::string& str) {
// TODO(amauryfa): Change the proto2 compiler to remove the assignments, and
// remove this hack.
bool _CalledFromGeneratedFile(int stacklevel) {
-#ifndef PYPY_VERSION
+#ifdef PYPY_VERSION
+ return true;
+#else
// This check is not critical and is somewhat difficult to implement correctly
// in PyPy.
PyFrameObject* frame = PyEval_GetFrame();
@@ -181,7 +183,6 @@ bool _CalledFromGeneratedFile(int stacklevel) {
// Not at global module scope
goto exit;
}
-#endif
result = true;
exit:
Py_XDECREF(frame_globals);
@@ -189,6 +190,7 @@ exit:
Py_XDECREF(frame_code);
Py_XDECREF(frame);
return result;
+#endif
}

// If the calling code is not a _pb2.py file, raise AttributeError.

0 comments on commit ff7c09e

Please sign in to comment.