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

<TIP number='336'>
<header><title>Supported Access To interp-&gt;errorline</title><author address="mailto:dgp@users.sf.net">Don Porter</author><status type='project' state='final' tclversion="8.6" vote='after'>$Revision: 1.4 $</status><history></history><created day='21' month='oct' year='2008' /></header>
<abstract>This TIP proposes a supported public interface to set and get the value of the <emph style="italic">errorLine</emph> field of the <emph style="italic">Tcl_Interp</emph> data structure.</abstract>
<body><section title="Background">
<para>A more forceful barrier to direct access to the <emph style="italic">result</emph> and <emph style="italic">freeProc</emph> fields of the <emph style="italic">Tcl_Interp</emph> data structure has just been accepted <tipref type="text" tip="330"/>. This revision leaves only the <emph style="italic">errorLine</emph> field still normally publicly visible. The visibility of this field prevents the realization of <emph style="italic">Tcl_Interp</emph> as a fully opaque data structure.</para>
<para>The <emph style="italic">result</emph> and <emph style="italic">freeProc</emph> fields have long had the recommended alternatives of <emph style="bold">Tcl_GetStringResult</emph> and <emph style="bold">Tcl_SetResult</emph> which make direct access unnecessary. The <emph style="italic">errorLine</emph> field has long gone without such alternatives. Starting with Tcl 8.5, some alternatives do exist. The value of the <emph style="italic">errorLine</emph> field can be set by passing an appropriate dictionary to <emph style="bold">Tcl_SetReturnOptions</emph> and the value can be retrieved from the dictionary returned by passing <emph style="bold">TCL_ERROR</emph> to <emph style="bold">Tcl_GetReturnOption</emph> <tipref type="text" tip="227"/>. The housekeeping burden of these alternatives is significant, so there&apos;s little attraction for replacing direct access to the <emph style="italic">errorLine</emph> field with them.</para>
<para>Specialized routines already exist for managing the fully private fields <emph style="italic">errorInfo</emph> and <emph style="italic">errorCode</emph> in the opaque part of the <emph style="italic">Interp</emph> data structure, <emph style="bold">Tcl_SetErrorCode</emph>, <emph style="bold">Tcl_AddErrorInfo</emph>, etc. The management of these values is needed frequently enough to make simplified alternatives like this worthwhile.</para>
</section>
<section title="Proposal">
<para>Create the following new public routines to get and set the <emph style="italic">errorLine</emph> field:</para>
<quote>int <emph style="bold">Tcl_GetErrorLine</emph>(Tcl_Interp *<emph style="italic">interp</emph>)</quote>
<quote>void <emph style="bold">Tcl_SetErrorLine</emph>(Tcl_Interp *<emph style="italic">interp</emph>, int <emph style="italic">value</emph>)</quote>
<para>These will be implemented as (equivalent to):</para>
<verbatim><vline encoding='base64'>aW50IFRjbF9HZXRFcnJvckxpbmUoVGNsX0ludGVycCAqaW50ZXJwKSB7</vline><vline encoding='base64'>ICAgIHJldHVybiAoKEludGVycCAqKSBpbnRlcnApLT5lcnJvckxpbmU7</vline><vline encoding='base64'>fQ==</vline><vline encoding='base64'></vline><vline encoding='base64'>dm9pZCBUY2xfU2V0RXJyb3JMaW5lKFRjbF9JbnRlcnAgKmludGVycCwgaW50IHZhbHVlKSB7</vline><vline encoding='base64'>ICAgICgoSW50ZXJwICopIGludGVycCktPmVycm9yTGluZSA9IHZhbHVlOw==</vline><vline encoding='base64'>fQ==</vline></verbatim>
<para>In addition, following the example of <tipref type="text" tip="330"/>, disable the default public access to the <emph style="italic">errorLine</emph> field, permitting the restoration of access only when the <emph style="bold">USE_INTERP_ERRORLINE</emph> directive is defined.</para>
</section>
<section title="Compatibility">
<para>This change is a source incompatibility with C code directly accessing the <emph style="italic">errorLine</emph> field. The quick fix to restore compatibility is to define <emph style="bold">USE_INTERP_ERRORLINE</emph>. The next step for migrating old code would be to adopt the new routines, and offer macros to duplicate the effect of the new routines when older Tcl headers are in use.</para>
</section>
<section title="Rationale">
<para>This is the last stepping stone to prepare the way for <emph style="italic">Tcl_Interp</emph> to become a fully opaque data structure. The rationale for the immediate disabling of public access is to (over?)learn the lesson of <tipref type="text" tip="330"/>. No matter how sternly you warn about deprecation, nothing happens until you turn it off, so let&apos;s move immediately to turning it off, with the burden on the users to restore what they need.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>

