This is an automated email from the ASF dual-hosted git repository.

leginee pushed a commit to branch bazel-migration
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit aefca8a1a7d08158cf333155540258b6068e611b
Author: Peter Kovacs <[email protected]>
AuthorDate: Mon Jul 27 07:07:22 2026 +0200

    build(python): link _socket into python27.dll
    
    Upstream CPython builds its extension modules as separate .pyd DLLs
    (PCbuild/_socket.vcproj et al).  This port has no .pyd extension-module
    targets at all -- python27.dll contains only what PC/config.c lists in
    _PyImport_Inittab -- so _socket did not exist.
    
    uno.py does "import socket" at module scope ("since on Windows sal3.dll no
    longer calls WSAStartup"), so without it every "import uno" raised
    ImportError.  That killed "import pythonloader", so pyuno_loader.cxx's
    CreateInstance() threw before activate() was ever reached and the Python
    UNO loader never started -- visible as an empty tree and greyed buttons in
    Tools > Macros > Organize Macros > Python, with the exception swallowed by
    ProviderCache.
    
    Adds Modules/socketmodule.c to the built-in set and the matching
    _PyImport_Inittab entry; ws2_32.lib was already in linkopts.  Expect
    "warning C4005: 'INVALID_SOCKET' : macro redefinition" -- socketmodule.c
    defines it before including the SDK's winsock2.h, same value.
    
    Every other extension module (select, unicodedata, _ssl, _ctypes, pyexpat,
    bz2, ...) is still absent and will fail the same way; the readme documents
    how to add them.
    
    This is build-system only: the dmake build gets _socket from PCbuild and
    needs no equivalent change.
    
    Co-Authored-By: Claude Opus 5 <[email protected]>
---
 .../modules/python/2.7.18/overlay/BUILD.bazel      |  7 ++++++
 .../modules/python/2.7.18/overlay/PC/config.c      |  7 ++++++
 ext_libraries/modules/python/2.7.18/source.json    |  4 ++--
 ext_libraries/modules/python/readme.md             | 26 ++++++++++++++++++++++
 4 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/ext_libraries/modules/python/2.7.18/overlay/BUILD.bazel 
b/ext_libraries/modules/python/2.7.18/overlay/BUILD.bazel
index 7b66bc1e88..ac30897be2 100644
--- a/ext_libraries/modules/python/2.7.18/overlay/BUILD.bazel
+++ b/ext_libraries/modules/python/2.7.18/overlay/BUILD.bazel
@@ -117,6 +117,11 @@ _PC_SRCS = [
 
 # ── Built-in modules (those listed in PC/config.c _inittab) ───────────
 # Only the modules compiled directly into python27.dll, not extension DLLs.
+# EXCEPTION: socketmodule.c.  Upstream builds it as a separate _socket.pyd
+# (PCbuild/_socket.vcproj) and this port has no .pyd extension targets at all,
+# so it is linked in as a built-in.  uno.py imports socket at module scope —
+# without _socket, "import uno" raises ImportError and pyuno's loader never
+# starts.  ws2_32.lib is already in linkopts below.
 _MODULE_SRCS = [
     # Entry points
     "Modules/main.c",
@@ -156,6 +161,8 @@ _MODULE_SRCS = [
     "Modules/timemodule.c",
     # Regex
     "Modules/_sre.c",
+    # Sockets — '_socket' (see note above); needed by uno.py
+    "Modules/socketmodule.c",
     # IO (subdirectory — pick up all .c files)
 ] + glob(["Modules/_io/*.c"]) + [
     # Remaining built-ins
diff --git a/ext_libraries/modules/python/2.7.18/overlay/PC/config.c 
b/ext_libraries/modules/python/2.7.18/overlay/PC/config.c
index c7acb652e7..928070f7e9 100644
--- a/ext_libraries/modules/python/2.7.18/overlay/PC/config.c
+++ b/ext_libraries/modules/python/2.7.18/overlay/PC/config.c
@@ -57,6 +57,12 @@ extern void init_json(void);
 extern void init_subprocess(void);
 extern void init_ast(void);
 extern void init_io(void);
+/* Upstream CPython ships _socket as a separate _socket.pyd 
(PCbuild/_socket.vcproj).
+   We have no .pyd extension-module targets, so it is linked into python27.dll 
and
+   listed here instead.  Required: uno.py does "import socket" at module 
scope, so
+   without it "import uno" -> "import pythonloader" fails and the whole Python 
UNO
+   loader is dead (ImportError: No module named _socket). */
+extern void init_socket(void);
 extern void _PyWarnings_Init(void);
 extern void initxxsubtype(void);
 extern void initzipimport(void);
@@ -81,6 +87,7 @@ struct _inittab _PyImport_Inittab[] = {
     {"_sha",           init_sha},
     {"_sha256",        init_sha256},
     {"_sha512",        init_sha512},
+    {"_socket",        init_socket},
     {"strop",          initstrop},
     {"time",           inittime},
 #ifdef WITH_THREAD
diff --git a/ext_libraries/modules/python/2.7.18/source.json 
b/ext_libraries/modules/python/2.7.18/source.json
index a64ea60d6c..2745cd141a 100644
--- a/ext_libraries/modules/python/2.7.18/source.json
+++ b/ext_libraries/modules/python/2.7.18/source.json
@@ -4,8 +4,8 @@
     "strip_prefix": "Python-2.7.18",
     "overlay": {
         "MODULE.bazel": "sha256-xlj90p6/lw2wir7wVOfypN7VivhHqwkIfA3JXUVWGlQ=",
-        "BUILD.bazel":  "sha256-V0pEN3cTRzG7IUM5ZEO8xVdjoJHBEyDNwBHzUY3Tz0w=",
-        "PC/config.c":  "sha256-Y+QGQKk2nk9HEbqn86YTbDscyrgwKuBQiekxJzAvrVI=",
+        "BUILD.bazel":  "sha256-TuUk4olhyqKhfLW8rcTVAprUfd6xP0h44wMd8cIfEPc=",
+        "PC/config.c":  "sha256-D68dVYB5dzuXQAIM5FCwxx4wSMLDJ/5LXCYWqbInHB8=",
         "PC/pyconfig.h": "sha256-yE8wW//MgHp8iKC5Y8Kpp3pAP43qrMzqd2WaRjtTXNQ="
     },
     "patches": {},
diff --git a/ext_libraries/modules/python/readme.md 
b/ext_libraries/modules/python/readme.md
index cb55ebc284..a2597b0807 100644
--- a/ext_libraries/modules/python/readme.md
+++ b/ext_libraries/modules/python/readme.md
@@ -28,6 +28,32 @@ ext_libraries/modules/python/
 
 ## Key build decisions
 
+### `_socket` is linked in, not built as `_socket.pyd`
+Upstream CPython builds a set of *extension modules* as separate `.pyd` DLLs
+(`PCbuild/_socket.vcproj`, `select`, `unicodedata`, `_ssl`, `_ctypes`, …).
+This port has **no `.pyd` extension-module targets at all** — `python27.dll`
+contains only what `PC/config.c` lists in `_PyImport_Inittab`.
+
+`socketmodule.c` is the one exception, compiled into `python27.dll` and listed
+in the overlay's `PC/config.c` as `{"_socket", init_socket}`.  It is not
+optional: 
[main/pyuno/source/module/uno.py](../../../main/pyuno/source/module/uno.py)
+does `import socket` at module scope ("since on Windows sal3.dll no longer 
calls
+WSAStartup"), so without `_socket` every `import uno` raises
+`ImportError: No module named _socket`.  That kills `import pythonloader`, so
+`pyuno_loader.cxx`'s `CreateInstance()` throws before `activate()` is ever
+reached and the whole Python UNO loader is dead — visible as an empty tree and
+greyed buttons in Tools ▸ Macros ▸ Organize Macros ▸ Python, with the exception
+swallowed by `ProviderCache`.  `ws2_32.lib` was already in `linkopts`.
+
+Expect `warning C4005: 'INVALID_SOCKET' : macro redefinition` — 
`socketmodule.c`
+defines it before including the SDK's `winsock2.h`.  Harmless, same value.
+
+**Still missing**: every other extension module.  A Python macro that imports
+`select`, `unicodedata`, `_ssl`, `_ctypes`, `pyexpat`, `bz2` … will fail the 
same
+way.  Add them the same way (source into `_MODULE_SRCS` + entry in 
`PC/config.c`)
+as they are needed, or build real `.pyd` targets — 
`//build/rules:copy_file.bzl`
+exists for the `.dll` → `.pyd` rename, see `main/pyuno/readme.md`.
+
 ### No DEF file
 Python 2.7.18's tarball does not include `PC/python27.def`. Exports are
 produced via `__declspec(dllexport)` through the `Py_BUILD_CORE` →

Reply via email to