8000 bpo-46398: posixshmem module shm_rename freebsd support. by devnexen · Pull Request #30621 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-46398: posixshmem module shm_rename freebsd support. #30621

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

devnexen
Copy link
Contributor
@devnexen devnexen commented Jan 16, 2022

@devnexen devnexen changed the title posixshmem module shm_rename freebsd support. bpo-46398: posixshmem module shm_rename freebsd support. Jan 16, 2022
@devnexen devnexen force-pushed the shm_rename branch 5 times, most recently from 36de652 to 4bec161 Compare January 17, 2022 12:49
@devnexen devnexen marked this pull request as ready for review January 17, 2022 20:10
@devnexen devnexen requested a review from tiran as a code owner January 17, 2022 20:10
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Feb 17, 2022
@MaxwellDupre

This comment was marked as outdated.


Rename a shared memory object.

Remove a shared memory object and relink to another path
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
Remove a shared memory object and relink to another path
Remove a shared memory object and relink to another path.

_posixshmem.shm_rename
path_from: unicode
path_to: unicode
flags: int
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
flags: int
flags: int
/

I think it was mistake to make parameters keyword-or-positional in other functions. It is better to make them positional-only, it will help if we decide to rename parameters.

With the SHM_RENAME_NOREPLACE flag, an error will be returned
if the new name exists.
"""
if platform.system() != "FreeBSD":
Copy link
Member

Choose a reason for hiding this comment

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

It is better to use hasattr(). If in future shm_rename() be added on other platforms, it will automatically add support of SharedMemory.rename().

Comment on lines 90 to 101
const char *from = PyUnicode_AsUTF8(path_from);
const char *to = PyUnicode_AsUTF8(path_to);
if (from == NULL || to == NULL) {
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.

This function has the same bug as shm_open() and shm_unlink() (see #115886). Please check the names for embedded null characters.

if newname:
newname = "/" + newname if self._prepend_leading_slash else newname
r = _posixshmem.shm_rename(self._name, newname, flags)
if r == None:
Copy link
Member

Choose a reason for hiding this comment

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

It is always true, isn't?

if platform.system() != "FreeBSD":
raise OSError("Unsupported operation on this platform")

if newname:
Copy link
Member

Choose a reason for hiding this comment

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

So it simply returns False if newname is empty and returns True otherwise? Why add such check in this method?

With the SHM_RENAME_NOREPLACE flag, an error will be returned
if the new name exists.
"""
if !platform.hasattr("shm_rename"):
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
if !platform.hasattr("shm_rename"):
if not platform.hasattr("shm_rename"):

Copy link
Member

Choose a reason for hiding this comment

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

What is this platform.hasattr() function? Where does it come from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review OS-freebsd stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0