Skip to content
Tcl Source Code Artifact [3329e1531d]
Login

Artifact [3329e1531d]

Artifact 3329e1531d355f68ee1fd52c4dfbd5823ae41cac:

Wiki page [Object Type Registration] by dgp on 2014-09-15 01:25:57.
D 2014-09-15T01:25:57.770
L Object\sType\sRegistration
U dgp
W 2963
<h1>Source Files</h1>
  *  portions of [/finfo?name=generic/tclObj.c|tclObj.c]

<h1>Public Routines</h1>
  *  Tcl_RegisterObjType
  *  Tcl_AppendAllObjTypes
  *  Tcl_GetObjType
  *  Tcl_ConvertToType

<h1>Private Routines</h1>
  *  TclInitObjectSubsystem
  *  TclFinalizeObjects

<h1>Directly Depends On Public Routines From</h1>
  *  [Threads]
  *  [Hash Tables]
  *  [list ObjectType]
  *  [Parsing and Evaluation]

<h1>Directly Depends On Private Routines From</h1>
  *  <i>None</i>

<h1>Discussion</h1>

Given the benefit of years of experience with the Tcl 8 stork
model of values, this entire module is believed by many to
have been a mistake.  It exposes enough of a mechanism to
give any arbitrary code the power to set a particular internal
representation as managed by other arbitrary code.  This is
typically a mistake, as only the code written to create, maintain,
and return a particular internal rep really knows when it is
proper to store it in the value.  Typically, any caller of
<b>Tcl_ConvertToType</b> on a type not of its own
responsibility, is going to act on knowledge about the
internal rep, breaking the encapsulation, and setting up fragility
when the implementation of the type is revised.

In place of <b>Tcl_ConvertToType</b>, any object type that
can usefully export something from its internal representation
ought to define an appropriate <b>GetFooFromObj</b> routine.
The details of each routine will depend on the nature of the
value stored, so it seems it ought not be a general interface.
If it is determined that a general solution has to be offered,
then presumably it would be oriented around ClientData.

Without <b>Tcl_ConvertToType</b> to service, there is no
longer any need for any type to define a setFromAnyProc.
Instead, the same function would be in whatever GetFooFromObj
routine it may supply.  Also with no <b>Tcl_ConvertToType</b>
to call, there is no need for any caller to access an arbitrary
Tcl_ObjType, so there's no need for <b>Tcl_GetObjType</b>.
And if no <b>Tcl_GetObjType</b> will be pulling types out
of registration, then no <b>Tcl_RegisterObjType</b> needs
to put them in there, nor do we need any mechanism to list
the types available.  The end result is a system with far
greater decoupling, which is helpful for independent,
non-coordinated development of interoperating modules.

Besides the advantages of a more decoupled system, there
are other problems with object type registration in that it has
never been well defined how to properly resolve any collisions
the the object type names by which registration happens.
Neither option of either raising errors on collision, nor using
collisions as a means to replace and retrofit has been embraced.
All that has been done is to avoid collisions as much as possible.

Over time, several of the object types built into Tcl have
pulled back from registration as they could.



Z 2104d699ebee5cf50a288b5fea7947db