diff --git a/.github/workflows/python_tests.yml b/.github/workflows/python_tests.yml index 369fea12a9..f6879738eb 100644 --- a/.github/workflows/python_tests.yml +++ b/.github/workflows/python_tests.yml @@ -55,11 +55,10 @@ jobs: - { os: macos-12, python-version: "3.10", architecture: x64 } # Windows uses the full API up until Python 3.10, so each of these # jobs tests a distinct binary wheel. - # TODO(b/231485326): fix the win32 wheels to load properly. - # - { os: windows-2019, python-version: "3.7", architecture: x86 } - # - { os: windows-2019, python-version: "3.8", architecture: x86 } - # - { os: windows-2019, python-version: "3.9", architecture: x86 } - # - { os: windows-2019, python-version: "3.10", architecture: x86 } + - { os: windows-2019, python-version: "3.7", architecture: x86 } + - { os: windows-2019, python-version: "3.8", architecture: x86 } + - { os: windows-2019, python-version: "3.9", architecture: x86 } + - { os: windows-2019, python-version: "3.10", architecture: x86 } - { os: windows-2019, python-version: "3.7", architecture: x64 } - { os: windows-2019, python-version: "3.8", architecture: x64 } - { os: windows-2019, python-version: "3.9", architecture: x64 } @@ -92,7 +91,7 @@ jobs: - name: Install Protobuf Wheels run: pip install -vvv --no-index --find-links wheels protobuf protobuftests - name: Test that module is importable - run: python -c 'from google._upb import _message; assert "google._upb._message.MessageMeta" in str(_message.MessageMeta)' + run: python -v -c 'from google._upb import _message; assert "google._upb._message.MessageMeta" in str(_message.MessageMeta)' if: ${{ !matrix.pure_python }} - name: Run the unit tests run: | diff --git a/python/dist/BUILD.bazel b/python/dist/BUILD.bazel index 6aa62e1dd5..2e6f3ed5ac 100644 --- a/python/dist/BUILD.bazel +++ b/python/dist/BUILD.bazel @@ -165,7 +165,7 @@ py_dist( binary_wheel = ":binary_wheel", full_api_cpus = [ # TODO(b/231485326): fix win32 build - # "win32", + "win32", "win64", ], # Windows needs version-specific wheels until 3.10. @@ -182,7 +182,7 @@ py_dist( # details). limited_api_wheels = { # TODO(b/231485326): fix win32 build - # "win32": "310", + "win32": "310", "win64": "310", "linux-x86_64": "37", "linux-aarch_64": "37", diff --git a/python/protobuf.c b/python/protobuf.c index 53bfe3a8a7..d3b6677728 100644 --- a/python/protobuf.c +++ b/python/protobuf.c @@ -131,10 +131,14 @@ PyUpb_WeakMap* PyUpb_WeakMap_New(void) { void PyUpb_WeakMap_Free(PyUpb_WeakMap* map) { upb_Arena_Free(map->arena); } +// To give better entropy in the table key, we shift away low bits that are +// always zero. +static const int PyUpb_PtrShift = (sizeof(void*) == 4) ? 2 : 3; + uintptr_t PyUpb_WeakMap_GetKey(const void* key) { uintptr_t n = (uintptr_t)key; - assert((n & 7) == 0); - return n >> 3; + assert((n & ((1 << PyUpb_PtrShift) - 1)) == 0); + return n >> PyUpb_PtrShift; } void PyUpb_WeakMap_Add(PyUpb_WeakMap* map, const void* key, PyObject* py_obj) { @@ -170,7 +174,7 @@ bool PyUpb_WeakMap_Next(PyUpb_WeakMap* map, const void** key, PyObject** obj, uintptr_t u_key; upb_value val; if (!upb_inttable_next2(&map->table, &u_key, &val, iter)) return false; - *key = (void*)(u_key << 3); + *key = (void*)(u_key << PyUpb_PtrShift); *obj = upb_value_getptr(val); return true; } diff --git a/python/py_extension.bzl b/python/py_extension.bzl index 8b175a8e7a..a363808d61 100644 --- a/python/py_extension.bzl +++ b/python/py_extension.bzl @@ -17,7 +17,11 @@ def py_extension(name, srcs, copts, deps = []): srcs = srcs, copts = copts + ["-fvisibility=hidden"], linkopts = selects.with_or({ - ("//python/dist:osx-x86_64_cpu", "//python/dist:osx-aarch64_cpu"): ["-undefined", "dynamic_lookup"], + ( + "//python/dist:osx-x86_64_cpu", + "//python/dist:osx-aarch64_cpu", + ): ["-undefined", "dynamic_lookup"], + "//python/dist:win32_cpu": ["-static-libgcc"], "//conditions:default": [], }), linkshared = True,