Re: [Python-Dev] ctypes, memory mapped files and context manager

2017年01月05日 Thread eryk sun
On Thu, Jan 5, 2017 at 11:28 PM, Hans-Peter Jansen wrote:> Leaves the question, how stable this "interface" is?> Accessing _objects here belongs to voodoo programming practices of course, but> the magic is locally limited to just two lines of code, which is acceptable in> order to get this con

Re: [Python-Dev] Adding bytes.frombuffer() constructor to PEP 467

2017年01月05日 Thread Yury Selivanov
On 2017年01月05日 7:11 PM, INADA Naoki wrote: bytes.frombuffer(x) is bytes(memoryview(x)) or memoryview(x).tobytes(). There is pitfall: memoryview should be closed. So b = bytes.frombuffer(x) is: with memoryview(x) as m: b = bytes(m) # or b = m.tobytes() Thinking more about this, an

Re: [Python-Dev] Adding bytes.frombuffer() constructor to PEP 467

2017年01月05日 Thread INADA Naoki
>> bytes.frombuffer(x) is bytes(memoryview(x)) or memoryview(x).tobytes().> There is pitfall: memoryview should be closed. So b = bytes.frombuffer(x) is: with memoryview(x) as m: b = bytes(m) # or b = m.tobytes() ___ Python-Dev mailing list Py

Re: [Python-Dev] ctypes, memory mapped files and context manager

2017年01月05日 Thread Hans-Peter Jansen
On Freitag, 6. Januar 2017 00:28:37 Hans-Peter Jansen wrote:> Hi Eryk,> > This is exactly, what I was after:> > @contextmanager> def cstructmap(cstruct, mm, offset = 0):> # resize the mmap (and backing file), if structure exceeds mmap size> # mmap size must be aligned to mmap.PAGESI

Re: [Python-Dev] ctypes, memory mapped files and context manager

2017年01月05日 Thread Hans-Peter Jansen
Hi Eryk, On Donnerstag, 5. Januar 2017 15:30:33 eryk sun wrote:> >> manager introduce a layer of indirection:> I think that's the best you can do with the current state of ctypes.> > from_buffer was made safer in Python 3 by ensuring it keeps a> memoryview reference in the _objects attribut

Re: [Python-Dev] Adding bytes.frombuffer() constructor to PEP 467

2017年01月05日 Thread Serhiy Storchaka
On 05.01.17 22:37, Alexander Belopolsky wrote: I propose the following: 1. For 3.6, restore and document 3.5 behavior. Recommend that 3rd party types that are both integer-like and buffer-like implement their own __bytes__ method to resolve the bytes(x) ambiguity. The __bytes__ method is used

Re: [Python-Dev] Adding bytes.frombuffer() constructor to PEP 467

2017年01月05日 Thread Alexander Belopolsky
On Wed, Oct 12, 2016 at 12:08 AM, INADA Naoki wrote:>> Now I'm sure about bytes.frombuffer() is worth enough. I would like to revive this thread (taking a liberty to shorten the subject line.) The issue of how the bytes(x) constructor should behave when given objects of various types have come

Re: [Python-Dev] IRC logs via BotBot.me

2017年01月05日 Thread Milan Oberkirch
On 01/05/2017 11:04 AM, Berker Peksağ wrote:> On Thu, Jan 5, 2017 at 2:27 AM, INADA Naoki wrote:>> Hi.>>>> IRC #python-dev channel is nice place to know what happens recently.>> But I can't log in always because I use only laptop PC.>>>> I found BotBot.me seems nice IRC log service and used

Re: [Python-Dev] ctypes, memory mapped files and context manager

2017年01月05日 Thread eryk sun
On Thu, Jan 5, 2017 at 2:37 AM, Nick Coghlan wrote:> On 5 January 2017 at 10:28, Hans-Peter Jansen wrote:>> In order to get this working properly, the ctypes mapping needs a method to>> free the mapping actively. E.g.:>>>> @contextmanager>> def map_struct(m, n):>> m.resize(n * mmap.PAG

Re: [Python-Dev] ctypes, memory mapped files and context manager

2017年01月05日 Thread Hans-Peter Jansen
Hi Nick, On Donnerstag, 5. Januar 2017 12:37:20 Nick Coghlan wrote:> I don't know ctypes well enough myself to comment on the idea of> offering fully deterministic cleanup, but the closest you could get to> that without requiring a change to ctypes is to have the context> manager introduce a l

Re: [Python-Dev] SystemError: new style getargs format but argument is not a tuple

2017年01月05日 Thread Serhiy Storchaka
On 05.01.17 06:43, Terry Reedy wrote: On 1/1/2017 6:40 PM, Serhiy Storchaka wrote: On 02.01.17 01:23, Terry Reedy wrote: There are several recent question on Stackoverflow about SystemError: new style getargs format but argument is not a tuple [snip] Resulting from using 3rd party packages.