File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22
33from test import support
4+ import array
45import marshal
56import sys
67import unittest
@@ -137,6 +138,27 @@ def test_sets(self):
137138 for constructor in (set , frozenset ):
138139 self .helper (constructor (self .d .keys ()))
139140
141+
142+ class BufferTestCase (unittest .TestCase , HelperMixin ):
143+
144+ def test_bytearray (self ):
145+ b = bytearray (b"abc" )
146+ self .helper (b )
147+ new = marshal .loads (marshal .dumps (b ))
148+ self .assertEqual (type (new ), bytes )
149+
150+ def test_memoryview (self ):
151+ b = memoryview (b"abc" )
152+ self .helper (b )
153+ new = marshal .loads (marshal .dumps (b ))
154+ self .assertEqual (type (new ), bytes )
155+
156+ def test_array (self ):
157+ a = array .array ('B' , b"abc" )
158+ new = marshal .loads (marshal .dumps (a ))
159+ self .assertEqual (new , b"abc" )
160+
161+
140162class BugsTestCase (unittest .TestCase ):
141163 def test_bug_5888452 (self ):
142164 # Simple-minded check for SF 588452: Debug build crashes
@@ -243,6 +265,7 @@ def test_main():
243265 CodeTestCase ,
244266 ContainerTestCase ,
245267 ExceptionTestCase ,
268+ BufferTestCase ,
246269 BugsTestCase )
247270
248271if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ What's New in Python 3.2.3 release candidate 1?
1010Core and Builtins
1111-----------------
1212
13+ - Issue #14172: Fix reference leak when marshalling a buffer-like object
14+ (other than a bytes object).
15+
1316- Issue #13521: dict.setdefault() now does only one lookup for the given key,
1417 making it "atomic" for many purposes. Patch by Filip Gruszczyński.
1518
Original file line number Diff line number Diff line change @@ -411,11 +411,12 @@ w_object(PyObject *v, WFILE *p)
411411 else if (PyObject_CheckBuffer (v )) {
412412 /* Write unknown buffer-style objects as a string */
413413 char * s ;
414- PyBufferProcs * pb = v -> ob_type -> tp_as_buffer ;
415414 Py_buffer view ;
416- if (( * pb -> bf_getbuffer ) (v , & view , PyBUF_SIMPLE ) != 0 ) {
415+ if (PyObject_GetBuffer (v , & view , PyBUF_SIMPLE ) != 0 ) {
417416 w_byte (TYPE_UNKNOWN , p );
417+ p -> depth -- ;
418418 p -> error = WFERR_UNMARSHALLABLE ;
419+ return ;
419420 }
420421 w_byte (TYPE_STRING , p );
421422 n = view .len ;
@@ -427,8 +428,7 @@ w_object(PyObject *v, WFILE *p)
427428 }
428429 w_long ((long )n , p );
429430 w_string (s , (int )n , p );
430- if (pb -> bf_releasebuffer != NULL )
431- (* pb -> bf_releasebuffer )(v , & view );
431+ PyBuffer_Release (& view );
432432 }
433433 else {
434434 w_byte (TYPE_UNKNOWN , p );
You can’t perform that action at this time.
0 commit comments