Skip to content

Commit 91d4aea

Browse files
committed
nit
1 parent d354eba commit 91d4aea

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

Modules/mmapmodule.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,14 +1131,29 @@ 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-
char buf[80] = {0, };
11351134
const char* prefix = "cpython:mmap:";
11361135
if (strlen(name) + strlen(prefix) > 80) {
1137-
PyErr_SetString(PyExc_ValueError, "name too long");
1136+
PyErr_SetString(PyExc_ValueError, "name is too long");
11381137
return NULL;
11391138
}
1140-
sprintf(buf, "%s%s", prefix, name);
1141-
_PyAnnotateMemoryMap(self->data, self->size, buf);
1139+
#ifdef MAP_ANONYMOUS
1140+
if (self->flags & MAP_ANONYMOUS) {
1141+
char buf[80] = {0, };
1142+
sprintf(buf, "%s%s", prefix, name);
1143+
_PyAnnotateMemoryMap(self->data, self->size, buf);
1144+
}
1145+
else {
1146+
/* cannot name non-anonymous mappings */
1147+
PyErr_SetString(PyExc_ValueError,
1148+
"Cannot set annotation on non-anonymous mappings");
1149+
return NULL;
1150+
}
1151+
#else
1152+
/* naming not supported on this platform */
1153+
PyErr_SetString(PyExc_ValueError,
1154+
"Annotation of mmap is not supported on this platform");
1155+
return NULL;
1156+
#endif
11421157
Py_RETURN_NONE;
11431158
}
11441159

@@ -1978,7 +1993,11 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
19781993
PyErr_SetFromErrno(PyExc_OSError);
19791994
return NULL;
19801995
}
1981-
_PyAnnotateMemoryMap(m_obj->data, map_size, "cpython:mmap");
1996+
#ifdef MAP_ANONYMOUS
1997+
if (m_obj->flags & MAP_ANONYMOUS) {
1998+
_PyAnnotateMemoryMap(m_obj->data, map_size, "cpython:mmap");
1999+
}
2000+
#endif
19822001
m_obj->access = (access_mode)access;
19832002
return (PyObject *)m_obj;
19842003
}

0 commit comments

Comments
 (0)