\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#392: Allow Bignums to be Disabled at Runtime on a Per-Interp Basis}
\date{October 30, 2011}
\author{Joe Mistachkin}
\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 \#392}&\textbf{Allow Bignums to be Disabled at Runtime on a Per-Interp Basis}\\\hline
Author&

Joe Mistachkin \tipmail{joe}{mistachkin.com}
\\
Created&Sunday, \(\text{30}^{\text{th}}\) October 2011\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Draft\\
Vote&Pending\\
Version&\tipversion$Revision: 1.1 $\\
Keywords&bignum, runaway, safe, math, precision, integer, tcl\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes the ability to enable or disable all use of bignums at runtime on a per-interpreter basis. The mechanism being presented to accomplish this goal has been designed to be generic enough so that it can be used for other per-interpreter configuration parameters in the future.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

As of Tcl version 8.5, almost any integer math calculation can result in bignums being used. Normally, this does not pose a serious problem; however, there are circumstances in which this can exhaust key system resources, such as memory or CPU time. Unlike other similar resource exhaustion problems, this one cannot be prevented by use of \textbf{interp create -safe}, \textbf{interp limit}, \textbf{interp cancel}, or similar mechanisms. If Tcl is being used in an embedding scenario, this has the potential to negatively impact the entire application or system. If Tcl is being used to evaluate marginally trusted or untrusted scripts in a safe interpreter, this can result in a denial-of-service (DoS) attack.

\section{Specification}

A new \textbf{interp configure} script command will be added, as follows:

\begin{quote}
\textbf{interp configure} \textit{path} ?\textit{name}? ?\textit{value}?
\end{quote}

This command instructs Tcl to modify or query the value of the named configuration parameter \textit{name} in the interpreter identified by \textit{path}.

\subsection{Arguments}

\begin{quote}
\textit{path}
\end{quote}

This argument is required and specifies the interpreter to be reconfigured. An empty string may be used to indicate the current interpreter.

\begin{quote}
\textit{name}
\end{quote}

This argument is optional. If this argument is not supplied, the current list of configuration parameter names for the interpreter identified by \textit{path} will be returned.

\begin{quote}
\textit{value}
\end{quote}

This argument is optional. If this argument is not supplied, the current value of the named configuration parameter for the interpreter identified by \textit{path} will be returned; otherwise, the current value of the configuration parameter will be changed to the specified value.

\subsection{C API}

\begin{quote}
Tcl\_Obj* \textbf{Tcl\_InterpConfigure}(Tcl\_Interp* \textit{interp}, Tcl\_Obj* \textit{nameObjPtr}, Tcl\_Obj* \textit{valueObjPtr})
\end{quote}

The \textbf{Tcl\_InterpConfigure} function gets or sets the named configuration parameter for the specified interpreter. The \textit{nameObjPtr}, if not NULL, must be a string containing the name of a known configuration parameter; otherwise, NULL will be returned and the interpreter result will be modified to contain an appropriate error message. The \textit{valueObjPtr}, if not NULL, must have a value convertible to the type required by the configuration parameter being set; otherwise, NULL will be returned and the interpreter result will be modified to contain an appropriate error message. If \textit{valueObjPtr} is NULL, the current value of the named configuration parameter will be returned instead of being changed. If \textit{nameObjPtr} is NULL, the complete list of known configuration parameter names will be returned. The caller is responsible for managing the reference count of the returned value.

\section{Configuration Parameters}

Upon interpreter creation, all configuration parameters start with a default value. The default value for a configuration parameter is considered to be part of the formal interface.

Initially, the only supported configuration parameter will be \textbf{bignums}.

When setting the \textbf{bignums} configuration parameter, the value must be convertible to a boolean. When the value of this configuration parameter is false, any math operation that would require using bignums to calculate will instead be limited to the precision available in the \textbf{Tcl\_WideInt} type. The default value of this configuration parameter will be true (i.e. use of bignums will be enabled by default, preserving backward compatibility).

\section{Reference Implementation}

Not yet complete; however, it will eventually be available on the \textbf{tip-392} branch of the Tcl source code repository.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
