\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#91: Backward Compatibility for Channel Types with 32-bit SeekProcs}
\date{May 03, 2002}
\author{Donal K. Fellows}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#91}&\textbf{Backward Compatibility for Channel Types with 32-bit SeekProcs}\\\hline
Author&

Donal K. Fellows \tipmail{fellowsd}{cs.man.ac.uk}
\\
Created&Friday, \(\text{3}^{\text{rd}}\) May 2002\\
Type&Project\\
Tcl Version&\(8.4\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.5 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

\cite{tip72} broke backward-compatibility for channels that supported the [seek] command, and this TIP adds the ability for old-style channels to work with the underlying 64-bit architecture.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Although the ability to work with large files (as added by \cite{tip72}) is crucially useful in many situations, it has introduced a few problems, one of which being that it broke backward compatibility for channel types (see \url{http://sourceforge.net/tracker/?func=detail&atid=410295&aid=551677&group_id=34191} for details.) Following discussion with the people concerned, I believe it is possible to modify the channel type structure so that old-style channels --- i.e. those compiled against Tcl 8.3 --- can still be supported (though with a limited range of operation.)

\section{Proposed Change}

The \textit{Tcl\_ChannelType} structure will have an extra field appended of type \textit{Tcl\_DriverWideSeekProc} called \textit{wideSeekProc}, which shall be guaranteed to be present (though possibly NULL) whenever the version of the \textit{Tcl\_ChannelType} structure is at least \textit{TCL\_CHANNEL\_VERSION\_3}. The type \textit{Tcl\_DriverSeekProc} shall be reverted to its pre-\cite{tip72} version, with the current type of \textit{Tcl\_DriverSeekProc} being transferred to the type \textit{Tcl\_DriverWideSeekProc}. In order to facilitate stacked channels, an additional requirement shall be imposed that if a channel driver implements a \textit{wideSeekProc}, then it shall also implement a \textit{seekProc}, so allowing stacked channels to work entirely in one domain or the other (well, in simple cases at least.)

Semantically, the core will handle seeks by preferring to use a \textit{wideSeekProc} if present, and using the \textit{seekProc} otherwise. Considering just the case where the \textit{seekProc} is used, if the offset argument exceeds that which is representable in a \textit{long}, \textit{Tcl\_Seek} will fail, simulating a system error of EOVERFLOW.

The only Tcl core channel which will need modification is the \textit{file} channel; this will be adapted to generate an error of EOVERFLOW when the resulting offset in a file would otherwise exceed that which can be expressed in a \textit{long} (which has the downside of making the seek operation no longer atomic when using the old interface, since the file offset will need to be restored to its old position in such cases.) On 64-bit platforms, both \textit{seekProc} and \textit{wideSeekProc} will be the same function.

\section{Rejected Alternatives}

I considered overloading the \textit{seekProc} field to have different types depending on the value of the \textit{version} field, but that's remarkably ugly and forces people to adapt rapidly at a source level. I don't know about everyone else, but I don't use a lot of programs at the moment that actually need access to files larger than 2GB.

I also considered allowing code to only implement the \textit{wideSeekProc} but it was easier to code the way I ended up doing it and I don't think there are that many people writing channel drivers that support seeking anway.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\begin{thebibliography}{TIP \#1}
\addcontentsline{toc}{section}{References}
\bibitem[TIP \#72]{tip72}
Donal K. Fellows,
\emph{64-Bit Value Support for Tcl on 32-Bit Platforms},
on-line at \url{http://purl.org/tcl/tip/72.html}
\end{thebibliography}
\end{document}
