Message223522
This version is tidied up enough that I think it could be reviewed.
Changes are:
* Defer `buf' allocation until __init__, rather than __new__ as was previously done. Now upon completion, BytesIO.__new__ returns a valid, closed BytesIO, whereas previously a valid, empty, open BytesIO was returned. Is this interface change permissible?
* Move __init__ guts into a "reinit()", for sharing with __setstate__, which also previously caused an unnecessary copy. Additionally gather up various methods for deallocating buffers into a single "reset()" function, called by reinit(), _dealloc(), and _close()
* Per Stefan's suggested approach, reinit() now explicitly checks for a read-only buffer, falling back to silently performing a copy if the returned buffer is read-write. That seems vastly preferable to throwing an exception, which would probably be another interface change.
* Call `unshare()` any place the buffer is about to be modified. If the buffer needs to be made private, it also accepts a size hint indicating how much less/more space the subsequent operation needs, to avoid a redundant reallocation after the unsharing.
Outstanding issues:
* I don't understand why buf_size is a size_t, and I'm certain the casting in unshare() is incorrect somehow. Is it simply to avoid signed overflow? |
|
Date |
User |
Action |
Args |
2014-07-20 16:50:34 | dw | set | recipients:
+ dw, pitrou, scoder, benjamin.peterson, stutzbach, hynek, serhiy.storchaka, kmike |
2014-07-20 16:50:34 | dw | set | messageid: <1405875034.32.0.75145330564.issue22003@psf.upfronthosting.co.za> |
2014-07-20 16:50:34 | dw | link | issue22003 messages |
2014-07-20 16:50:34 | dw | create | |
|