Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: parameter improvements



This is quite a big patch we makes some structural changes to the
parameter code.  It's attached as a gzip'd file.

First, it removes the long-standing limitation that numeric types can't
have justification or padding declared as part of the type (the
parameter flags worked since this is all done after type conversion).
You could work round this in zsh code, but it was illogical and an
inconvenience in code shared with ksh.  There are some tests for this.
It wasn't too much work.

A few minor changes which I think are improvements came in as a result.
For example, the former:

% typeset -Z 10 foo=" 32"
% print $foo
0000000 32

(note the variable is a scalar; -Z didn't used to work with integers,
and even now it does the space is stripped on input in that case) now
outputs

 000000032

which I think makes more sense, given the (strange but documented)
feature that blanks are ignored when deciding whether to add
zero-padding, but are not stripped.  Replacing the spaces with zeroes
would be an option.

This came in because I decided to handle zero-padding intelligently for
numbers, i.e. the zeroes go in the right place.

Note, however, that truncation of numbers to fit the justified form is
not particularly intelligent.  It's up to the user to pick a sensible
format and precision.


That change added an extra word to the param structure.  So I took the
opportunity of rewriting the structure.  Instead of containing three
function pointers for getting, setting and unsetting the value, it
contains a single pointer to a structure with a set of methods.  As only
one such structure is needed per type, this is a significant gain for
ordinary parameters.  The complexity comes in that special parameters
typically each need their own get and set methods, which means
proliferating structures for special types.  However, these are declared
constant, so there is even some potential for a memory management gain
for these as well.

Graphically, taking scalars as an example, it looked like this
before the change:

   Per parameter            Per type
   -------------            --------

   pm {
     union {
       *cfn         ->      strgetfn()
       ....
       ....
     } gets
     union {
       *cfn         ->      strsetfn()
       ....
       ....
     } sets
     *unsetfn       ->      stdunsetfn
   }

(note that unsetfn actually wasn't unionized.)

After:

   pm {
      union {
        *s          ->  stdscalar_gsu = { &strgetfn, &strsetfn, &stdunsetfn }
	...
      } gsu;
   }

Use of the GSU (get/set/unset) structure adds a little bit of extra type
safety, although initialising the unions is kludged so this isn't complete.

This means an extra indirection, the effect of which should be entirely
negligible.  This looks much more like how a C++ class would work,
although the hierarchy of real C++ classes would almost certainly be
organised differently.  I hope, therefore, this will be expandable for
any more sophisticated parameter handling that needs doing.  In
particular it will be possible to have variant-format GSU structures
with extra elements without changing the size of individual parameters.

The biggest worry is that I've declared one of the special *_gsu
variables wrongly so that a special variable is broken.  Keep an eye out
for this (cast your eye over the declarations in params.c if you feel
inclined).

This time, all tests pass, including the new ones I've added for
justification and padding.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

Attachment: vtable_width.dif.gz
Description: Parameter patch



Messages sorted by: Reverse Date, Date, Thread, Author