Skip to content

Commit bd02cc5

Browse files
committed
Address code review
1 parent cc3cf8a commit bd02cc5

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Lib/test/test_mmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ def test_flush_parameters(self):
11651165
m.flush(PAGESIZE)
11661166
m.flush(PAGESIZE, PAGESIZE)
11671167

1168-
@unittest.skipUnless(hasattr(mmap, 'MAP_ANONYMOUS'), 'requires MAP_ANONYMOUS')
1168+
@unittest.skipUnless(hasattr(mmap, 'MAP_ANONYMOUS') and sys.platform == "linux", 'requires MAP_ANONYMOUS and should be linux')
11691169
def test_set_name(self):
11701170
# Test setting name on anonymous mmap
11711171
m = mmap.mmap(-1, PAGESIZE)

Modules/mmapmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,14 +1131,14 @@ static PyObject *
11311131
mmap_mmap_set_name_impl(mmap_object *self, const char *name)
11321132
/*[clinic end generated code: output=1edaf4fd51277760 input=6c7dd91cad205f07]*/
11331133
{
1134-
const char* prefix = "cpython:mmap:";
1134+
#if defined(MAP_ANONYMOUS) && defined(__linux__)
1135+
const char *prefix = "cpython:mmap:";
11351136
if (strlen(name) + strlen(prefix) > 80) {
11361137
PyErr_SetString(PyExc_ValueError, "name is too long");
11371138
return NULL;
11381139
}
1139-
#ifdef MAP_ANONYMOUS
11401140
if (self->flags & MAP_ANONYMOUS) {
1141-
char buf[80] = {0, };
1141+
char buf[81] = {0, };
11421142
sprintf(buf, "%s%s", prefix, name);
11431143
_PyAnnotateMemoryMap(self->data, self->size, buf);
11441144
}
@@ -1150,7 +1150,7 @@ mmap_mmap_set_name_impl(mmap_object *self, const char *name)
11501150
}
11511151
#else
11521152
/* naming not supported on this platform */
1153-
PyErr_SetString(PyExc_ValueError,
1153+
PyErr_SetString(NotImplementedError,
11541154
"Annotation of mmap is not supported on this platform");
11551155
return NULL;
11561156
#endif

0 commit comments

Comments
 (0)