Skip to content

Commit 40ca5c7

Browse files
committed
unix: link _decimal against standalone libmpdec
The previous commit enabled support for building mpdecimal as a standalone project. This commit replaces the inline build of mpdecimal as part of CPython to linking against our standalone mpdecimal. On Python 3.8 and 3.9, this effectively upgrades mpdecimal to 2.5.1. This required a minimal patch. As part of this, we also fix the defines on macOS. UNIVERSAL is no longer needed, as this is handled by mpdecimal's build system. But _decimal.c does need one of the CONFIG_ defines set or else things blow up.
1 parent fe9fca0 commit 40ca5c7

File tree

3 files changed

+33
-42
lines changed

3 files changed

+33
-42
lines changed

cpython-unix/build-cpython.sh

+6
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ patch -p1 < ${ROOT}/patch-ctypes-callproc.patch
188188
# See https://bugs.python.org/issue37060.
189189
patch -p1 < ${ROOT}/patch-ctypes-static-binary.patch
190190

191+
# Older versions of Python need patching to work with modern mpdecimal.
192+
if [[ "${PYTHON_MAJMIN_VERSION}" = "3.8" || "${PYTHON_MAJMIN_VERSION}" = "3.9" ]]; then
193+
patch -p1 < ${ROOT}/patch-decimal-modern-mpdecimal.patch
194+
fi
195+
191196
# CPython 3.10 added proper support for building against libedit outside of
192197
# macOS. On older versions, we need to patch readline.c.
193198
if [[ "${PYTHON_MAJMIN_VERSION}" = "3.8" || "${PYTHON_MAJMIN_VERSION}" = "3.9" ]]; then
@@ -262,6 +267,7 @@ CONFIGURE_FLAGS="
262267
--host=${TARGET_TRIPLE}
263268
--prefix=/install
264269
--with-openssl=${TOOLS_PATH}/deps
270+
--with-system-libmpdec
265271
--without-ensurepip
266272
${EXTRA_CONFIGURE_FLAGS}"
267273

cpython-unix/extension-modules.yml

+5-42
Original file line numberDiff line numberDiff line change
@@ -211,59 +211,22 @@ _dbm:
211211
_decimal:
212212
sources:
213213
- _decimal/_decimal.c
214-
- _decimal/libmpdec/basearith.c
215-
- _decimal/libmpdec/constants.c
216-
- _decimal/libmpdec/context.c
217-
- _decimal/libmpdec/convolute.c
218-
- _decimal/libmpdec/crt.c
219-
- _decimal/libmpdec/difradix2.c
220-
- _decimal/libmpdec/fnt.c
221-
- _decimal/libmpdec/fourstep.c
222-
- _decimal/libmpdec/io.c
223-
- _decimal/libmpdec/mpdecimal.c
224-
- _decimal/libmpdec/numbertheory.c
225-
- _decimal/libmpdec/sixstep.c
226-
- _decimal/libmpdec/transpose.c
227-
sources-conditional:
228-
# memory.c renamed to mpalloc.c in 3.9.
229-
- source: _decimal/libmpdec/memory.c
230-
maximum-python-version: "3.8"
231-
- source: _decimal/libmpdec/mpalloc.c
232-
minimum-python-version: "3.9"
233-
includes:
234-
- Modules/_decimal/libmpdec
214+
includes-deps:
215+
- include
235216
defines-conditional:
236-
- define: ANSI=1
237-
targets:
238-
- .*-unknown-linux-.*
239-
- define: ASM=1
240-
targets:
241-
- i686-.*
242-
- x86_64.*
243217
- define: CONFIG_32=1
244218
targets:
245219
- armv7-.*
246220
- i686-.*
247221
- mips-.*
248222
- mipsel-.*
249223
- define: CONFIG_64=1
250-
targets:
251-
# CONFIG_64 is mutually exclusive with UNIVERSAL=1
252-
- aarch64-unknown-linux-.*
253-
- s390x-unknown-linux-.*
254-
- x86_64.*-unknown-linux-.*
255-
- define: HAVE_UINT128_T=1
256224
targets:
257225
- aarch64-.*
258-
- s390x-.*
226+
- s390x-unknown-linux-.*
259227
- x86_64.*
260-
- define: PPRO=1
261-
targets:
262-
- i686-.*
263-
# TODO is this correct for non-universal binaries?
264-
- define: UNIVERSAL=1
265-
targets:
266-
- .*-apple-.*
228+
links:
229+
- mpdec
267230

268231
_elementtree:
269232
sources:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
2+
index 83e237d02b..9a4329f494 100644
3+
--- a/Modules/_decimal/_decimal.c
4+
+++ b/Modules/_decimal/_decimal.c
5+
@@ -3293,7 +3293,7 @@ dec_format(PyObject *dec, PyObject *args)
6+
}
7+
else {
8+
size_t n = strlen(spec.dot);
9+
- if (n > 1 || (n == 1 && !isascii((uchar)spec.dot[0]))) {
10+
+ if (n > 1 || (n == 1 && !isascii((unsigned char)spec.dot[0]))) {
11+
/* fix locale dependent non-ascii characters */
12+
dot = dotsep_as_utf8(spec.dot);
13+
if (dot == NULL) {
14+
@@ -3302,7 +3302,7 @@ dec_format(PyObject *dec, PyObject *args)
15+
spec.dot = PyBytes_AS_STRING(dot);
16+
}
17+
n = strlen(spec.sep);
18+
- if (n > 1 || (n == 1 && !isascii((uchar)spec.sep[0]))) {
19+
+ if (n > 1 || (n == 1 && !isascii((unsigned char)spec.sep[0]))) {
20+
/* fix locale dependent non-ascii characters */
21+
sep = dotsep_as_utf8(spec.sep);
22+
if (sep == NULL) {

0 commit comments

Comments
 (0)