Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-132983: Minor fixes and clean up for the _zstd module#134930

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
serhiy-storchaka wants to merge7 commits intopython:main
base:main
Choose a base branch
Loading
fromserhiy-storchaka:zstd-fixes

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedMay 30, 2025
edited by bedevere-appbot
Loading

Copy link
Member

@emmatypingemmatyping left a comment

Choose a reason for hiding this comment

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

One question and one concern, but the rest looks good! Thank you for the improvements :)

ret = PyDict_SetItem(self->c_dicts, level, capsule);
/* Add PyCapsule object to self->c_dicts if it is not already present. */
PyObject *result;
ret = PyDict_SetDefaultRef(self->c_dicts, level, capsule, &result);
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiousity, isPyDict_SetDefaultRef the "correct" way to set items in a dictionary for new code?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

The GIL is released after checking that there is no entry for level in self->c_dicts. After it acquired again, it may happen that a new entry has already been added. In that case we should use already added capsule object.

Copy link
Member

@emmatypingemmatypingMay 31, 2025
edited
Loading

Choose a reason for hiding this comment

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

self is guarded by a lock, so no other object can modify it while it is locked. We don't use critical sections so I believe we don't unlock when the GIL is released. (Similarly this is true below)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Well, then I'll remove this change.

Although I wonder if it's possible to get rid of the lock here and if it would be of any use.

Copy link
Member

@emmatypingemmatypingMay 31, 2025
edited
Loading

Choose a reason for hiding this comment

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

Yes, I think it might be possible to remove the lock. The dict_buffer/len are immutable, so the only concern would likely be actually setting the c_dicts member. Perhaps this can be investigated in a follow up?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

For now, I removed these changes. We can investigate later if there is a benefit of removing the lock for these calls.

emmatyping reacted with thumbs up emoji
Comment on lines 69 to 71
if (self->d_dict!= NULL) {
ZSTD_freeDDict(ret);
}
Copy link
Member

Choose a reason for hiding this comment

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

This check doesn't look quite right. We're already in a block whereself->d_dict == NULL.

Copy link
MemberAuthor

@serhiy-storchakaserhiy-storchakaMay 30, 2025
edited
Loading

Choose a reason for hiding this comment

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

This is the same case as above, but simpler. After the GIL was released and acquired, we cannot already assume that self->d_dict == NULL.

Copy link
Member

Choose a reason for hiding this comment

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

Similar to the above, perhaps this could be addressed in a follow-up? (or if you'd like to tackle removing locking from ZstdDict here I suppose that's fine)

Comment on lines -510 to -515
if (!PyType_Check(c_parameter_type) || !PyType_Check(d_parameter_type)) {
PyErr_SetString(PyExc_ValueError,
"The two arguments should be CompressionParameter and "
"DecompressionParameter types.");
return NULL;
}
Copy link
Member

Choose a reason for hiding this comment

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

Sanity check on removing the type checks here?

Copy link
Member

Choose a reason for hiding this comment

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

The type checks are already handled by argument clinic, so these are actually redundant.

serhiy-storchaka reacted with thumbs up emoji
Copy link
Member

@emmatypingemmatyping left a comment

Choose a reason for hiding this comment

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

The changes look good! One minor wording suggestion but great otherwise. Thank you!


/* Wrong type */
PyErr_SetString(PyExc_TypeError,
"zstd_dict argument should be ZstdDict object.");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"zstd_dict argument should be ZstdDict object.");
"zstd_dict argument should beaZstdDict object.");

Comment on lines +22 to +23
ZstdDict*
_Py_parse_zstd_dict(const_zstd_state*state,PyObject*dict,int*ptype)
Copy link
Member

Choose a reason for hiding this comment

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

This is a great refactor, thank you!

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

@AA-TurnerAA-TurnerAA-Turner left review comments

@emmatypingemmatypingemmatyping approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@serhiy-storchaka@AA-Turner@emmatyping

[8]ページ先頭

©2009-2025 Movatter.jp