forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] main from python:main #38
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reviewer's GuideThis PR enhances thread-safety in the _zstd extension by replacing critical-section macros with explicit PyMutex locks across compressor, decompressor, and dictionary modules, refactors and unifies dictionary loading logic, cleans up generated clinic code, adds multithreading tests for shared dictionaries, and includes minor library fixes in asyncio and types. Sequence Diagram for ZstdCompressor Dictionary Loading with LockingsequenceDiagram
participant C as Caller
participant ZSC as ZstdCompressor
participant ZDict as ZstdDict
C->>ZSC: _zstd_load_c_dict(dict_obj, type)
activate ZSC
ZSC->>ZDict: PyMutex_Lock(&zd->lock)
activate ZDict
ZSC->>ZSC: Calls _zstd_load_impl(zd, type)
activate ZSC
alt type == DICT_TYPE_DIGESTED
ZSC->>ZDict: _get_CDict(zd, compression_level)
activate ZDict
note right of ZDict: asserts zd->lock is held
ZDict-->>ZSC: ZSTD_CDict*
deactivate ZDict
ZSC->>ZSC: ZSTD_CCtx_refCDict(cctx, c_dict)
else type == DICT_TYPE_UNDIGESTED
ZSC->>ZSC: ZSTD_CCtx_loadDictionary(cctx, zd->dict_content)
else type == DICT_TYPE_PREFIX
ZSC->>ZSC: ZSTD_CCtx_refPrefix(cctx, zd->dict_content)
end
deactivate ZSC
ZSC->>ZDict: PyMutex_Unlock(&zd->lock)
deactivate ZDict
ZSC-->>C: result
deactivate ZSC
Sequence Diagram for ZstdCompressor Compression with LockingsequenceDiagram
participant C as Caller
participant ZSC as ZstdCompressor
C->>ZSC: _zstd_ZstdCompressor_compress_impl(data, mode)
activate ZSC
ZSC->>ZSC: PyMutex_Lock(&self->lock)
activate ZSC
alt use_multithread and mode == ZSTD_e_continue
ZSC->>ZSC: compress_mt_continue_lock_held(data)
note right of ZSC: asserts self->lock is held
else
ZSC->>ZSC: compress_lock_held(data, mode)
note right of ZSC: asserts self->lock is held
end
ZSC->>ZSC: PyMutex_Unlock(&self->lock)
deactivate ZSC
ZSC-->>C: compressed_data
deactivate ZSC
Sequence Diagram for ZstdDecompressor Dictionary Loading with LockingsequenceDiagram
participant C as Caller
participant ZSD as ZstdDecompressor
participant ZDict as ZstdDict
C->>ZSD: _zstd_load_d_dict(dict_obj, type)
activate ZSD
ZSD->>ZDict: PyMutex_Lock(&zd->lock)
activate ZDict
ZSD->>ZSD: Calls _zstd_load_impl(zd, type)
activate ZSD
alt type == DICT_TYPE_DIGESTED
ZSD->>ZDict: _get_DDict(zd)
activate ZDict
note right of ZDict: asserts zd->lock is held
ZDict-->>ZSD: ZSTD_DDict*
deactivate ZDict
ZSD->>ZSD: ZSTD_DCtx_refDDict(dctx, d_dict)
else type == DICT_TYPE_UNDIGESTED
ZSD->>ZSD: ZSTD_DCtx_loadDictionary(dctx, zd->dict_content)
else type == DICT_TYPE_PREFIX
ZSD->>ZSD: ZSTD_DCtx_refPrefix(dctx, zd->dict_content)
end
deactivate ZSD
ZSD->>ZDict: PyMutex_Unlock(&zd->lock)
deactivate ZDict
ZSD-->>C: result
deactivate ZSD
Sequence Diagram for ZstdDecompressor Decompression with LockingsequenceDiagram
participant C as Caller
participant ZSD as ZstdDecompressor
C->>ZSD: _zstd_ZstdDecompressor_decompress_impl(data, max_length)
activate ZSD
ZSD->>ZSD: PyMutex_Lock(&self->lock)
activate ZSD
ZSD->>ZSD: stream_decompress_lock_held(data, max_length)
activate ZSD
note right of ZSD: asserts self->lock is held
ZSD->>ZSD: decompress_lock_held(in_buffer, max_length)
opt Error or Completion
ZSD->>ZSD: decompressor_reset_session_lock_held()
note right of ZSD: asserts self->lock is held
end
deactivate ZSD
ZSD->>ZSD: PyMutex_Unlock(&self->lock)
deactivate ZSD
ZSD-->>C: decompressed_data
deactivate ZSD
Sequence Diagram for Accessing ZstdDecompressor.unused_data with LockingsequenceDiagram
participant C as Caller
participant ZSD as ZstdDecompressor
C->>ZSD: get unused_data
activate ZSD
ZSD->>ZSD: PyMutex_Lock(&self->lock)
activate ZSD
ZSD->>ZSD: Access internal state (self->eof, self->unused_data)
ZSD->>ZSD: PyMutex_Unlock(&self->lock)
deactivate ZSD
ZSD-->>C: unused_data_bytes
deactivate ZSD
Class Diagram for _zstd Module Structs with Added LocksclassDiagram
direction LR
class ZstdCompressor {
+PyMutex lock
+int compression_level
+PyObject* dict
+ZSTD_CCtx* cctx
+int use_multithread
}
class ZstdDecompressor {
+PyMutex lock
+PyObject* dict
+ZSTD_DCtx* dctx
+PyObject* unused_data
+int eof
}
class ZstdDict {
+PyMutex lock
+PyObject* dict_content
+uint32_t dict_id
+PyObject* c_dicts
+ZSTD_DDict* d_dict
}
Updated Class Diagram for asyncio.tools.CycleFoundExceptionclassDiagram
class Exception {
<<Python Base Class>>
}
class CycleFoundException {
+cycles: list~list~int~~
+id2name: dict~int, str~~
+__init__(self, cycles, id2name) None
}
CycleFoundException --|> Exception
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.1)
Can you help keep this open source service alive? 💖 Please sponsor : )
Summary by Sourcery
Introduce explicit PyMutex-based locking across the Zstd extension to replace critical section macros, refactor and unify dictionary loading logic, strengthen thread-safety through new concurrency tests, and apply related fixes in asyncio components.
New Features:
Bug Fixes:
Enhancements:
Documentation:
BaseSubprocessTransport.__del__
fails if the event loop is already closed, which can leak an orphan process python/cpython#114177 and Using a frozen attributes to Exception class python/cpython#134451.Tests: