Skip to content

Conversation

@corona10
Copy link
Member

@corona10 corona10 commented Dec 9, 2025

@corona10 corona10 requested a review from encukou December 10, 2025 00:09
}
#else
/* naming not supported on this platform */
PyErr_SetString(PyExc_ValueError,
Copy link
Member

Choose a reason for hiding this comment

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

In ssl.c we usually raise a NotImplementedError in such cases. If you always want to raise the same error, I suggest that you document this ValueError.

result = m.set_name(long_name)
self.assertIsNone(result)

# Test name too long
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test with NUL bytes inside it?

mmap_mmap_set_name_impl(mmap_object *self, const char *name)
/*[clinic end generated code: output=1edaf4fd51277760 input=6c7dd91cad205f07]*/
{
const char* prefix = "cpython:mmap:";
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
const char* prefix = "cpython:mmap:";
const char *prefix = "cpython:mmap:";

Alternatively you can use a macro and in the printf have MACRO "%s" as a format string instead. Same idea as usages of PRI* macros

corona10 and others added 4 commits December 11, 2025 02:41
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@corona10
Copy link
Member Author

@picnixz @vstinner PTAL :)

@corona10 corona10 requested a review from picnixz December 11, 2025 01:23
"Annotation of mmap is not supported on this platform");
return NULL;
#endif
Py_RETURN_NONE;
Copy link
Member

Choose a reason for hiding this comment

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

You can move this one in the ifdef block.

Co-authored-by: Victor Stinner <vstinner@python.org>
@corona10 corona10 requested review from picnixz and vstinner December 11, 2025 19:29

.. method:: set_name(name, /)

Annotate the memory map with the given *name* for easier identification
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
Annotate the memory map with the given *name* for easier identification
Annotate the memory mapping with the given *name* for easier identification

to Python or if Python is built in :ref:`debug mode <debug-build>`
The length of *name* must not exceed 67 bytes.

.. availability:: Linux >= 5.17
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
.. availability:: Linux >= 5.17
.. availability:: Linux >= 5.17 (kernel built with `CONFIG_ANON_VMA_NAME` option)

(Contributed by Serhiy Storchaka in :gh:`78502`.)

* Added the :meth:`mmap.mmap.set_name` method
to annotate an anonymous memory map
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
to annotate an anonymous memory map
to annotate an anonymous memory mapping

self.assertIsNone(result)

# Test name too long
too_long_name = 'x' * 80
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
too_long_name = 'x' * 80
too_long_name = 'x' * 68

return NULL;
}
if (self->flags & MAP_ANONYMOUS) {
char buf[81] = {0, };
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that it's useful to initialize the buffer since we are directly writing into it.

Suggested change
char buf[81] = {0, };
char buf[81];

/*[clinic end generated code: output=1edaf4fd51277760 input=6c7dd91cad205f07]*/
{
#if defined(MAP_ANONYMOUS) && defined(__linux__)
const char *prefix = "cpython:mmap:";
Copy link
Member

Choose a reason for hiding this comment

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

Is it really needed to include mmap: in the name? Why not just:

Suggested change
const char *prefix = "cpython:mmap:";
const char *prefix = "cpython:";

Copy link
Member

Choose a reason for hiding this comment

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

An alternative is to even omit the prefix, and just the name to name.


# Test name length limit (80 chars including prefix "cpython:mmap:")
# Prefix is 13 chars, so max name is 67 chars
long_name = 'x' * 30
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to test the longest valid name here:

Suggested change
long_name = 'x' * 30
long_name = 'x' * 67

And check for overflow below (68 characters).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants