Repository navigation
Python 3.11 loses the ability to set PYTHON_DECIMAL_WITH_MACHINE #98557
Description
Bug report
Python 3.10 had the ability to set PYTHON_DECIMAL_WITH_MACHINE to override the choice of configuration for the _decimal module:
Lines 2388 to 2397 in dcb342b
| machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE') | |
| if machine: | |
| # Override automatic configuration to facilitate testing. | |
| define_macros = config[machine] | |
| elif MACOS: | |
| # Universal here means: build with the same options Python | |
| # was built with. | |
| define_macros = config['universal'] | |
| elif sizeof_size_t == 8: |
Since Python 3.11, this is no longer possible. This feature was necessary, on macOS particularly, with the --with-system-libmpdec option if that system libmpdec is configured differently to the default Python config. On macOS, the default Python config forces universal, while setting PYTHON_DECIMAL_WITH_MACHINE allowed it to be single-arch.
libmpdec produces different headers depending on how it was built, which is why the setting is important to be able to override. Without it, the _decimal module will fail to compile if the default does not match how system libmpdec was built.
Homebrew's Python currently depends on this feature.
A test within CPython also seems to depend on this feature:
cpython/Modules/_decimal/tests/runall-memorydebugger.sh
Lines 63 to 79 in f4c0348
| unset PYTHON_DECIMAL_WITH_MACHINE | |
| libmpdec_config=$config | |
| if [ X"$config" != X"auto" ]; then | |
| PYTHON_DECIMAL_WITH_MACHINE=$config | |
| export PYTHON_DECIMAL_WITH_MACHINE | |
| else | |
| libmpdec_config="" | |
| fi | |
| ############ refleak tests ########### | |
| print_config "refleak tests: config=$config" $args | |
| printf "\nbuilding python ...\n\n" | |
| cd ../../ | |
| $GMAKE distclean > /dev/null 2>&1 | |
| ./configure CFLAGS="$ADD_CFLAGS" LDFLAGS="$ADD_LDFLAGS" --with-pydebug $args > /dev/null 2>&1 | |
| $GMAKE | grep _decimal |
Your environment
- CPython versions tested on: 3.11.0rc2
- Operating system and architecture: macOS 12 (x86_64 and arm64)
Activity
AlexWaygood commentedon Oct 24, 2022
Cc. @rhettinger for
decimalmodule expertise.erlend-aasland commentedon Oct 24, 2022
FTR, this was removed in GH-29541 (cc. @tiran as PR author and @mdickinson as PR reviewer)
erlend-aasland commentedon Oct 24, 2022
AFAICS from GH-29541, it should be possible to set
PYTHON_DECIMAL_WITH_MACHINEvia CFLAGS (for exampleLIBMPDEC_CFLAGS). @Bo98, can you please test this?Bo98 commentedon Oct 24, 2022
What reads
PYTHON_DECIMAL_WITH_MACHINE? It's not a define to be passed to C but something that used to change what item is selected from:cpython/configure.ac
Lines 3882 to 3891 in 75a6fad
Unless you suggest that I instead pass
LIBMPDEC_CFLAGS=-DCONFIG_64=1 -DASM=1on x86_64 andLIBMPDEC_CFLAGS=-DCONFIG_64=1 -DANSI=1 -DHAVE_UINT128_T=1on arm64? (Assuming this list is never changing.)erlend-aasland commentedon Oct 24, 2022
Ah, sorry, you are right. I misread the diff from GH-29541; it is used as an index, not a CFLAG.
erlend-aasland commentedon Oct 24, 2022
Yes, it seems this ability is now lost; there is no way to manually override that
AS_CASE. We'd either have to reintroducePYTHON_DECIMAL_WITH_MACHINE, or provide a newconfigureswitch for this, if we were to reintroduce this.erlend-aasland commentedon Oct 24, 2022
You mentioned Homebrew? Does this prevent Homebrew from building and distributing Python 3.11? Is there a Homebrew ticket for this?
erlend-aasland commentedon Oct 24, 2022
From #98557 (comment):
Then from the OP:
I suggest you use
LIBMPDEC_CFLAGSto set these flags depending on how yourlibmpdecwas built. That seems to me to be a more robust approach than lettingconfigurechose flags which might not reflect how yourlibmpdecwas built.ISTM we don't need a way to override the
libmpdec_machineswitch inconfigure.Bo98 commentedon Oct 24, 2022
Not yet considering we don't ship betas, but what we'll probably do for 3.11.0 (and what I've done in a local test rc2 build) is a
s/libmpdec_machine=universal/libmpdec_machine=x64/(uint128on arm64) onconfigure. Not a desirable long-term solution but should be ok for a short-term fix.PYTHON_DECIMAL_WITH_MACHINEdid directly match the option you would pass to libmpdec configure. If you passedMACHINE=x64to libmpdec while building then you would pass the same to Python.It made sense and is what Stefan Krah recommended we did.
Might I propose an alternative way forward here however. I propose looking into not setting any CFLAGS for the system libmpdec and checking
MPD_CONFIG_64andMPD_CONFIG_32in_decimalsource code, given mpdecimal.h should tell you how it was built by setting those.FWIW, this is what the relevent section of mpdecimal.h looks like on a different configurations of system libmpdec:
Universal
x64 and uint128
erlend-aasland commentedon Oct 24, 2022
That sounds like a better way forward indeed. I've already pinged Christian on this issue; let's wait and see if he also agrees.
carlocab commentedon Oct 4, 2024
It's been a while here. Can we find a way to move this forward?
erlend-aasland commentedon Oct 14, 2024
For 3.11? Unfortunately not; 3.11 only received security fixes. For 3.12 and newer, the environment variables
LIBMPDEC_CFLAGSandLIBMPDEC_LIBSare available if you want to customise how_decimalis built.See also #115119.
Bo98 commentedon Oct 14, 2024
Looks like #115406 might have fixed this by moving the assumptions into a
AS_VAR_IF([with_system_libmpdec], [no]in 3.13. Specifically, the flag anddecimal.cchanges rather than the actualpkg-configpart, so the fix works for pre-4.0 too.For 3.11 and 3.12 it was previously unfixable without patching the
configurefile (LIBMPDEC_CFLAGSwon't override it), unless a backport of that new patch is applied.erlend-aasland commentedon Oct 14, 2024
Right, so my gut feel would be that a backport of #115406 probably won't happen; such changes to the
configurescript are always slight behavioural changes to the build system, so backporting them may create havoc for distros.