Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dcb2403

Browse files
author
Victor Stinner
committed
Issue #8485: PyUnicode_FSConverter() doesn't accept bytearray object anymore,
you have to convert your bytearray filenames to bytes
1 parent c303c12 commit dcb2403

File tree

8 files changed

+104
-151
lines changed

8 files changed

+104
-151
lines changed

Doc/whatsnew/3.2.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,6 @@ Porting to Python 3.2
151151
This section lists previously described changes and other bugfixes
152152
that may require changes to your code:
153153

154+
* bytearray objects cannot be used anymore as filenames: convert them to bytes
155+
154156
* Stub

Include/unicodeobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,8 +1238,8 @@ PyAPI_FUNC(int) PyUnicode_EncodeDecimal(
12381238
/* --- File system encoding ---------------------------------------------- */
12391239

12401240
/* ParseTuple converter which converts a Unicode object into the file
1241-
system encoding, using the PEP 383 error handler; bytes objects are
1242-
output as-is. */
1241+
system encoding as a bytes object, using the PEP 383 error handler; bytes
1242+
objects are output as-is. */
12431243

12441244
PyAPI_FUNC(int) PyUnicode_FSConverter(PyObject*, void*);
12451245

Lib/test/test_bytes.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,6 @@ def delslice():
815815
self.assertRaises(BufferError, delslice)
816816
self.assertEquals(b, orig)
817817

818-
def test_empty_bytearray(self):
819-
# Issue #7561: operations on empty bytearrays could crash in many
820-
# situations, due to a fragile implementation of the
821-
# PyByteArray_AS_STRING() C macro.
822-
self.assertRaises(ValueError, int, bytearray(b''))
823-
self.assertRaises((ValueError, OSError), os.mkdir, bytearray(b''))
824-
825818

826819
class AssortedBytesTest(unittest.TestCase):
827820
#

Lib/test/test_os.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,6 @@ def test_execvpe_with_bad_program(self):
607607
def test_execvpe_with_bad_arglist(self):
608608
self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
609609

610-
class ArgTests(unittest.TestCase):
611-
def test_bytearray(self):
612-
# Issue #7561: posix module didn't release bytearray exports properly.
613-
b = bytearray(os.sep.encode('ascii'))
614-
self.assertRaises(OSError, os.mkdir, b)
615-
# Check object is still resizable.
616-
b[:] = b''
617-
618610
class Win32ErrorTests(unittest.TestCase):
619611
def test_rename(self):
620612
self.assertRaises(WindowsError, os.rename, support.TESTFN, support.TESTFN+".bak")
@@ -872,7 +864,6 @@ def test_CTRL_BREAK_EVENT(self):
872864

873865
def test_main():
874866
support.run_unittest(
875-
ArgTests,
876867
FileTests,
877868
StatAttributeTests,
878869
EnvironTests,

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 3.2 Alpha 1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #8485: PyUnicode_FSConverter() doesn't accept bytearray object anymore,
16+
you have to convert your bytearray filenames to bytes
17+
1518
- Issue #7332: Remove the 16KB stack-based buffer in
1619
PyMarshal_ReadLastObjectFromFile, which doesn't bring any noticeable
1720
benefit compared to the dynamic memory allocation fallback. Patch by

Modules/_posixsubprocess.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,7 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
271271
if (cwd_obj != Py_None) {
272272
if (PyUnicode_FSConverter(cwd_obj, &cwd_obj2) == 0)
273273
goto cleanup;
274-
if (PyBytes_Check(cwd_obj2))
275-
cwd = PyBytes_AS_STRING(cwd_obj2);
276-
else
277-
cwd = PyByteArray_AS_STRING(cwd_obj2);
274+
cwd = PyBytes_AsString(cwd_obj2);
278275
} else {
279276
cwd = NULL;
280277
cwd_obj2 = NULL;

0 commit comments

Comments
 (0)