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

Skip to content

Commit 5bc7ec9

Browse files
committed
Merged revisions 80325 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r80325 | antoine.pitrou | 2010-04-22 00:53:29 +0200 (jeu., 22 avril 2010) | 6 lines 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. ........
1 parent 5ae6810 commit 5bc7ec9

3 files changed

Lines changed: 10 additions & 16 deletions

File tree

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ Piotr Meyer
540540
John Nagle
541541
Takahiro Nakayama
542542
Travers Naran
543+
Charles-François Natali
543544
Fredrik Nehr
544545
Trent Nelson
545546
Tony Nelson

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ What's New in Python 3.2 Alpha 1?
1212
Core 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

Python/marshal.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,32 +1078,21 @@ getfilesize(FILE *fp)
10781078
PyObject *
10791079
PyMarshal_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

0 commit comments

Comments
 (0)