GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-115119: Fix libmpdec detection when pkg-config files are missing by stratakis · Pull Request #150502 · python/cpython

Conversation

@stratakis

@stratakis stratakis commented May 27, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

The fallback for systems with no mpdecimal .pc files used AC_LINK_IFELSE directly, which relied on LIBMPDEC_LIBS being set. On failure this was empty so the link test ran without -lmpdec.

Use AC_CHECK_HEADER and AC_CHECK_LIB instead.

  • Issue: Unvendor libmpdec sources #115119

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@stratakis
pythongh-115119: Fix libmpdec detection when pkg-config files are mis…
f508b78
…sing

The fallback for systems with no mpdecimal .pc files used AC_LINK_IFELSE
directly, which relied on LIBMPDEC_LIBS being set. On failure this was empty
so the link test ran without -lmpdec.

Use AC_CHECK_HEADER and AC_CHECK_LIB instead.
@stratakis
stratakis requested review from AA-Turner, corona10, emmatyping and erlend-aasland as code owners May 27, 2026 02:33
@bedevere-app bedevere-app Bot mentioned this pull request May 27, 2026
Unvendor libmpdec sources #115119
Closed
15 tasks done
@bedevere-app bedevere-app Bot added the awaiting review label May 27, 2026
@stratakis

stratakis commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

Found when trying to test what configure options to add for my buildbots and I saw the _decimal module wasn't actually building on centos stream 9 and 10, because they ship mpdecimal 2.5.1, hence no .pc files.

I followed the convention of other libraries.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev
skirpichev self-requested a review May 27, 2026 02:44
@skirpichev

skirpichev commented May 27, 2026

Copy link
Copy Markdown
Member

Could you please add a news entry?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

skirpichev
skirpichev approved these changes May 27, 2026
View reviewed changes

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (modulo news entry)

Thanks for fixing this, it was my fault to believe, that pkg-config support was introduced in v2.5.0. But it was v4.0.0.

(Tested with v2.5.0)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting core review and removed awaiting review labels May 27, 2026
@stratakis
Add news entry
7430986
@skirpichev

skirpichev commented May 31, 2026

Copy link
Copy Markdown
Member

CC @zware, @vstinner

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Jun 1, 2026

Copy link
Copy Markdown
Member

How can I test this change? I need a system with libmpdec library and header files installed, but where pkg-config 'libmpdec >= 2.5.0' --libs fails? Can I replace libmpdec >= 2.5.0 with libmpdec >= 55.0 to test the change for example? What is the expected behavior?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev

skirpichev commented Jun 1, 2026

Copy link
Copy Markdown
Member

How can I test this change?

You can install libmpdec from sources for versions < 4.0.0. (./configure && make all install)

I also checked Debian and derivatives, nobody ships *.pc files as a patch :(.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Jun 1, 2026

Copy link
Copy Markdown
Member

I applied the following change on configure.ac and I ran make regen-configure.

diff --git a/configure.ac b/configure.ac
index c8dce3fd49b..b9020368664 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4376,7 +4376,7 @@ if test "$ac_cv_ffi_complex_double_supported" = "yes"; then
 fi
 
 dnl Check for libmpdec >= 2.5.0
-PKG_CHECK_MODULES([LIBMPDEC], [libmpdec >= 2.5.0], [have_mpdec=yes], [
+PKG_CHECK_MODULES([LIBMPDEC], [libmpdec >= 55.0], [have_mpdec=yes], [
   WITH_SAVE_ENV([
     CPPFLAGS="$CPPFLAGS $LIBMPDEC_CFLAGS"
     LIBS="$LIBS $LIBMPDEC_LIBS"

./configure fails to locate libmpdecimal:

checking for libmpdec >= 55.0... no
...
checking for stdlib extension module _decimal... missing

I downloaded this PR, made a similar ./configure.ac change, and ran make regen-configure. This time, it succeeded:

checking for libmpdec >= 55.0... no
checking for mpdecimal.h... (cached) yes
checking for mpd_version in -lmpdec... (cached) yes
...
checking for stdlib extension module _decimal... yes

I get these flags in Makefile:

$ grep ^MODULE__DECIMAL Makefile
MODULE__DECIMAL_STATE=yes
MODULE__DECIMAL_CFLAGS= -DTEST_COVERAGE
MODULE__DECIMAL_LDFLAGS=-lmpdec -lm

Python builds successfully and I can import the decimal module.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner reviewed Jun 1, 2026
View reviewed changes
Comment thread configure.ac
], [const char *x = mpd_version();])],
[have_mpdec=yes],
[have_mpdec=no])
AC_CHECK_HEADER([mpdecimal.h], [

@vstinner vstinner Jun 1, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AC_CHECK_HEADER([mpdecimal.h] seems to be redundant to me. Is it really useful? We already check we can build/link a C program which starts with #include <mpdecimal.h> (below).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@stratakis stratakis Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good to have it there for the helpful error message, referencing that the header is missing aka "checking for mpdecimal.h... no". In the case the library is there without the header it will move on to compile the program with "checking for mpd_version in -lmpdec... yes" and then fail.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

skirpichev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@skirpichev skirpichev Jun 2, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. These checks are logically distinct: first is for the header, next is for the library version.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
vstinner merged commit 025cc26 into python:main Jun 2, 2026
50 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting core review label Jun 2, 2026
@vstinner

vstinner commented Jun 2, 2026

Copy link
Copy Markdown
Member

Merged, thanks for the fix.

The 3.15 branch has different code in configure.ac, it doesn't seem to be affected.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev

skirpichev commented Jun 2, 2026

Copy link
Copy Markdown
Member

The 3.15 branch has different code in configure.ac, it doesn't seem to be affected.

Old releases are affected. But in such cases the fallback is using bundled libmpdec, instead of undetected from the system. I think it's less severe issue, probably not worth to be fixed.

vstinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stratakis

stratakis commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

The 3.15 branch has different code in configure.ac, it doesn't seem to be affected.

Old releases are affected. But in such cases the fallback is using bundled libmpdec, instead of undetected from the system. I think it's less severe issue, probably not worth to be fixed.

I don't see any issues via testing on previous branches, some stale makefile rules but if the system libmpdec option is used then it will properly link to that one without building the bundled one.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev

skirpichev commented Jun 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

if the system libmpdec option is used then it will properly link to that one without building the bundled one.

I don't understand how this could be. See code e.g. in the v3.14:

cpython/configure.ac

Lines 4218 to 4232 in 7756f59

AC_DEFUN([USE_BUNDLED_LIBMPDEC],
[LIBMPDEC_CFLAGS="-I\$(srcdir)/Modules/_decimal/libmpdec"
LIBMPDEC_LIBS="-lm \$(LIBMPDEC_A)"
LIBMPDEC_INTERNAL="\$(LIBMPDEC_HEADERS) \$(LIBMPDEC_A)"
have_mpdec=yes
with_system_libmpdec=no])
AS_VAR_IF(
[with_system_libmpdec], [yes],
[PKG_CHECK_MODULES(
[LIBMPDEC], [libmpdec >= 2.5.0], [],
[LIBMPDEC_CFLAGS=${LIBMPDEC_CFLAGS-""}
LIBMPDEC_LIBS=${LIBMPDEC_LIBS-"-lmpdec -lm"}
LIBMPDEC_INTERNAL=])],
[USE_BUNDLED_LIBMPDEC()])

If PKG_CHECK_MODULES() fails - USE_BUNDLED_LIBMPDEC() is used with with_system_libmpdec=no.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stratakis

stratakis commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

if the system libmpdec option is used then it will properly link to that one without building the bundled one.

I don't understand how this could be. See code e.g. in the v3.14:

cpython/configure.ac

Lines 4218 to 4232 in 7756f59

AC_DEFUN([USE_BUNDLED_LIBMPDEC],
[LIBMPDEC_CFLAGS="-I\$(srcdir)/Modules/_decimal/libmpdec"
LIBMPDEC_LIBS="-lm \$(LIBMPDEC_A)"
LIBMPDEC_INTERNAL="\$(LIBMPDEC_HEADERS) \$(LIBMPDEC_A)"
have_mpdec=yes
with_system_libmpdec=no])
AS_VAR_IF(
[with_system_libmpdec], [yes],
[PKG_CHECK_MODULES(
[LIBMPDEC], [libmpdec >= 2.5.0], [],
[LIBMPDEC_CFLAGS=${LIBMPDEC_CFLAGS-""}
LIBMPDEC_LIBS=${LIBMPDEC_LIBS-"-lmpdec -lm"}
LIBMPDEC_INTERNAL=])],
[USE_BUNDLED_LIBMPDEC()])

If PKG_CHECK_MODULES() fails - USE_BUNDLED_LIBMPDEC() is used with with_system_libmpdec=no.

USE_BUNDLED_LIBMPDEC() is the argument to AS_VAR_IF() so it won't fall through if PKG_CHECK_MODULES() fails. I've also verified this on a Centos Stream 9 machine on the 3.14 branch, no bundled object files and _decimal.so is linked against the system library (assuming of course I tested properly).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments
@skirpichev skirpichev skirpichev approved these changes
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner
@corona10 corona10 Awaiting requested review from corona10 corona10 is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@emmatyping emmatyping Awaiting requested review from emmatyping emmatyping is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@stratakis @skirpichev @vstinner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.