]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #7332: Remove the 16KB stack-based buffer in
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 21 Apr 2010 22:53:29 +0000 (22:53 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 21 Apr 2010 22:53:29 +0000 (22:53 +0000)
PyMarshal_ReadLastObjectFromFile, which doesn't bring any noticeable
benefit compared to the dynamic memory allocation fallback.  Patch by
Charles-François Natali.

Misc/ACKS
Misc/NEWS
Python/marshal.c

index 9eeb9bb206eb472f72e4ba8ba7679c593d0bd081..cd74072b1ad4eb35b14696f378920f8ac0be1904 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -536,6 +536,7 @@ Piotr Meyer
 John Nagle
 Takahiro Nakayama
 Travers Naran
+Charles-François Natali
 Fredrik Nehr
 Trent Nelson
 Tony Nelson
index d956c9317366124b8f79071fa7de82f92cf761dd..329b053fe6b0ca26c77c1d7423dfc7a0a51e55b3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,11 @@ What's New in Python 2.7 beta 2?
 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.
 
index 9e4a6926a5580202e0bf9cccbe23a2d2955078f6..14f71346c86b167173c31c9b4c858068cfa7ab80 100644 (file)
@@ -1126,23 +1126,13 @@ getfilesize(FILE *fp)
 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 @@ PyMarshal_ReadLastObjectFromFile(FILE *fp)
                           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 @@ PyMarshal_ReadLastObjectFromFile(FILE *fp)
         */
        return PyMarshal_ReadObjectFromFile(fp);
 
-#undef SMALL_FILE_LIMIT
 #undef REASONABLE_FILE_LIMIT
 }