Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#2648 remove stdio.h from tcl.h ?

obsolete: 8.5a2
closed-rejected
Don Porter
None
5
2004-06-04
2004-03-31
Don Porter
No

Lines 141-143 of tcl.h:

#ifndef BUFSIZ
# include <stdio.h>
#endif

I have to assume that getting
BUFSIZ defined is not the point,
as that never gets used within
tcl.h. Within all of Tcl's C code
BUFSIZ only shows up in
unix/tclLoadAix.c and that file
unconditionally #include-s
stdio.h for itself.

So, I take it that the #ifndef
BUFSIZ test is just in place to
prevent a double #include of
stdio.h, perhaps on some strange
system somewhere with a botched
stdio.h that's not safe to #include
more than once?

Anyhow, the main point seems to
be to get at the declarations of
stdio.h. But why? Nothing else
in tcl.h has need of those declarations.
Several things throughout Tcl need
stdio.h, but they get it already, either by
a #include of tclInt.h -- which #include's
stdio.h unconditionally -- or by just #include-ing
stdio.h for themselves.

Is it for the benefit of packages that
#include "tcl.h" ? That seems bizarre.
If a package needs stdio.h, it's logical
for it to #include it for itself. If not, then
Tcl is forcing it into the picture where it's
not needed.

Seems these 3 lines could just be removed
with no loss, and arguable gain.

Discussion

  • Logged In: YES
    user_id=79902

    I think we can probably remove the BUFSIZ test from there,
    but I worry that much existing extension code assumes that
    stdio.h was implied by tcl.h, so perhaps the #include can't
    go until 9.0?

     
  • Joe English
    Joe English
    2004-03-31

    Logged In: YES
    user_id=68433

    Agree 100% with dgp's assessment: this can go.

    It looks like it hasn't been needed since Tcl 7.6 when the
    channel system was added. (Prior to that there were public
    routines that took FILE *s.)

    As for extensions that need stdio.h but don't bother
    including it because they've already included tcl.h: they
    can fix themselves.

    Tcl has never guaranteed absolute source-level compatibility
    for extensions at minor releases. This is an easy fix for
    extension authors, and adding #include <stdio.h> won't
    introduce a retro-incompatibility with pre-8.5 headers. It
    can go.

     
  • tauvan
    tauvan
    2004-04-05

    Logged In: YES
    user_id=1011552

    Suggestion:
    It looks like that stdio was not a compatiblity issue and
    was needed by most files, so delete the three lines, add
    #include <stdio.h> at the very top of "tcl.h".
    Almost every file includes "tclInit.h" which includes "tcl.h"
    and 13 files reference it plus it's the first thing in "tclInit.h".

     
  • Joe English
    Joe English
    2004-04-25

    Logged In: YES
    user_id=68433

    Existing extension code that assumes <tcl.h> includes
    <stdio.h> can easily be updated to include <stdio.h>
    themselves. We don't guarantee 100% source-level
    compatibility across minor revision numbers.

     
  • Don Porter
    Don Porter
    2004-04-25

    • assigned_to: jenglish --> dgp
    • status: open --> closed-fixed
     
  • Don Porter
    Don Porter
    2004-04-25

    Logged In: YES
    user_id=80530

    fixed in HEAD.

     
  • Don Porter
    Don Porter
    2004-04-30

    • assigned_to: dgp --> jenglish
    • status: closed-fixed --> open-remind
     
  • Don Porter
    Don Porter
    2004-04-30

    Logged In: YES
    user_id=80530

    OK, I found a reason not to do this.
    Not a good reason, mind you, but a reason.

    A program that wants to call Tcl_Seek()
    or Tcl_FSSeek() will #include <tcl.h> to
    get their declarations.

    In order to call them, though, it's best to pass
    them the values SEEK_SET, SEEK_CUR,
    or SEEK_END. Those values are
    #define'd in <stdio.h>.

    Probably would be better if Tcl defined its
    own values for passing to its own routines,
    but as things are, it appears tcl.h ought to
    include stdio.h after all.

     
  • tauvan
    tauvan
    2004-04-30

    Logged In: YES
    user_id=1011552

    Here's a strange question. In tclUnixPort.h it includes tclInt.h which
    includes stdio.h. In tclUnixPort.h the following:
    #ifndef SEEK_SET
    # define SEEK_SET 0
    #endif
    #ifndef SEEK_CUR
    # define SEEK_CUR 1
    #endif
    #ifndef SEEK_END
    # define SEEK_END 2
    #endif
    Was or is there a time when SEEK_SET, SEEK_CUR, SEEK_END not
    defined or differently defined?

     
  • tauvan
    tauvan
    2004-04-30

    Logged In: YES
    user_id=1011552

    Yes, there is mine is in unistd.h!

     
  • tauvan
    tauvan
    2004-04-30

    Logged In: YES
    user_id=1011552

    Sorry, more specifically, it is #define'd in <sys/unistd.h>, but
    the same #ifndef... as in tclUnixPort.h, is in <stdio.h>.

     
  • Don Porter
    Don Porter
    2004-06-04

    Logged In: YES
    user_id=80530

    stdio.h restored to tcl.h for the
    sake of the SEEK_* #define's
    and for the sake of many
    extensions that have come to
    depend on it being there.

     
  • Don Porter
    Don Porter
    2004-06-04

    • assigned_to: jenglish --> dgp
    • status: open-remind --> closed-rejected