[Python-checkins] r80325 - in python/trunk: Misc/ACKS Misc/NEWS Python/marshal.c

antoine.pitrou python-checkins at python.org
Thu Apr 22 00:53:29 CEST 2010


Author: antoine.pitrou
Date: Thu Apr 22 00:53:29 2010
New Revision: 80325

Log:
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
Charles-François Natali.



Modified:
   python/trunk/Misc/ACKS
   python/trunk/Misc/NEWS
   python/trunk/Python/marshal.c

Modified: python/trunk/Misc/ACKS
==============================================================================
--- python/trunk/Misc/ACKS	(original)
+++ python/trunk/Misc/ACKS	Thu Apr 22 00:53:29 2010
@@ -536,6 +536,7 @@
 John Nagle
 Takahiro Nakayama
 Travers Naran
+Charles-François Natali
 Fredrik Nehr
 Trent Nelson
 Tony Nelson

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Thu Apr 22 00:53:29 2010
@@ -12,6 +12,11 @@
 Core and Builtins
 -----------------
 
+- 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
+  Charles-François Natali.
+
 - Issue #8417: Raise an OverflowError when an integer larger than sys.maxsize is
   passed to bytearray.
 

Modified: python/trunk/Python/marshal.c
==============================================================================
--- python/trunk/Python/marshal.c	(original)
+++ python/trunk/Python/marshal.c	Thu Apr 22 00:53:29 2010
@@ -1126,23 +1126,13 @@
 PyObject *
 PyMarshal_ReadLastObjectFromFile(FILE *fp)
 {
-/* 75% of 2.1's .pyc files can exploit SMALL_FILE_LIMIT.
- * REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc.
- */
-#define SMALL_FILE_LIMIT (1L << 14)
+/* REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc. */
 #define REASONABLE_FILE_LIMIT (1L << 18)
 #ifdef HAVE_FSTAT
 	off_t filesize;
-#endif
-#ifdef HAVE_FSTAT
 	filesize = getfilesize(fp);
-	if (filesize > 0) {
-		char buf[SMALL_FILE_LIMIT];
-		char* pBuf = NULL;
-		if (filesize <= SMALL_FILE_LIMIT)
-			pBuf = buf;
-		else if (filesize <= REASONABLE_FILE_LIMIT)
-			pBuf = (char *)PyMem_MALLOC(filesize);
+	if (filesize > 0 && filesize <= REASONABLE_FILE_LIMIT) {
+		char* pBuf = (char *)PyMem_MALLOC(filesize);
 		if (pBuf != NULL) {
 			PyObject* v;
 			size_t n;
@@ -1150,8 +1140,7 @@
 			   is smaller than REASONABLE_FILE_LIMIT */
 			n = fread(pBuf, 1, (int)filesize, fp);
 			v = PyMarshal_ReadObjectFromString(pBuf, n);
-			if (pBuf != buf)
-				PyMem_FREE(pBuf);
+			PyMem_FREE(pBuf);
 			return v;
 		}
 
@@ -1162,7 +1151,6 @@
 	 */
 	return PyMarshal_ReadObjectFromFile(fp);
 
-#undef SMALL_FILE_LIMIT
 #undef REASONABLE_FILE_LIMIT
 }
 


More information about the Python-checkins mailing list