From 723ac3a72744dd8cfa38ccd660a57bf749127dee Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Dec 2025 22:58:21 +0000 Subject: [PATCH 1/5] Initial plan From 8ef95afaa0a6794c8595473e6455def9e3cb344e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Dec 2025 23:02:35 +0000 Subject: [PATCH 2/5] Fix remaining issues in STUBS.md: terminology, file paths, and formatting Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- STUBS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/STUBS.md b/STUBS.md index 5c006a5..ea0be58 100644 --- a/STUBS.md +++ b/STUBS.md @@ -14,7 +14,7 @@ All stubs are implemented in: `Python/frozen_stubs.c` **Stubs Created**: - `_PyImport_FrozenBootstrap` - Bootstrap frozen modules -- `_PyImport_FrozenStdlib` - Standard library frozen modules +- `_PyImport_FrozenStdlib` - Standard library frozen modules - `_PyImport_FrozenTest` - Test frozen modules - `PyImport_FrozenModules` - Main frozen modules array - `_PyImport_FrozenAliases` - Frozen module aliases @@ -78,7 +78,7 @@ All stubs are implemented in: `Python/frozen_stubs.c` **Stubs Created**: - `plock()` - Process memory locking (Solaris-specific) -**Implementation**: Returns -1 with errno set to `ENOSYS` (not implemented). Also removed `HAVE_PLOCK` from pyconfig.h. +**Implementation**: Returns -1 with errno set to `ENOSYS` (not implemented). Also commented out `HAVE_PLOCK` in `Include/pyconfig.h`. **Note**: `plock()` is a legacy Solaris function not available on modern Linux systems. @@ -86,7 +86,7 @@ All stubs are implemented in: `Python/frozen_stubs.c` ### pyconfig.h Modifications -The following configuration define was commented out: +The following configuration define was commented out in `Include/pyconfig.h`: ```c /* plock is not available on modern Linux systems */ From 9b25757234377a2639eab0ad7caa0462399ded17 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Dec 2025 23:33:21 +0000 Subject: [PATCH 3/5] Revert documentation-only changes to prepare for actual implementation Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- STUBS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/STUBS.md b/STUBS.md index ea0be58..5c006a5 100644 --- a/STUBS.md +++ b/STUBS.md @@ -14,7 +14,7 @@ All stubs are implemented in: `Python/frozen_stubs.c` **Stubs Created**: - `_PyImport_FrozenBootstrap` - Bootstrap frozen modules -- `_PyImport_FrozenStdlib` - Standard library frozen modules +- `_PyImport_FrozenStdlib` - Standard library frozen modules - `_PyImport_FrozenTest` - Test frozen modules - `PyImport_FrozenModules` - Main frozen modules array - `_PyImport_FrozenAliases` - Frozen module aliases @@ -78,7 +78,7 @@ All stubs are implemented in: `Python/frozen_stubs.c` **Stubs Created**: - `plock()` - Process memory locking (Solaris-specific) -**Implementation**: Returns -1 with errno set to `ENOSYS` (not implemented). Also commented out `HAVE_PLOCK` in `Include/pyconfig.h`. +**Implementation**: Returns -1 with errno set to `ENOSYS` (not implemented). Also removed `HAVE_PLOCK` from pyconfig.h. **Note**: `plock()` is a legacy Solaris function not available on modern Linux systems. @@ -86,7 +86,7 @@ All stubs are implemented in: `Python/frozen_stubs.c` ### pyconfig.h Modifications -The following configuration define was commented out in `Include/pyconfig.h`: +The following configuration define was commented out: ```c /* plock is not available on modern Linux systems */ From 9af93798059131c2ad47665c189a660cabf6d4b1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Dec 2025 23:38:30 +0000 Subject: [PATCH 4/5] Fix and enable faulthandler module compilation - Fixed non-constant initializer error by replacing Py_ARRAY_LENGTH with sizeof - Enabled faulthandler.c in CMakeLists.txt - Removed faulthandler stubs from frozen_stubs.c - Updated STUBS.md to reflect faulthandler is now functional Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- CMakeLists.txt | 2 +- Modules/faulthandler.c | 4 +++- Python/frozen_stubs.c | 13 ------------- STUBS.md | 23 +++++++++++++---------- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffabb07..cd6eb55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,7 @@ set(OTHER_MODULE_SOURCES Modules/symtablemodule.c Modules/xxsubtype.c Modules/atexitmodule.c - # Modules/faulthandler.c # Has compilation issues with constant initialization + Modules/faulthandler.c Modules/_datetimemodule.c Modules/_tracemalloc.c ) diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index d49ce79..546e7a1 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -71,8 +71,10 @@ static fault_handler_t faulthandler_handlers[] = { handler fails in faulthandler_fatal_error() */ {SIGSEGV, 0, "Segmentation fault", } }; +/* Calculate array length using sizeof instead of Py_ARRAY_LENGTH to avoid + non-constant initializer error */ static const size_t faulthandler_nsignals = \ - Py_ARRAY_LENGTH(faulthandler_handlers); + sizeof(faulthandler_handlers) / sizeof(faulthandler_handlers[0]); #ifdef FAULTHANDLER_USE_ALT_STACK # define stack _PyRuntime.faulthandler.stack diff --git a/Python/frozen_stubs.c b/Python/frozen_stubs.c index 7429766..286adcb 100644 --- a/Python/frozen_stubs.c +++ b/Python/frozen_stubs.c @@ -66,19 +66,6 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config) return PyStatus_Ok(); } -/* Faulthandler stubs - module excluded from build */ -int -_PyFaulthandler_Init(int enable) -{ - return 0; -} - -void -_PyFaulthandler_Fini(void) -{ - /* No-op */ -} - /* plock stub - not available on all systems */ #ifndef HAVE_PLOCK int plock(int op) diff --git a/STUBS.md b/STUBS.md index 5c006a5..6317c20 100644 --- a/STUBS.md +++ b/STUBS.md @@ -63,13 +63,14 @@ All stubs are implemented in: `Python/frozen_stubs.c` **Purpose**: Signal handling and crash reporting module. -**Stubs Created**: -- `_PyFaulthandler_Init()` - Initialize fault handler -- `_PyFaulthandler_Fini()` - Finalize fault handler +**Status**: ✅ **RESOLVED** - Faulthandler module is now fully functional and included in the build. -**Implementation**: No-op functions that return success. Fault handler module excluded from build due to compilation issues. +**Resolution**: Fixed the constant initialization error by replacing `Py_ARRAY_LENGTH()` macro with direct `sizeof` calculation for the `faulthandler_nsignals` variable. The macro's type-checking feature using `__builtin_types_compatible_p` is not a constant expression, so using simple `sizeof(array) / sizeof(array[0])` resolves the compilation issue. -**Note**: The faulthandler module was excluded from compilation (`Modules/faulthandler.c`) due to constant initialization errors with `Py_ARRAY_LENGTH` macro. +**Changes Made**: +- Modified `Modules/faulthandler.c` to use `sizeof` instead of `Py_ARRAY_LENGTH` for array length calculation +- Enabled faulthandler module in `CMakeLists.txt` +- Removed stub implementations from `Python/frozen_stubs.c` ### 7. POSIX Functions @@ -97,16 +98,18 @@ This prevents the code from attempting to call the non-existent `plock()` functi ## Module Exclusions -The following module was excluded from the build: +~~The following module was excluded from the build:~~ -- **faulthandler** (`Modules/faulthandler.c`) - Excluded due to compilation errors with non-constant array initialization +~~- **faulthandler** (`Modules/faulthandler.c`) - Excluded due to compilation errors with non-constant array initialization~~ + +**Update**: No modules are currently excluded. The faulthandler module has been fixed and is now included in the build. ## Impact on Functionality These stubs mean the following features are not available in this build: 1. **No frozen modules**: Cannot embed Python code as frozen C arrays -2. **No fault handler**: No signal handling for crashes/segfaults +2. ~~**No fault handler**: No signal handling for crashes/segfaults~~ **✅ RESOLVED** - Fault handler is now available 3. **No plock**: No Solaris-style process memory locking 4. **Minimal build info**: Git metadata is stubbed with placeholder values 5. **No custom built-in modules**: Only modules explicitly linked are available @@ -116,7 +119,7 @@ These stubs mean the following features are not available in this build: To get a fully-functional Python interpreter, the following would be needed: 1. Generate actual frozen modules using `Tools/build/freeze_modules.py` -2. Re-enable and fix the faulthandler module compilation +2. ~~Re-enable and fix the faulthandler module compilation~~ **✅ COMPLETED** 3. Implement proper path configuration in `_PyConfig_InitPathConfig()` 4. Generate real build information with git metadata 5. Add more built-in modules to the `_PyImport_Inittab` table @@ -131,7 +134,7 @@ The interpreter successfully: ## Build Statistics -- **Total source files compiled**: 177 +- **Total source files compiled**: 178 (increased from 177 with faulthandler enabled) - **Core library size**: libpython_core.a - **Executable**: typthon - **Build tool**: Ninja (recommended) or Unix Makefiles From f55db59a1a153757ef067546249c9315155b84f6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Dec 2025 23:41:56 +0000 Subject: [PATCH 5/5] Implement dynamic git version information in build metadata - Added CMake git detection to capture branch and commit hash - Modified frozen_stubs.c to use CMake-provided git information - Build info now shows actual git metadata instead of "default" - Updated STUBS.md to reflect improvement Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- CMakeLists.txt | 28 ++++++++++++++++++++++++++++ Python/frozen_stubs.c | 16 +++++++++++++--- STUBS.md | 21 ++++++++++++++------- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd6eb55..84a2a8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,28 @@ set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +# Generate git version information +find_package(Git QUIET) +if(GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) +else() + set(GIT_COMMIT_HASH "unknown") + set(GIT_BRANCH "unknown") +endif() + # Platform detection if(UNIX AND NOT APPLE) set(LINUX TRUE) @@ -27,6 +49,12 @@ if(NOT MSVC) add_compile_options(-fwrapv -fno-strict-aliasing) endif() +# Add git version information as compile definitions +add_compile_definitions( + GIT_COMMIT_HASH="${GIT_COMMIT_HASH}" + GIT_BRANCH="${GIT_BRANCH}" +) + # Collect Python core source files file(GLOB PYTHON_SOURCES Python/*.c) file(GLOB OBJECTS_SOURCES Objects/*.c) diff --git a/Python/frozen_stubs.c b/Python/frozen_stubs.c index 286adcb..82786a1 100644 --- a/Python/frozen_stubs.c +++ b/Python/frozen_stubs.c @@ -34,22 +34,32 @@ struct _inittab _PyImport_Inittab[] = { }; /* Build info stubs */ + +/* Use CMake-generated git information if available */ +#ifndef GIT_COMMIT_HASH +#define GIT_COMMIT_HASH "unknown" +#endif + +#ifndef GIT_BRANCH +#define GIT_BRANCH "default" +#endif + const char * Py_GetBuildInfo(void) { - return "Typthon 3.14.0 (default, " __DATE__ " " __TIME__ ")"; + return "Typthon 3.14.0 (" GIT_BRANCH ":" GIT_COMMIT_HASH ", " __DATE__ " " __TIME__ ")"; } const char * _Py_gitidentifier(void) { - return "default"; + return GIT_BRANCH; } const char * _Py_gitversion(void) { - return "Typthon 3.14.0"; + return "Typthon 3.14.0:" GIT_COMMIT_HASH; } /* DL open flags stub */ diff --git a/STUBS.md b/STUBS.md index 6317c20..15ad856 100644 --- a/STUBS.md +++ b/STUBS.md @@ -34,12 +34,19 @@ All stubs are implemented in: `Python/frozen_stubs.c` **Purpose**: Provide version and build metadata to the interpreter. -**Stubs Created**: -- `Py_GetBuildInfo()` - Returns build date/time string -- `_Py_gitidentifier()` - Returns git branch identifier ("default") -- `_Py_gitversion()` - Returns version string ("Typthon 3.14.0") +**Status**: ✅ **IMPROVED** - Git metadata is now dynamically generated at build time. -**Implementation**: Simple string returns with minimal metadata. +**Implementation**: +- `Py_GetBuildInfo()` - Returns build string with git branch, commit hash, and build timestamp +- `_Py_gitidentifier()` - Returns actual git branch name from CMake +- `_Py_gitversion()` - Returns version string with commit hash + +**Resolution**: Added CMake configuration to detect git information at build time and pass it as compile definitions. The functions now return actual git metadata instead of placeholder values. + +**Changes Made**: +- Modified `CMakeLists.txt` to detect git branch and commit hash +- Updated `Python/frozen_stubs.c` to use CMake-generated definitions +- Build info now shows: "Typthon 3.14.0 (branch:hash, date time)" format ### 4. Dynamic Loading @@ -111,7 +118,7 @@ These stubs mean the following features are not available in this build: 1. **No frozen modules**: Cannot embed Python code as frozen C arrays 2. ~~**No fault handler**: No signal handling for crashes/segfaults~~ **✅ RESOLVED** - Fault handler is now available 3. **No plock**: No Solaris-style process memory locking -4. **Minimal build info**: Git metadata is stubbed with placeholder values +4. ~~**Minimal build info**: Git metadata is stubbed with placeholder values~~ **✅ IMPROVED** - Git metadata now shows actual branch and commit 5. **No custom built-in modules**: Only modules explicitly linked are available ## Future Improvements @@ -121,7 +128,7 @@ To get a fully-functional Python interpreter, the following would be needed: 1. Generate actual frozen modules using `Tools/build/freeze_modules.py` 2. ~~Re-enable and fix the faulthandler module compilation~~ **✅ COMPLETED** 3. Implement proper path configuration in `_PyConfig_InitPathConfig()` -4. Generate real build information with git metadata +4. ~~Generate real build information with git metadata~~ **✅ COMPLETED** 5. Add more built-in modules to the `_PyImport_Inittab` table ## Testing