WebSafe 3.7github.com
|
|
🏠
Skip to content

gh-132983: Simplify _zstd_exec()#133775

Merged
AA-Turner merged 6 commits intopython:mainfrom
AA-Turner:zstd-exec
May 9, 2025
Merged

gh-132983: Simplify _zstd_exec()#133775
AA-Turner merged 6 commits intopython:mainfrom
AA-Turner:zstd-exec

Conversation

@AA-Turner
Copy link
Member

@AA-Turner AA-Turner commented May 9, 2025

cc @Rogdham (can't request review).

Follows on from #133670. Again best reviewed commit-by-commit. We remove around 100 lines of C code overall.

The last commit (6a3a135 (#133775)) only serves to merge two functions and contains no behaviour change, but does increase the diff size.

  • Rename type specs to add underscores after 'zstd'
  • Replace the add_type_to_module() function with an ADD_TYPE macro, using PyModule_AddType instead of PyModule_AddObjectRef.
  • Remove the unused 'empty_readonly_memoryview', 'str_flush', 'str_read', 'str_readinto', and 'str_write' module state members
  • Set the CONTINUE/FLUSH_* constants in Python rather than C. To achieve this, export the three ZSTD_EndDirective enum members from the _zstd module.
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Overall, I think it's a nice improvement but usually, C classes are read-only (e.g., _sha2.SHA2Type does not allow setting class variables afterwards; the same holds for lzma.LZMACompressor so it would be better to do the same for the Zstd* types)

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

It would be better to make classes implemented in C immutable.

Copy link
Member

@emmatyping emmatyping left a comment

Choose a reason for hiding this comment

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

Thanks! These are great refactors.

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

You can add Py_TPFLAGS_IMMUTABLETYPE in this PR or in another.

@AA-Turner AA-Turner merged commit bbe9c31 into python:main May 9, 2025
42 checks passed
@AA-Turner AA-Turner deleted the zstd-exec branch May 9, 2025 19:15
@AA-Turner AA-Turner added the needs backport to 3.14 bugs and security fixes label May 9, 2025
@miss-islington-app
Copy link

Thanks @AA-Turner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 9, 2025
(cherry picked from commit bbe9c31)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented May 9, 2025

GH-133786 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 9, 2025
AA-Turner added a commit that referenced this pull request May 9, 2025
gh-132983: Simplify ``_zstd_exec()`` (GH-133775)
(cherry picked from commit bbe9c31)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants

Comments