[issue40915] multiple problems with mmap.resize() in Windows

2021-12-18 Thread Steve Dower


Steve Dower  added the comment:


New changeset 6214caafbe66e34e84c1809abf0b7aab6791956b by neonene in branch 
'main':
bpo-40915: Avoid compiler warnings by fixing mmapmodule conversion from 
LARGE_INTEGER to Py_ssize_t (GH-30175)
https://github.com/python/cpython/commit/6214caafbe66e34e84c1809abf0b7aab6791956b


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40915] multiple problems with mmap.resize() in Windows

2021-12-17 Thread neonene


Change by neonene :


--
nosy: +neonene
nosy_count: 6.0 -> 7.0
pull_requests: +28391
pull_request: https://github.com/python/cpython/pull/30175

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40915] multiple problems with mmap.resize() in Windows

2021-10-26 Thread Tim Golden


Change by Tim Golden :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40915] multiple problems with mmap.resize() in Windows

2021-10-26 Thread Tim Golden


Tim Golden  added the comment:


New changeset aea5ecc458084e01534ea6a11f4181f369869082 by Tim Golden in branch 
'main':
bpo-40915: Fix mmap resize bugs on Windows (GH-29213)
https://github.com/python/cpython/commit/aea5ecc458084e01534ea6a11f4181f369869082


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40915] multiple problems with mmap.resize() in Windows

2021-10-25 Thread Tim Golden


Change by Tim Golden :


--
keywords: +patch
pull_requests: +27477
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/29213

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40915] multiple problems with mmap.resize() in Windows

2021-10-23 Thread Tim Golden


Change by Tim Golden :


--
assignee:  -> tim.golden

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40915] multiple problems with mmap.resize() in Windows

2020-09-18 Thread Dong-hee Na


Change by Dong-hee Na :


--
nosy: +corona10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40915] multiple problems with mmap.resize() in Windows

2020-06-09 Thread Eryk Sun


Eryk Sun  added the comment:

For a concrete example, here's a rewrite of the Windows implementation that 
incorporates the suggested changes.

#include 

#ifdef MS_WINDOWS
/* a named file mapping that's open more than once can't be resized */
/* this check could be moved into is_resizeable */
if (self->tagname) {
typedef NTSTATUS NTAPI ntqo_f(HANDLE, OBJECT_INFORMATION_CLASS,
PVOID, ULONG, PULONG);
ntqo_f *pNtQueryObject = (ntqo_f *)GetProcAddress(
GetModuleHandleW(L"ntdll"), "NtQueryObject");
if (pNtQueryObject) {
PUBLIC_OBJECT_BASIC_INFORMATION info;
NTSTATUS status = pNtQueryObject(self->map_handle,
ObjectBasicInformation, , sizeof(info), NULL);
if (NT_SUCCESS(status) && info.HandleCount > 1) {
PyErr_SetFromWindowsErr(ERROR_USER_MAPPED_FILE);
return NULL;
}
}
}
DWORD error = 0;
char *old_data = self->data;
LARGE_INTEGER offset, max_size;
offset.QuadPart = self->offset;
max_size.QuadPart = new_size;
/* close the file mapping */
CloseHandle(self->map_handle);
self->map_handle = NULL;
/* if it's not the paging file, unmap the view and resize the file */
if (self->file_handle != INVALID_HANDLE_VALUE) {
UnmapViewOfFile(self->data);
self->data = NULL;
/* resize the file */
if (!SetFilePointerEx(self->file_handle, max_size, NULL,
 FILE_BEGIN) ||
!SetEndOfFile(self->file_handle)) {
/* resizing failed. try to remap the file */
error = GetLastError();
new_size = max_size.QuadPart = self->size;
}
}
/* create a new file mapping and map a new view */
/* FIXME: call CreateFileMappingW with wchar_t tagname */
self->map_handle = CreateFileMapping(self->file_handle, NULL,
PAGE_READWRITE, max_size.HighPart, max_size.LowPart,
self->tagname);
if (self->map_handle != NULL &&
  GetLastError() != ERROR_ALREADY_EXISTS) {
self->data = MapViewOfFile(self->map_handle, FILE_MAP_WRITE,
offset.HighPart, offset.LowPart, new_size);
if (self->data != NULL) {
/* copy the old view if using the paging file */
if (self->file_handle == INVALID_HANDLE_VALUE) {
memcpy(self->data, old_data,
self->size < new_size ? self->size : new_size);
}
self->size = new_size;
} else {
error = GetLastError();
CloseHandle(self->map_handle);
self->map_handle = NULL;
}
} else {
error = GetLastError();
}
/* unmap the old view if using the paging file */
if (self->file_handle == INVALID_HANDLE_VALUE) {
UnmapViewOfFile(old_data);
}
if (error) {
PyErr_SetFromWindowsErr(error);
return NULL;
}
Py_RETURN_NONE;
#endif /* MS_WINDOWS */

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40915] multiple problems with mmap.resize() in Windows

2020-06-09 Thread Eryk Sun


Change by Eryk Sun :


--
Removed message: https://bugs.python.org/msg371153

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40915] multiple problems with mmap.resize() in Windows

2020-06-09 Thread Eryk Sun


Eryk Sun  added the comment:

For a concrete example, here's a rewrite of the Windows implementation that 
incorporates the suggested changes. 

#include 

#ifdef MS_WINDOWS
/* a named file mapping that's open more than once can't be resized */
/* this check could be moved into is_resizeable */
if (self->tagname) {
typedef NTSTATUS NTAPI ntqo_f(HANDLE, OBJECT_INFORMATION_CLASS,
PVOID, ULONG, PULONG);
ntqo_f *pNtQueryObject = (ntqo_f *)GetProcAddress(
GetModuleHandleW(L"ntdll"), "NtQueryObject");
if (pNtQueryObject) {
PUBLIC_OBJECT_BASIC_INFORMATION info;
NTSTATUS status = pNtQueryObject(self->map_handle,
ObjectBasicInformation, , sizeof(info), NULL);
if (NT_SUCCESS(status) && info.HandleCount > 1) {
PyErr_SetFromWindowsErr(ERROR_USER_MAPPED_FILE);
return NULL;
}
}
}
DWORD error = 0;
char *old_data = self->data;
LARGE_INTEGER offset;
offset.QuadPart = self->offset;
/* close the file mapping */
CloseHandle(self->map_handle);
self->map_handle = NULL;
/* if it's not the paging file, unmap the view and resize the file */
if (self->file_handle != INVALID_HANDLE_VALUE) {
UnmapViewOfFile(self->data);
self->data = NULL;
/* resize the file */
if (!SetFilePointerEx(self->file_handle, offset, NULL,
 FILE_BEGIN) ||
!SetEndOfFile(self->file_handle)) {
/* resizing failed. try to remap the file */
error = GetLastError();
new_size = self->size;
}
}
/* create a new file mapping and map a new view */
LARGE_INTEGER max_size;
max_size.QuadPart = new_size;
/* FIXME: call CreateFileMappingW with wchar_t tagname */
self->map_handle = CreateFileMapping(self->file_handle, NULL,
PAGE_READWRITE, max_size.HighPart, max_size.LowPart,
self->tagname);
if (self->map_handle != NULL &&
  GetLastError() != ERROR_ALREADY_EXISTS) {
self->data = MapViewOfFile(self->map_handle, FILE_MAP_WRITE,
offset.HighPart, offset.LowPart, new_size);
if (self->data != NULL) {
/* copy the old view if using the paging file */
if (self->file_handle == INVALID_HANDLE_VALUE) {
memcpy(self->data, old_data,
self->size < new_size ? self->size : new_size);
}
self->size = new_size;
} else {
error = GetLastError();
CloseHandle(self->map_handle);
self->map_handle = NULL;
}
} else {
error = GetLastError();
}
/* unmap the old view if using the paging file */
if (self->file_handle == INVALID_HANDLE_VALUE) {
UnmapViewOfFile(old_data);
}
if (error) {
PyErr_SetFromWindowsErr(error);
return NULL;
}
Py_RETURN_NONE;
#endif /* MS_WINDOWS */

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40915] multiple problems with mmap.resize() in Windows

2020-06-08 Thread Eryk Sun


Change by Eryk Sun :


--
title: muultiple problems with mmap.resize()  in Windows -> multiple problems 
with mmap.resize()  in Windows

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com