Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1fe8cbc2
Commit
1fe8cbc2
authored
Sep 04, 2003
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #788249: Pass an explicit buffer to setvbuf in PyFile_SetBufSize().
Fixes #603724. Will backport to 2.3.
parent
379d78ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
Include/fileobject.h
Include/fileobject.h
+1
-0
Objects/fileobject.c
Objects/fileobject.c
+19
-5
No files found.
Include/fileobject.h
View file @
1fe8cbc2
...
...
@@ -19,6 +19,7 @@ typedef struct {
char
*
f_buf
;
/* Allocated readahead buffer */
char
*
f_bufend
;
/* Points after last occupied position */
char
*
f_bufptr
;
/* Current buffer position */
char
*
f_setbuf
;
/* Buffer for setbuf(3) and setvbuf(3) */
#ifdef WITH_UNIVERSAL_NEWLINES
int
f_univ_newline
;
/* Handle any newline convention */
int
f_newlinetypes
;
/* Types of newlines seen */
...
...
Objects/fileobject.c
View file @
1fe8cbc2
...
...
@@ -283,25 +283,37 @@ PyFile_FromString(char *name, char *mode)
void
PyFile_SetBufSize
(
PyObject
*
f
,
int
bufsize
)
{
PyFileObject
*
file
=
(
PyFileObject
*
)
f
;
if
(
bufsize
>=
0
)
{
#ifdef HAVE_SETVBUF
int
type
;
switch
(
bufsize
)
{
case
0
:
type
=
_IONBF
;
break
;
#ifdef HAVE_SETVBUF
case
1
:
type
=
_IOLBF
;
bufsize
=
BUFSIZ
;
break
;
#endif
default:
type
=
_IOFBF
;
#ifndef HAVE_SETVBUF
bufsize
=
BUFSIZ
;
#endif
break
;
}
fflush
(
file
->
f_fp
);
if
(
type
==
_IONBF
)
{
PyMem_Free
(
file
->
f_setbuf
);
file
->
f_setbuf
=
NULL
;
}
else
{
file
->
f_setbuf
=
PyMem_Realloc
(
file
->
f_setbuf
,
bufsize
);
}
setvbuf
(((
PyFileObject
*
)
f
)
->
f_fp
,
(
char
*
)
NULL
,
type
,
bufsize
);
#ifdef HAVE_SETVBUF
setvbuf
(
file
->
f_fp
,
file
->
f_setbuf
,
type
,
bufsize
);
#else
/* !HAVE_SETVBUF */
if
(
bufsize
<=
1
)
setbuf
(((
PyFileObject
*
)
f
)
->
f_fp
,
(
char
*
)
NULL
);
setbuf
(
file
->
f_fp
,
file
->
f_setbuf
);
#endif
/* !HAVE_SETVBUF */
}
}
...
...
@@ -376,6 +388,7 @@ static PyObject *
file_close
(
PyFileObject
*
f
)
{
int
sts
=
0
;
PyMem_Free
(
f
->
f_setbuf
);
if
(
f
->
f_fp
!=
NULL
)
{
if
(
f
->
f_close
!=
NULL
)
{
Py_BEGIN_ALLOW_THREADS
...
...
@@ -1928,6 +1941,7 @@ file_init(PyObject *self, PyObject *args, PyObject *kwds)
}
if
(
open_the_file
(
foself
,
name
,
mode
)
==
NULL
)
goto
Error
;
foself
->
f_setbuf
=
NULL
;
PyFile_SetBufSize
(
self
,
bufsize
);
goto
Done
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment