[Python-checkins] r80361 - in python/branches/py3k: Doc/whatsnew/3.2.rst Include/unicodeobject.h Lib/test/test_bytes.py Lib/test/test_os.py Misc/NEWS Modules/_posixsubprocess.c Modules/posixmodule.c Objects/unicodeobject.c

victor.stinner python-checkins at python.org
Thu Apr 22 14:08:36 CEST 2010


Author: victor.stinner
Date: Thu Apr 22 14:08:36 2010
New Revision: 80361

Log:
Issue #8485: PyUnicode_FSConverter() doesn't accept bytearray object anymore,
you have to convert your bytearray filenames to bytes


Modified:
   python/branches/py3k/Doc/whatsnew/3.2.rst
   python/branches/py3k/Include/unicodeobject.h
   python/branches/py3k/Lib/test/test_bytes.py
   python/branches/py3k/Lib/test/test_os.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Modules/_posixsubprocess.c
   python/branches/py3k/Modules/posixmodule.c
   python/branches/py3k/Objects/unicodeobject.c

Modified: python/branches/py3k/Doc/whatsnew/3.2.rst
==============================================================================
--- python/branches/py3k/Doc/whatsnew/3.2.rst	(original)
+++ python/branches/py3k/Doc/whatsnew/3.2.rst	Thu Apr 22 14:08:36 2010
@@ -151,4 +151,6 @@
 This section lists previously described changes and other bugfixes
 that may require changes to your code:
 
+* bytearray objects cannot be used anymore as filenames: convert them to bytes
+
 * Stub

Modified: python/branches/py3k/Include/unicodeobject.h
==============================================================================
--- python/branches/py3k/Include/unicodeobject.h	(original)
+++ python/branches/py3k/Include/unicodeobject.h	Thu Apr 22 14:08:36 2010
@@ -1238,8 +1238,8 @@
 /* --- File system encoding ---------------------------------------------- */
 
 /* ParseTuple converter which converts a Unicode object into the file
-   system encoding, using the PEP 383 error handler; bytes objects are
-   output as-is. */
+   system encoding as a bytes object, using the PEP 383 error handler; bytes
+   objects are output as-is. */
 
 PyAPI_FUNC(int) PyUnicode_FSConverter(PyObject*, void*);
 

Modified: python/branches/py3k/Lib/test/test_bytes.py
==============================================================================
--- python/branches/py3k/Lib/test/test_bytes.py	(original)
+++ python/branches/py3k/Lib/test/test_bytes.py	Thu Apr 22 14:08:36 2010
@@ -815,13 +815,6 @@
         self.assertRaises(BufferError, delslice)
         self.assertEquals(b, orig)
 
-    def test_empty_bytearray(self):
-        # Issue #7561: operations on empty bytearrays could crash in many
-        # situations, due to a fragile implementation of the
-        # PyByteArray_AS_STRING() C macro.
-        self.assertRaises(ValueError, int, bytearray(b''))
-        self.assertRaises((ValueError, OSError), os.mkdir, bytearray(b''))
-
 
 class AssortedBytesTest(unittest.TestCase):
     #

Modified: python/branches/py3k/Lib/test/test_os.py
==============================================================================
--- python/branches/py3k/Lib/test/test_os.py	(original)
+++ python/branches/py3k/Lib/test/test_os.py	Thu Apr 22 14:08:36 2010
@@ -607,14 +607,6 @@
     def test_execvpe_with_bad_arglist(self):
         self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
 
-class ArgTests(unittest.TestCase):
-    def test_bytearray(self):
-        # Issue #7561: posix module didn't release bytearray exports properly.
-        b = bytearray(os.sep.encode('ascii'))
-        self.assertRaises(OSError, os.mkdir, b)
-        # Check object is still resizable.
-        b[:] = b''
-
 class Win32ErrorTests(unittest.TestCase):
     def test_rename(self):
         self.assertRaises(WindowsError, os.rename, support.TESTFN, support.TESTFN+".bak")
@@ -872,7 +864,6 @@
 
 def test_main():
     support.run_unittest(
-        ArgTests,
         FileTests,
         StatAttributeTests,
         EnvironTests,

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Thu Apr 22 14:08:36 2010
@@ -12,6 +12,9 @@
 Core and Builtins
 -----------------
 
+- Issue #8485: PyUnicode_FSConverter() doesn't accept bytearray object anymore,
+  you have to convert your bytearray filenames to bytes
+
 - Issue #7332: Remove the 16KB stack-based buffer in
   PyMarshal_ReadLastObjectFromFile, which doesn't bring any noticeable
   benefit compared to the dynamic memory allocation fallback.  Patch by

Modified: python/branches/py3k/Modules/_posixsubprocess.c
==============================================================================
--- python/branches/py3k/Modules/_posixsubprocess.c	(original)
+++ python/branches/py3k/Modules/_posixsubprocess.c	Thu Apr 22 14:08:36 2010
@@ -271,10 +271,7 @@
     if (cwd_obj != Py_None) {
         if (PyUnicode_FSConverter(cwd_obj, &cwd_obj2) == 0)
             goto cleanup;
-        if (PyBytes_Check(cwd_obj2))
-            cwd = PyBytes_AS_STRING(cwd_obj2);
-        else
-            cwd = PyByteArray_AS_STRING(cwd_obj2);
+        cwd = PyBytes_AsString(cwd_obj2);
     } else {
         cwd = NULL;
         cwd_obj2 = NULL;

Modified: python/branches/py3k/Modules/posixmodule.c
==============================================================================
--- python/branches/py3k/Modules/posixmodule.c	(original)
+++ python/branches/py3k/Modules/posixmodule.c	Thu Apr 22 14:08:36 2010
@@ -536,38 +536,6 @@
 	return d;
 }
 
-/* Convert a bytes object to a char*. Optionally lock the buffer if it is a
-   bytes array. */
-
-static char*
-bytes2str(PyObject* o, int lock)
-{
-	if(PyBytes_Check(o))
-		return PyBytes_AsString(o);
-	else if(PyByteArray_Check(o)) {
-		if (lock && PyObject_GetBuffer(o, NULL, 0) < 0)
-			/* On a bytearray, this should not fail. */
-			PyErr_BadInternalCall();
-		return PyByteArray_AsString(o);
-	} else {
-		/* The FS converter should have verified that this
-		   is either bytes or bytearray. */
-		Py_FatalError("bad object passed to bytes2str");
-		/* not reached. */
-		return "";
-	}
-}
-
-/* Release the lock, decref the object. */
-static void
-release_bytes(PyObject* o)
-{
-	if (PyByteArray_Check(o))
-		o->ob_type->tp_as_buffer->bf_releasebuffer(o, 0);
-	Py_DECREF(o);
-}
-
-
 /* Set a POSIX-specific error from errno, and return NULL */
 
 static PyObject *
@@ -594,8 +562,8 @@
 posix_error_with_allocated_filename(PyObject* name)
 {
 	PyObject *rc = PyErr_SetFromErrnoWithFilename(PyExc_OSError, 
-						      bytes2str(name, 0));
-	release_bytes(name);
+						      PyBytes_AsString(name));
+	Py_DECREF(name);
 	return rc;
 }
 
@@ -751,13 +719,13 @@
 	if (!PyArg_ParseTuple(args, format,
 	                      PyUnicode_FSConverter, &opath1))
 		return NULL;
-	path1 = bytes2str(opath1, 1);
+	path1 = PyBytes_AsString(opath1);
 	Py_BEGIN_ALLOW_THREADS
 	res = (*func)(path1);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath1);
-	release_bytes(opath1);
+	Py_DECREF(opath1);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -775,13 +743,13 @@
 	                      PyUnicode_FSConverter, &opath2)) {
 		return NULL;
 	}
-	path1 = bytes2str(opath1, 1);
-	path2 = bytes2str(opath2, 1);
+	path1 = PyBytes_AsString(opath1);
+	path2 = PyBytes_AsString(opath2);
 	Py_BEGIN_ALLOW_THREADS
 	res = (*func)(path1, path2);
 	Py_END_ALLOW_THREADS
-	release_bytes(opath1);
-	release_bytes(opath2);
+	Py_DECREF(opath1);
+	Py_DECREF(opath2);
 	if (res != 0)
 		/* XXX how to report both path1 and path2??? */
 		return posix_error();
@@ -1530,7 +1498,7 @@
 	if (!PyArg_ParseTuple(args, format,
 	                      PyUnicode_FSConverter, &opath))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = (*statfunc)(path, &st);
 	Py_END_ALLOW_THREADS
@@ -1545,7 +1513,7 @@
 	else
 		result = _pystat_fromstructstat(&st);
 
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return result;
 }
 
@@ -1583,11 +1551,11 @@
 	if (!PyArg_ParseTuple(args, "O&i:access",
 			      PyUnicode_FSConverter, &opath, &mode))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	attr = GetFileAttributesA(path);
 	Py_END_ALLOW_THREADS
-	release_bytes(opath);
+	Py_DECREF(opath);
 finish:
 	if (attr == 0xFFFFFFFF)
 		/* File does not exist, or cannot read attributes */
@@ -1603,11 +1571,11 @@
 	if (!PyArg_ParseTuple(args, "O&i:access", 
 			      PyUnicode_FSConverter, &opath, &mode))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = access(path, mode);
 	Py_END_ALLOW_THREADS
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return PyBool_FromLong(res == 0);
 #endif
 }
@@ -1750,7 +1718,7 @@
 	if (!PyArg_ParseTuple(args, "O&i:chmod", PyUnicode_FSConverter,
 	                      &opath, &i))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	attr = GetFileAttributesA(path);
 	if (attr != 0xFFFFFFFF) {
@@ -1765,23 +1733,23 @@
 	Py_END_ALLOW_THREADS
 	if (!res) {
 		win32_error("chmod", path);
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 #else /* MS_WINDOWS */
 	if (!PyArg_ParseTuple(args, "O&i:chmod", PyUnicode_FSConverter,
 	                      &opath, &i))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = chmod(path, i);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 #endif
@@ -1824,13 +1792,13 @@
 	if (!PyArg_ParseTuple(args, "O&i:lchmod", PyUnicode_FSConverter,
 	                      &opath, &i))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = lchmod(path, i);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_RETURN_NONE;
 }
 #endif /* HAVE_LCHMOD */
@@ -1851,13 +1819,13 @@
 	if (!PyArg_ParseTuple(args, "O&k:chflags",
 			      PyUnicode_FSConverter, &opath, &flags))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = chflags(path, flags);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -1879,13 +1847,13 @@
 	if (!PyArg_ParseTuple(args, "O&k:lchflags",
 			      PyUnicode_FSConverter, &opath, &flags))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = lchflags(path, flags);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -1950,13 +1918,13 @@
 	                      PyUnicode_FSConverter, &opath,
 	                      &uid, &gid))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = chown(path, (uid_t) uid, (gid_t) gid);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -2002,13 +1970,13 @@
 	                      PyUnicode_FSConverter, &opath,
 	                      &uid, &gid))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	res = lchown(path, (uid_t) uid, (gid_t) gid);
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -2209,12 +2177,12 @@
 	if (!PyArg_ParseTuple(args, "O&:listdir",
 	                      PyUnicode_FSConverter, &opath))
 		return NULL;
-	if (PyObject_Size(opath)+1 > MAX_PATH) {
+	if (PyBytes_GET_SIZE(opath)+1 > MAX_PATH) {
 		PyErr_SetString(PyExc_ValueError, "path too long");
 		Py_DECREF(opath);
 		return NULL;
 	}
-	strcpy(namebuf, bytes2str(opath, 0));
+	strcpy(namebuf, PyBytes_AsString(opath));
 	len = PyObject_Size(opath);
 	if (len > 0) {
 		char ch = namebuf[len-1];
@@ -2290,10 +2258,10 @@
     if (!PyArg_ParseTuple(args, "O&:listdir", 
                           PyUnicode_FSConverter, &oname))
         return NULL;
-    name = bytes2str(oname);
-    len = PyObject_Size(oname);
+    name = PyBytes_AsString(oname);
+    len = PyBytes_GET_SIZE(oname);
     if (len >= MAX_PATH) {
-        release_bytes(oname);
+        Py_DECREF(oname);
         PyErr_SetString(PyExc_ValueError, "path too long");
         return NULL;
     }
@@ -2306,7 +2274,7 @@
     strcpy(namebuf + len, "*.*");
 
     if ((d = PyList_New(0)) == NULL) {
-        release_bytes(oname);
+        Py_DECREF(oname);
         return NULL;
     }
 
@@ -2349,7 +2317,7 @@
         } while (DosFindNext(hdir, &ep, sizeof(ep), &srchcnt) == NO_ERROR && srchcnt > 0);
     }
 
-    release_bytes(oname);
+    Py_DECREF(oname);
     return d;
 #else
 	PyObject *oname;
@@ -2366,13 +2334,13 @@
 	}
 	if (!PyArg_ParseTuple(args, "O&:listdir", PyUnicode_FSConverter, &oname))
 		return NULL;
-	name = bytes2str(oname, 1);
+	name = PyBytes_AsString(oname);
 	if ((dirp = opendir(name)) == NULL) {
 		return posix_error_with_allocated_filename(oname);
 	}
 	if ((d = PyList_New(0)) == NULL) {
 		closedir(dirp);
-		release_bytes(oname);
+		Py_DECREF(oname);
 		return NULL;
 	}
 	for (;;) {
@@ -2425,7 +2393,7 @@
 		Py_DECREF(v);
 	}
 	closedir(dirp);
-	release_bytes(oname);
+	Py_DECREF(oname);
 
 	return d;
 
@@ -2474,14 +2442,14 @@
 	if (!PyArg_ParseTuple (args, "O&:_getfullpathname",
 	                       PyUnicode_FSConverter, &opath))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (!GetFullPathName(path, sizeof(outbuf)/sizeof(outbuf[0]),
 	                     outbuf, &temp)) {
 		win32_error("GetFullPathName", path);
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
-	release_bytes(opath);
+	Py_DECREF(opath);
 	if (PyUnicode_Check(PyTuple_GetItem(args, 0))) {
 		return PyUnicode_Decode(outbuf, strlen(outbuf),
 			Py_FileSystemDefaultEncoding, NULL);
@@ -2521,7 +2489,7 @@
 	if (!PyArg_ParseTuple(args, "O&|i:mkdir",
 	                      PyUnicode_FSConverter, &opath, &mode))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 	/* PyUnicode_AS_UNICODE OK without thread lock as
 	   it is a simple dereference. */
@@ -2529,10 +2497,10 @@
 	Py_END_ALLOW_THREADS
 	if (!res) {
 		win32_error("mkdir", path);
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 #else
@@ -2540,7 +2508,7 @@
 	if (!PyArg_ParseTuple(args, "O&|i:mkdir",
 	                      PyUnicode_FSConverter, &opath, &mode))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	Py_BEGIN_ALLOW_THREADS
 #if ( defined(__WATCOMC__) || defined(PYCC_VACPP) ) && !defined(__QNX__)
 	res = mkdir(path);
@@ -2550,7 +2518,7 @@
 	Py_END_ALLOW_THREADS
 	if (res < 0)
 		return posix_error_with_allocated_filename(opath);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 #endif
@@ -2699,11 +2667,11 @@
 	                      PyUnicode_FSConverter, &command_obj))
 		return NULL;
 
-	command = bytes2str(command_obj, 1);
+	command = PyBytes_AsString(command_obj);
 	Py_BEGIN_ALLOW_THREADS
 	sts = system(command);
 	Py_END_ALLOW_THREADS
-	release_bytes(command_obj);
+	Py_DECREF(command_obj);
 #endif
 	return PyLong_FromLong(sts);
 }
@@ -2838,7 +2806,7 @@
 		if (!PyArg_ParseTuple(args, "O&O:utime",
 				PyUnicode_FSConverter, &oapath, &arg))
 			return NULL;
-		apath = bytes2str(oapath, 1);
+		apath = PyBytes_AsString(oapath);
 		Py_BEGIN_ALLOW_THREADS
 		hFile = CreateFileA(apath, FILE_WRITE_ATTRIBUTES, 0,
 				    NULL, OPEN_EXISTING,
@@ -2846,10 +2814,10 @@
 		Py_END_ALLOW_THREADS
 		if (hFile == INVALID_HANDLE_VALUE) {
 			win32_error("utime", apath);
-			release_bytes(oapath);
+			Py_DECREF(oapath);
 			return NULL;
 		}
-		release_bytes(oapath);
+		Py_DECREF(oapath);
 	}
 	
 	if (arg == Py_None) {
@@ -2917,7 +2885,7 @@
 	if (!PyArg_ParseTuple(args, "O&O:utime",
 				  PyUnicode_FSConverter, &opath, &arg))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (arg == Py_None) {
 		/* optional time values not given */
 		Py_BEGIN_ALLOW_THREADS
@@ -2927,18 +2895,18 @@
 	else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) {
 		PyErr_SetString(PyExc_TypeError,
 				"utime() arg 2 must be a tuple (atime, mtime)");
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
 	else {
 		if (extract_time(PyTuple_GET_ITEM(arg, 0),
 				 &atime, &ausec) == -1) {
-			release_bytes(opath);
+			Py_DECREF(opath);
 			return NULL;
 		}
 		if (extract_time(PyTuple_GET_ITEM(arg, 1),
 				 &mtime, &musec) == -1) {
-			release_bytes(opath);
+			Py_DECREF(opath);
 			return NULL;
 		}
 		ATIME = atime;
@@ -2958,7 +2926,7 @@
 	if (res < 0) {
 		return posix_error_with_allocated_filename(opath);
 	}
-	release_bytes(opath);
+	Py_DECREF(opath);
 	Py_INCREF(Py_None);
 	return Py_None;
 #undef UTIME_ARG
@@ -3001,12 +2969,11 @@
 	Py_ssize_t size;
 	if (!PyUnicode_FSConverter(o, &bytes))
 		return 0;
-	size = PyObject_Size(bytes);
+	size = PyBytes_GET_SIZE(bytes);
 	*out = PyMem_Malloc(size+1);
 	if (!*out)
 		return 0;
-	/* Don't lock bytes, as we hold the GIL */
-	memcpy(*out, bytes2str(bytes, 0), size+1);
+	memcpy(*out, PyBytes_AsString(bytes), size+1);
 	Py_DECREF(bytes);
 	return 1;
 }
@@ -3038,7 +3005,7 @@
                               PyUnicode_FSConverter,
                               &opath, &argv))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3049,18 +3016,18 @@
 	}
 	else {
 		PyErr_SetString(PyExc_TypeError, "execv() arg 2 must be a tuple or list");
-                release_bytes(opath);
+                Py_DECREF(opath);
 		return NULL;
 	}
 	if (argc < 1) {
 		PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty");
-                release_bytes(opath);
+                Py_DECREF(opath);
 		return NULL;
 	}
 
 	argvlist = PyMem_NEW(char *, argc+1);
 	if (argvlist == NULL) {
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return PyErr_NoMemory();
 	}
 	for (i = 0; i < argc; i++) {
@@ -3069,7 +3036,7 @@
 			free_string_array(argvlist, i);
 			PyErr_SetString(PyExc_TypeError,
 					"execv() arg 2 must contain only strings");
-			release_bytes(opath);
+			Py_DECREF(opath);
 			return NULL;
 
 		}
@@ -3081,7 +3048,7 @@
 	/* If we get here it's definitely an error */
 
 	free_string_array(argvlist, argc);
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return posix_error();
 }
 
@@ -3115,7 +3082,7 @@
 			      PyUnicode_FSConverter,
 			      &opath, &argv, &env))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3224,7 +3191,7 @@
 	Py_XDECREF(vals);
 	Py_XDECREF(keys);
   fail_0:
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return NULL;
 }
 #endif /* HAVE_EXECV */
@@ -3258,7 +3225,7 @@
 			      PyUnicode_FSConverter,
 			      &opath, &argv))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3270,13 +3237,13 @@
 	else {
 		PyErr_SetString(PyExc_TypeError,
 				"spawnv() arg 2 must be a tuple or list");
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
 
 	argvlist = PyMem_NEW(char *, argc+1);
 	if (argvlist == NULL) {
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return PyErr_NoMemory();
 	}
 	for (i = 0; i < argc; i++) {
@@ -3286,7 +3253,7 @@
 			PyErr_SetString(
 				PyExc_TypeError,
 				"spawnv() arg 2 must contain only strings");
-			release_bytes(opath);
+			Py_DECREF(opath);
 			return NULL;
 		}
 	}
@@ -3306,7 +3273,7 @@
 #endif
 
 	free_string_array(argvlist, argc);
-	release_bytes(opath);
+	Py_DECREF(opath);
 
 	if (spawnval == -1)
 		return posix_error();
@@ -3351,7 +3318,7 @@
 			      PyUnicode_FSConverter,
 			      &opath, &argv, &env))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3468,7 +3435,7 @@
 	Py_XDECREF(vals);
 	Py_XDECREF(keys);
   fail_0:
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return res;
 }
 
@@ -3501,7 +3468,7 @@
 			      PyUnicode_FSConverter,
 			      &opath, &argv))
 		return NULL;
-	path = bytes2str(opath);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3513,13 +3480,13 @@
 	else {
 		PyErr_SetString(PyExc_TypeError,
 				"spawnvp() arg 2 must be a tuple or list");
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
 
 	argvlist = PyMem_NEW(char *, argc+1);
 	if (argvlist == NULL) {
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return PyErr_NoMemory();
 	}
 	for (i = 0; i < argc; i++) {
@@ -3529,7 +3496,7 @@
 			PyErr_SetString(
 				PyExc_TypeError,
 				"spawnvp() arg 2 must contain only strings");
-			release_bytes(opath);
+			Py_DECREF(opath);
 			return NULL;
 		}
 	}
@@ -3544,7 +3511,7 @@
 	Py_END_ALLOW_THREADS
 
 	free_string_array(argvlist, argc);
-	release_bytes(opath);
+	Py_DECREF(opath);
 
 	if (spawnval == -1)
 		return posix_error();
@@ -3585,7 +3552,7 @@
 			      PyUnicode_FSConverter,
 			      &opath, &argv, &env))
 		return NULL;
-	path = bytes2str(opath);
+	path = PyBytes_AsString(opath);
 	if (PyList_Check(argv)) {
 		argc = PyList_Size(argv);
 		getitem = PyList_GetItem;
@@ -3693,7 +3660,7 @@
 	Py_XDECREF(vals);
 	Py_XDECREF(keys);
   fail_0:
-	release_bytes(opath);
+	Py_DECREF(opath);
 	return res;
 }
 #endif /* PYOS_OS2 */
@@ -4692,10 +4659,10 @@
 	if (!PyArg_ParseTuple(args, "O&:readlink", 
 				PyUnicode_FSConverter, &opath))
 		return NULL;
-	path = bytes2str(opath, 1);
+	path = PyBytes_AsString(opath);
 	v = PySequence_GetItem(args, 0);
 	if (v == NULL) {
-		release_bytes(opath);
+		Py_DECREF(opath);
 		return NULL;
 	}
 
@@ -4710,7 +4677,7 @@
 	if (n < 0)
 		return posix_error_with_allocated_filename(opath);
 
-	release_bytes(opath);
+	Py_DECREF(opath);
 	v = PyBytes_FromStringAndSize(buf, n);
 	if (arg_is_unicode) {
 		PyObject *w;
@@ -4955,13 +4922,13 @@
 	                      PyUnicode_FSConverter, &ofile,
 	                      &flag, &mode))
 		return NULL;
-	file = bytes2str(ofile, 1);
+	file = PyBytes_AsString(ofile);
 	Py_BEGIN_ALLOW_THREADS
 	fd = open(file, flag, mode);
 	Py_END_ALLOW_THREADS
 	if (fd < 0)
 		return posix_error_with_allocated_filename(ofile);
-	release_bytes(ofile);
+	Py_DECREF(ofile);
 	return PyLong_FromLong((long)fd);
 }
 
@@ -5423,8 +5390,8 @@
 			      PyUnicode_FSConverter, &os1, 
 			      PyUnicode_FSConverter, &os2))
 		return NULL;
-	s1 = bytes2str(os1, 1);
-	s2 = bytes2str(os2, 1);
+	s1 = PyBytes_AsString(os1);
+	s2 = PyBytes_AsString(os2);
 #endif
 
 #if defined(PYOS_OS2)
@@ -5468,8 +5435,8 @@
 	PyOS_snprintf(newenv, len, "%s=%s", s1, s2);
 	if (putenv(newenv)) {
                 Py_DECREF(newstr);
-		release_bytes(os1);
-		release_bytes(os2);
+		Py_DECREF(os1);
+		Py_DECREF(os2);
                 posix_error();
                 return NULL;
 	}
@@ -5491,8 +5458,8 @@
     }
 #endif
 #ifndef MS_WINDOWS
-	release_bytes(os1);
-	release_bytes(os2);
+	Py_DECREF(os1);
+	Py_DECREF(os2);
 #endif
 	Py_INCREF(Py_None);
         return Py_None;
@@ -6865,17 +6832,17 @@
 			      PyUnicode_FSConverter, &ofilepath, 
 			      &operation))
 		return NULL;
-	filepath = bytes2str(ofilepath, 1);
+	filepath = PyBytes_AsString(ofilepath);
 	Py_BEGIN_ALLOW_THREADS
 	rc = ShellExecute((HWND)0, operation, filepath, 
 			  NULL, NULL, SW_SHOWNORMAL);
 	Py_END_ALLOW_THREADS
 	if (rc <= (HINSTANCE)32) {
 		PyObject *errval = win32_error("startfile", filepath);
-		release_bytes(ofilepath);
+		Py_DECREF(ofilepath);
 		return errval;
 	}
-	release_bytes(ofilepath);
+	Py_DECREF(ofilepath);
 	Py_INCREF(Py_None);
 	return Py_None;
 }

Modified: python/branches/py3k/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k/Objects/unicodeobject.c	(original)
+++ python/branches/py3k/Objects/unicodeobject.c	Thu Apr 22 14:08:36 2010
@@ -1624,7 +1624,7 @@
         Py_DECREF(*(PyObject**)addr);
         return 1;
     }
-    if (PyBytes_Check(arg) || PyByteArray_Check(arg)) {
+    if (PyBytes_Check(arg)) {
         output = arg;
         Py_INCREF(output);
     }


More information about the Python-checkins mailing list