<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Tue May 21 13:14:59 GMT 2013 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='392'>
<header><title>Allow Bignums to be Disabled at Runtime on a Per-Interp Basis</title><author address="mailto:joe@mistachkin.com">Joe Mistachkin</author><status type='project' state='draft' tclversion="8.5" vote='prior'>$Revision: 1.1 $</status><history></history><created day='30' month='oct' year='2011' /><keyword>bignum runaway safe math precision integer tcl</keyword></header>
<abstract>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.</abstract>
<body><section title="Rationale">
<para>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 <emph style="bold">interp create -safe</emph>, <emph style="bold">interp limit</emph>, <emph style="bold">interp cancel</emph>, 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.</para>
</section>
<section title="Specification">
<para>A new <emph style="bold">interp configure</emph> script command will be added, as follows:</para>
<quote><emph style="bold">interp configure</emph> <emph style="italic">path</emph> ?<emph style="italic">name</emph>? ?<emph style="italic">value</emph>?</quote>
<para>This command instructs Tcl to modify or query the value of the named configuration parameter <emph style="italic">name</emph> in the interpreter identified by <emph style="italic">path</emph>.</para>
<subsection title="Arguments">
<quote><emph style="italic">path</emph></quote>
<para>This argument is required and specifies the interpreter to be reconfigured. An empty string may be used to indicate the current interpreter.</para>
<quote><emph style="italic">name</emph></quote>
<para>This argument is optional. If this argument is not supplied, the current list of configuration parameter names for the interpreter identified by <emph style="italic">path</emph> will be returned.</para>
<quote><emph style="italic">value</emph></quote>
<para>This argument is optional. If this argument is not supplied, the current value of the named configuration parameter for the interpreter identified by <emph style="italic">path</emph> will be returned; otherwise, the current value of the configuration parameter will be changed to the specified value.</para>
</subsection>
<subsection title="C API">
<quote>Tcl_Obj* <emph style="bold">Tcl_InterpConfigure</emph>(Tcl_Interp* <emph style="italic">interp</emph>, Tcl_Obj* <emph style="italic">nameObjPtr</emph>, Tcl_Obj* <emph style="italic">valueObjPtr</emph>)</quote>
<para>The <emph style="bold">Tcl_InterpConfigure</emph> function gets or sets the named configuration parameter for the specified interpreter. The <emph style="italic">nameObjPtr</emph>, 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 <emph style="italic">valueObjPtr</emph>, 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 <emph style="italic">valueObjPtr</emph> is NULL, the current value of the named configuration parameter will be returned instead of being changed. If <emph style="italic">nameObjPtr</emph> 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.</para>
</subsection>
</section>
<section title="Configuration Parameters">
<para>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.</para>
<para>Initially, the only supported configuration parameter will be <emph style="bold">bignums</emph>.</para>
<para>When setting the <emph style="bold">bignums</emph> 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 <emph style="bold">Tcl_WideInt</emph> type. The default value of this configuration parameter will be true (i.e. use of bignums will be enabled by default, preserving backward compatibility).</para>
</section>
<section title="Reference Implementation">
<para>Not yet complete; however, it will eventually be available on the <emph style="bold">tip-392</emph> branch of the Tcl source code repository.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>
