File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -540,6 +540,7 @@ Piotr Meyer
540540John Nagle
541541Takahiro Nakayama
542542Travers Naran
543+ Charles-François Natali
543544Fredrik Nehr
544545Trent Nelson
545546Tony Nelson
Original file line number Diff line number Diff line change @@ -12,6 +12,11 @@ What's New in Python 3.2 Alpha 1?
1212Core and Builtins
1313-----------------
1414
15+ - Issue #7332: Remove the 16KB stack-based buffer in
16+ PyMarshal_ReadLastObjectFromFile, which doesn't bring any noticeable
17+ benefit compared to the dynamic memory allocation fallback. Patch by
18+ Charles-François Natali.
19+
1520- Issue #8417: Raise an OverflowError when an integer larger than sys.maxsize is
1621 passed to bytes or bytearray.
1722
Original file line number Diff line number Diff line change @@ -1078,32 +1078,21 @@ getfilesize(FILE *fp)
10781078PyObject *
10791079PyMarshal_ReadLastObjectFromFile (FILE * fp )
10801080{
1081- /* 75% of 2.1's .pyc files can exploit SMALL_FILE_LIMIT.
1082- * REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc.
1083- */
1084- #define SMALL_FILE_LIMIT (1L << 14)
1081+ /* REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc. */
10851082#define REASONABLE_FILE_LIMIT (1L << 18)
10861083#ifdef HAVE_FSTAT
10871084 off_t filesize ;
1088- #endif
1089- #ifdef HAVE_FSTAT
10901085 filesize = getfilesize (fp );
1091- if (filesize > 0 ) {
1092- char buf [SMALL_FILE_LIMIT ];
1093- char * pBuf = NULL ;
1094- if (filesize <= SMALL_FILE_LIMIT )
1095- pBuf = buf ;
1096- else if (filesize <= REASONABLE_FILE_LIMIT )
1097- pBuf = (char * )PyMem_MALLOC (filesize );
1086+ if (filesize > 0 && filesize <= REASONABLE_FILE_LIMIT ) {
1087+ char * pBuf = (char * )PyMem_MALLOC (filesize );
10981088 if (pBuf != NULL ) {
10991089 PyObject * v ;
11001090 size_t n ;
11011091 /* filesize must fit into an int, because it
11021092 is smaller than REASONABLE_FILE_LIMIT */
11031093 n = fread (pBuf , 1 , (int )filesize , fp );
11041094 v = PyMarshal_ReadObjectFromString (pBuf , n );
1105- if (pBuf != buf )
1106- PyMem_FREE (pBuf );
1095+ PyMem_FREE (pBuf );
11071096 return v ;
11081097 }
11091098
@@ -1114,7 +1103,6 @@ PyMarshal_ReadLastObjectFromFile(FILE *fp)
11141103 */
11151104 return PyMarshal_ReadObjectFromFile (fp );
11161105
1117- #undef SMALL_FILE_LIMIT
11181106#undef REASONABLE_FILE_LIMIT
11191107}
11201108
You can’t perform that action at this time.
0 commit comments