mirror of
https://github.com/johndoe6345789/typthon.git
synced 2026-04-24 13:45:05 +00:00
Merge pull request #20 from johndoe6345789/copilot/fix-remaining-issues-in-stubs-md
Resolve remaining stub issues: Enable faulthandler and implement git version metadata
This commit is contained in:
@@ -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)
|
||||
@@ -102,7 +130,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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
@@ -66,19 +76,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)
|
||||
|
||||
44
STUBS.md
44
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
|
||||
|
||||
@@ -63,13 +70,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,18 +105,20 @@ 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
|
||||
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
|
||||
@@ -116,9 +126,9 @@ 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
|
||||
4. ~~Generate real build information with git metadata~~ **✅ COMPLETED**
|
||||
5. Add more built-in modules to the `_PyImport_Inittab` table
|
||||
|
||||
## Testing
|
||||
@@ -131,7 +141,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
|
||||
|
||||
Reference in New Issue
Block a user