Skip to content

gh-93202: Always use %zd printf formatter #93201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2022
Merged

gh-93202: Always use %zd printf formatter #93201

merged 1 commit into from
May 25, 2022

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented May 25, 2022

Python now always use the %zu and %zd printf formats to
format a size_t or Py_ssize_t number. Building Python 3.12 requires a
C11 compiler, so these printf formats are now always supported.

  • PyObject_Print() and _PyObject_Dump() now use the printf %zd format
    to display an object reference count.
  • Update PY_FORMAT_SIZE_T comment.
  • Remove outdated notes about the %zd format in PyBytes_FromFormat()
    and PyUnicode_FromFormat() documentations.
  • configure no longer checks for the %zd format and no longer defines
    PY_FORMAT_SIZE_T macro in pyconfig.h.
  • pymacconfig.h no longer undefines PY_FORMAT_SIZE_T: macOS 10.4 is
    no longer supported. Python 3.12 now requires macOS 10.6 (Snow
    Leopard) or newer.

@vstinner
Copy link
Member Author

@Yhg1s: Better late than never! The XXX note was added in 2006 by commit 8b87a0b ;-)

Python now always use the ``%zu`` and ``%zd`` printf formats to
format a size_t or Py_ssize_t number. Building Python 3.12 requires a
C11 compiler, so these printf formats are now always supported.

* PyObject_Print() and _PyObject_Dump() now use the printf %zd format
  to display an object reference count.
* Update PY_FORMAT_SIZE_T comment.
* Remove outdated notes about the %zd format in PyBytes_FromFormat()
  and PyUnicode_FromFormat() documentations.
* configure no longer checks for the %zd format and no longer defines
  PY_FORMAT_SIZE_T macro in pyconfig.h.
* pymacconfig.h no longer undefines PY_FORMAT_SIZE_T: macOS 10.4 is
  no longer supported. Python 3.12 now requires macOS 10.6 (Snow
  Leopard) or newer.
@vstinner vstinner changed the title PyObject_Print() uses %zd format with fprintf() gh-93202: Always use %zd printf formatter May 25, 2022
@vstinner
Copy link
Member Author

@methane: Would you mind to review this change?

I found more code to update. I completed my PR. I created the issue #93202 and I added a NEWS entry just in case (if someone gets a build error).

Copy link
Member

@methane methane left a comment

Choose a reason for hiding this comment

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

LGTM.
Would you add "test-with-buildbot" label before merging this?

@vstinner vstinner added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 25, 2022
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @vstinner for commit 8c6742f 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 25, 2022
@vstinner
Copy link
Member Author

Would you add "test-with-buildbot" label before merging this?

Sure! That's a good idea!

Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

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

lgtm

@vstinner
Copy link
Member Author

I'm not sure why the list of pending buildbot jobs is still long 3 hours later. But remaining jobs are very similar of already completed jobs, I don't think that it's worth it to wait for them.

test_launcher is failing on a Windows job, but it's a known and unrelated issue: #93005

So far so good, there is no build error.

@vstinner vstinner merged commit 71d8775 into python:main May 25, 2022
@vstinner vstinner deleted the refcnt_zd branch May 25, 2022 12:21
@vstinner
Copy link
Member Author

I also removed this note in the doc as part of this change:

.. % Similar comments apply to the %ll width modifier and

The ll printf specifier (ex: %lli) is also part of C99.

@vstinner
Copy link
Member Author

Thanks for the review @methane and @erlend-aasland! It's now merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants