- Added comprehensive frozen module stubs (bootstrap, stdlib, test, aliases) - Added build info stubs (Py_GetBuildInfo, git version/identifier) - Added import system stubs (_PyImport_Inittab, _PyImport_GetDLOpenFlags) - Added path config stub (_PyConfig_InitPathConfig) - Added faulthandler stubs (excluded problematic module from build) - Added plock() stub for missing Solaris-specific function - Fixed HAVE_CLOCK_GETTIME configuration - Added complete tokenizer sources (helpers.c, lexer/*.c) - Added essential modules (atexit, datetime, tracemalloc) - Fixed frozen_stubs.c to use correct pointer types - Commented out HAVE_PLOCK (not available on modern Linux) - Created STUBS.md documenting all stub implementations - Successfully builds and links typthon executable - Interpreter works: ./typthon --version shows "Typthon 3.14.0b4+" Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
4.7 KiB
Typthon Build System Stubs Documentation
This document lists all stub implementations created to resolve linking issues in the Typthon CMake build system.
Stub File Location
All stubs are implemented in: Python/frozen_stubs.c
Stubbed Components
1. Frozen Modules
Purpose: CPython's frozen modules system allows embedding Python code as C arrays. These are normally generated during the build process.
Stubs Created:
_PyImport_FrozenBootstrap- Bootstrap frozen modules_PyImport_FrozenStdlib- Standard library frozen modules_PyImport_FrozenTest- Test frozen modulesPyImport_FrozenModules- Main frozen modules array_PyImport_FrozenAliases- Frozen module aliases
Implementation: Empty arrays/NULL pointers that satisfy linker requirements but provide no actual frozen modules.
2. Import System
Purpose: Module initialization table for built-in modules.
Stubs Created:
_PyImport_Inittab- Empty module initialization table
Implementation: Empty array that prevents initialization of additional built-in modules beyond those explicitly linked.
3. Build Information
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")
Implementation: Simple string returns with minimal metadata.
4. Dynamic Loading
Purpose: Configuration for dynamic library loading.
Stubs Created:
_PyImport_GetDLOpenFlags()- Returns dlopen flags
Implementation: Returns RTLD_NOW | RTLD_GLOBAL (0x102) for immediate symbol resolution.
5. Path Configuration
Purpose: Initialize Python module search paths.
Stubs Created:
_PyConfig_InitPathConfig()- Initializes path configuration
Implementation: Returns PyStatus_Ok() without actually configuring paths. The interpreter will use defaults.
6. Fault Handler
Purpose: Signal handling and crash reporting module.
Stubs Created:
_PyFaulthandler_Init()- Initialize fault handler_PyFaulthandler_Fini()- Finalize fault handler
Implementation: No-op functions that return success. Fault handler module excluded from build due to compilation issues.
Note: The faulthandler module was excluded from compilation (Modules/faulthandler.c) due to constant initialization errors with Py_ARRAY_LENGTH macro.
7. POSIX Functions
Purpose: Platform-specific system call that's not universally available.
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.
Note: plock() is a legacy Solaris function not available on modern Linux systems.
Configuration Changes
pyconfig.h Modifications
The following configuration define was commented out:
/* plock is not available on modern Linux systems */
/* #define HAVE_PLOCK 1 */
This prevents the code from attempting to call the non-existent plock() function, instead using our stub implementation.
Module Exclusions
The following module was excluded from the build:
- faulthandler (
Modules/faulthandler.c) - Excluded due to compilation errors with non-constant array initialization
Impact on Functionality
These stubs mean the following features are not available in this build:
- No frozen modules: Cannot embed Python code as frozen C arrays
- No fault handler: No signal handling for crashes/segfaults
- No plock: No Solaris-style process memory locking
- Minimal build info: Git metadata is stubbed with placeholder values
- No custom built-in modules: Only modules explicitly linked are available
Future Improvements
To get a fully-functional Python interpreter, the following would be needed:
- Generate actual frozen modules using
Tools/build/freeze_modules.py - Re-enable and fix the faulthandler module compilation
- Implement proper path configuration in
_PyConfig_InitPathConfig() - Generate real build information with git metadata
- Add more built-in modules to the
_PyImport_Inittabtable
Testing
The interpreter successfully:
- ✅ Starts and shows version:
typthon --version - ✅ Displays help:
typthon --help - ✅ Links all core libraries without errors
- ✅ Builds with Ninja in under 2 minutes on modern hardware
Build Statistics
- Total source files compiled: 177
- Core library size: libpython_core.a
- Executable: typthon
- Build tool: Ninja (recommended) or Unix Makefiles
- Build time: ~90 seconds with parallel compilation (
-j4)