@@ -109,7 +109,7 @@ typedef struct {
109
109
#ifdef MS_WINDOWS
110
110
HANDLE map_handle ;
111
111
HANDLE file_handle ;
112
- char * tagname ;
112
+ wchar_t * tagname ;
113
113
#endif
114
114
115
115
#ifdef UNIX
@@ -539,7 +539,7 @@ mmap_resize_method(mmap_object *self,
539
539
CloseHandle (self -> map_handle );
540
540
/* if the file mapping still exists, it cannot be resized. */
541
541
if (self -> tagname ) {
542
- self -> map_handle = OpenFileMapping (FILE_MAP_WRITE , FALSE,
542
+ self -> map_handle = OpenFileMappingW (FILE_MAP_WRITE , FALSE,
543
543
self -> tagname );
544
544
if (self -> map_handle ) {
545
545
PyErr_SetFromWindowsErr (ERROR_USER_MAPPED_FILE );
@@ -568,7 +568,7 @@ mmap_resize_method(mmap_object *self,
568
568
569
569
/* create a new file mapping and map a new view */
570
570
/* FIXME: call CreateFileMappingW with wchar_t tagname */
571
- self -> map_handle = CreateFileMapping (
571
+ self -> map_handle = CreateFileMappingW (
572
572
self -> file_handle ,
573
573
NULL ,
574
574
PAGE_READWRITE ,
@@ -843,12 +843,11 @@ mmap__repr__method(PyObject *self)
843
843
static PyObject *
844
844
mmap__sizeof__method (mmap_object * self , void * unused )
845
845
{
846
- Py_ssize_t res ;
847
-
848
- res = _PyObject_SIZE (Py_TYPE (self ));
849
- if (self -> tagname )
850
- res += strlen (self -> tagname ) + 1 ;
851
- return PyLong_FromSsize_t (res );
846
+ size_t res = _PyObject_SIZE (Py_TYPE (self ));
847
+ if (self -> tagname ) {
848
+ res += (wcslen (self -> tagname ) + 1 ) * sizeof (self -> tagname [0 ]);
849
+ }
850
+ return PyLong_FromSize_t (res );
852
851
}
853
852
#endif
854
853
@@ -1400,7 +1399,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
1400
1399
DWORD off_lo ; /* lower 32 bits of offset */
1401
1400
DWORD size_hi ; /* upper 32 bits of size */
1402
1401
DWORD size_lo ; /* lower 32 bits of size */
1403
- const char * tagname = "" ;
1402
+ PyObject * tagname = Py_None ;
1404
1403
DWORD dwErr = 0 ;
1405
1404
int fileno ;
1406
1405
HANDLE fh = 0 ;
@@ -1410,7 +1409,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
1410
1409
"tagname" ,
1411
1410
"access" , "offset" , NULL };
1412
1411
1413
- if (!PyArg_ParseTupleAndKeywords (args , kwdict , "in|ziL " , keywords ,
1412
+ if (!PyArg_ParseTupleAndKeywords (args , kwdict , "in|OiL " , keywords ,
1414
1413
& fileno , & map_size ,
1415
1414
& tagname , & access , & offset )) {
1416
1415
return NULL ;
@@ -1543,17 +1542,19 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
1543
1542
m_obj -> weakreflist = NULL ;
1544
1543
m_obj -> exports = 0 ;
1545
1544
/* set the tag name */
1546
- if (tagname != NULL && * tagname != '\0' ) {
1547
- m_obj -> tagname = PyMem_Malloc (strlen (tagname )+ 1 );
1545
+ if (!Py_IsNone (tagname )) {
1546
+ if (!PyUnicode_Check (tagname )) {
1547
+ Py_DECREF (m_obj );
1548
+ return PyErr_Format (PyExc_TypeError , "expected str or None for "
1549
+ "'tagname', not %.200s" ,
1550
+ Py_TYPE (tagname )-> tp_name );
1551
+ }
1552
+ m_obj -> tagname = PyUnicode_AsWideCharString (tagname , NULL );
1548
1553
if (m_obj -> tagname == NULL ) {
1549
- PyErr_NoMemory ();
1550
1554
Py_DECREF (m_obj );
1551
1555
return NULL ;
1552
1556
}
1553
- strcpy (m_obj -> tagname , tagname );
1554
1557
}
1555
- else
1556
- m_obj -> tagname = NULL ;
1557
1558
1558
1559
m_obj -> access = (access_mode )access ;
1559
1560
size_hi = (DWORD )(size >> 32 );
@@ -1562,12 +1563,12 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
1562
1563
off_lo = (DWORD )(offset & 0xFFFFFFFF );
1563
1564
/* For files, it would be sufficient to pass 0 as size.
1564
1565
For anonymous maps, we have to pass the size explicitly. */
1565
- m_obj -> map_handle = CreateFileMapping (m_obj -> file_handle ,
1566
- NULL ,
1567
- flProtect ,
1568
- size_hi ,
1569
- size_lo ,
1570
- m_obj -> tagname );
1566
+ m_obj -> map_handle = CreateFileMappingW (m_obj -> file_handle ,
1567
+ NULL ,
1568
+ flProtect ,
1569
+ size_hi ,
1570
+ size_lo ,
1571
+ m_obj -> tagname );
1571
1572
if (m_obj -> map_handle != NULL ) {
1572
1573
m_obj -> data = (char * ) MapViewOfFile (m_obj -> map_handle ,
1573
1574
dwDesiredAccess ,
0 commit comments