TIP 291: Add the 'platform' Package to Tcl

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2017 Conference, Houston/TX, US, Oct 16-20
Send your abstracts to tclconference@googlegroups.com
by Aug 21.
Author:         Steve Landers <steve@DigitalSmarties.com>
Author:         Andreas Kupries <andreask@activestate.com>
State:          Final
Type:           Project
Vote:           Done
Created:        26-Oct-2006
Post-History:   
Keywords:       Tcl,Critcl,TEApot
Tcl-Version:    8.5

Abstract

This TIP proposes adding the platform package to the Tcl core sources and to install it automatically, similar to what is currently done with the tcltest package.

Rationale

It has been shown by the current users of the platform package - the Critcl (C Runtime in Tcl) and the TEApot repository system - that it is useful to not only be able to identify the architecture of a machine running Tcl, but to condense this information into a single identifier, standardized across platforms.

Whilst Tcl provides the tcl_platform array for identifying the current architecture (in particular, the platform and machine elements) this is not always sufficient. This is because (on Unix machines) tcl_platform reflects the values returned by the uname command and these aren't standardized across platforms and architectures. In addition, on at least one platform (AIX) the tcl_platform(machine) contains the CPU serial number.

Consequently, individual applications need to manipulate the values in tcl_platform (along with the output of system specific utilities) - which is both inconvenient for developers, and introduces the potential for inconsistencies in identifying architectures and in naming conventions.

Placing the platform package into the core in the same manner as tcltest will prevent such fragmentation - i.e., it will establish a standard naming convention for architectures running Tcl - and will make it more convenient for developers to identify the current architecture a Tcl program is running on.

Specification of the proposed Change

Tcl Level API

Two new packages, platform and platform::shell are made available, and can be loaded into Tcl via package require.

The package platform provides three commands:

  1. ::platform::identify

    This command returns an identifier describing the platform the Tcl core is running on.

  2. ::platform::generic

    This command returns a simplified identifier, leaving out details like kernel version, libc version, etc.

  3. ::platform::patterns id

    This command takes an identifier as returned by ::platform::identify and returns a list of identifiers for compatible architectures.

All identifiers have the general format OS-CPU. The CPU part will not contain dashes anymore, whereas the OS part may contain dashes.

The package platform::shell provides three commands as well, two of which are wrappers around commands provided by platform.

  1. ::platform::shell::generic shell

    This command returns the generic identification of the specified shell. The shell has to be executable on the host machine, but does not have to have the package platform itself. This is supplied by the caller.

  2. ::platform::shell::identify shell

    This command returns the exact identification of the specified shell. The shell has to be executable on the host machine, but does not have to have the package platform itself. This is supplied by the caller.

  3. ::platform::shell::platform shell

    This command returns the contents of tcl_platform(platform) for the specified shell. The shell has to be executable on the host machine.

Public C API

One deficiency in the current implementation of the package platform is the difficulty of distinguishing 64bit and 32bit systems. To remove this deficiency the variable tcl_platform of the Tcl core is extended to contain an entry pointerSize. The value associated with this entry is the number of bytes needed by the machine to store a void * pointer.

Discussion

When choosing the format for platform identifiers we had two contenders, i.e. OS-CPU vs. CPU-OS, the second of which is used by GCC. However for developers using a scripting language like Tcl the OS is of more importance than the CPU architecture. Because of this the first form was chosen.

Reference Implementation

This is available on SourceForge http://sourceforge.net/support/tracker.php?aid=1600701 .

Copyright

This document has been placed in the public domain.

Please note that any correspondence to the author concerning this TIP is considered in the public domain unless otherwise specifically requested by the individual(s) authoring said correspondence. This is to allow information about the TIP to be placed in a public forum for discussion.

History