Re: Addition to fileobject

Guido.van.Rossum@cwi.nl
Wed, 16 Mar 1994 00:49:18 +0100

> I've added a nobuf extension to the fileobject to stop buffering of
> data. Saves having to do flush all the time :-).

Right, this is indeed needed...

> I didn't do a diff, as I wasn't sure where in fileobject.c it should
> go (I just threw it in somewhere).

So do I, usually...

> This is the extra line for the methodlist struct:
>
> {"nobuf", (method)file_nobuf},

> And here is the extra function - it seems to work without any
> problems but I am a python NEWBIE so use with care :-)
>
> static object *
> file_nobuf(f, args)
> fileobject *f;
> object *args;
> {
> if (!getnoarg(args))
> return NULL;
> if (f->f_fp != NULL) {
> if (f->f_close != NULL) {
^^^^^^^^^^^^^^^^^^^^^^^This test seems unnecessary.
It makes your code stop working for file object variants without an
explicit close function. (Bet you copied it from file_close :-).

> BGN_SAVE
> errno = 0;
> setbuf(f->f_fp, NULL);
> END_SAVE
> }
> }
> INCREF(None);
> return None;
> }

Otherwise it looks fine to me. (Could there be a problem that stdio
does not want you to call setbuf when you've already done I/O?)

> Any chance of getting this into the OFFICIAL version (assuming it works
> properly).

I'd opt for an interface to setvbuf (without the silly magic
constants). Something like these options is needed:

- no buffering
- line buffering
- buffer of given size

This could be done with a single integer parameter if we use a
special value (e.g. -1) to mean line buffering.

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>