On Thu, Dec 13, 2012 at 3:06 AM, Roland Mainz <[email protected]> wrote:
> On Wed, Dec 12, 2012 at 4:02 PM, David Korn <[email protected]> wrote:
>> cc: [email protected]
>> Subject: Re: Re: [ast-developers] [rfe] typeset -B to define a (C99-like)
>> <stdbool.h> datatype
>> --------
>>
>> Why bother with an alias? Why not just create Bool as a predefined type?
>
> Erm... I had a couple of reasons:
> 1. All basic ksh93 types modelled after C types (e.g. integer, float,
> compound) are aliases to the real type definitions
> 2. C99 (see the <stdbool.h> manpage quote in my earlier email) says
> "... bool - Expands to _Bool..." ... which IMO makes sense since C99
> allows to |#undef bool| and redefine it to something else. We can do
> the same with $ unalias bool #.
> 3. Irek suggested the same $ unalias bool # for the (very) unlikely
> case ([a1]) that someone already uses "bool" as a command name
>
> [a1]= See
> http://www.mail-archive.com/[email protected]/msg00154.html
> where at least for Sun's Solaris we added this clause to ksh93(1):
> -- snip --
> CAVEATS
> + It is recommended that ksh93 scripts should choose shell
> + function names outside the namespace used by reserved
> + keywords of the ISO C99, C++ and JAVA languages to avoid
> + collisions with future enhancements to ksh93.
> -- snip --
Attached (as "ksh93_bool_prototype20121213_002.diff.txt") is an
updated version of the patch.
The difference to the previous patch is the addition of $ unset _Bool
# to prevent the tests in the ksh93 test suite which assume that $ ksh
-c 'typeset -pa' # return an empty string do not complain (the issue
is that declaring an "enum foo" creates an indexed array "foo" (AFAIK
an implementation artefact ?!) over which the tests then stumble).
Per discussion with Irek&&Olga I've kept the concept of having an
alias bool=_Bool to allow consumers to undefine or redirect "bool" and
to be consistent with the other basic ksh93 types (like "integer",
"float" or "compound") which are all aliases of the real type
definitions.
* Open issues:
- typeset -T has issues with enums - reported in
http://lists.research.att.com/pipermail/ast-developers/2012q4/002169.html
("[ast-developers] Declaring an enum with ast-ksh.2012-11-21 corrupts
output of $ typeset -T # ..")
- The use of $ unset _Bool # should be replaced with something which
simply avoids the creation of the indexed array of the same name
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) [email protected]
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
diff -r -u original/src/cmd/ksh93/data/aliases.c
build_bool/src/cmd/ksh93/data/aliases.c
--- src/cmd/ksh93/data/aliases.c 2012-06-12 21:00:58.000000000 +0200
+++ src/cmd/ksh93/data/aliases.c 2012-12-11 23:21:46.073236479 +0100
@@ -33,6 +33,7 @@
"2d", NV_NOFREE, "set -f;_2d",
#endif /* SHOPT_FS_3D */
"autoload", NV_NOFREE, "typeset -fu",
+ "bool", NV_NOFREE|BLT_DCL, "_Bool",
"command", NV_NOFREE, "command ",
"compound", NV_NOFREE|BLT_DCL, "typeset -C",
"fc", NV_NOFREE, "hist",
diff -r -u original/src/cmd/ksh93/sh/main.c build_bool/src/cmd/ksh93/sh/main.c
--- src/cmd/ksh93/sh/main.c 2012-11-20 18:09:41.000000000 +0100
+++ src/cmd/ksh93/sh/main.c 2012-12-14 04:30:39.265412053 +0100
@@ -240,6 +240,9 @@
else if(sh_isoption(shp,SH_INTERACTIVE) &&
sh_isoption(shp,SH_PRIVILEGED))
sh_source(shp, iop, e_suidprofile);
}
+
+ sh_trap(shp,"enum _Bool=(false true) ; unset _Bool ;",0);
+
shp->st.cmdname = error_info.id = command;
sh_offstate(shp,SH_PROFILE);
if(rshflag)
Only in original/src/cmd/ksh93/tests: arrays.sh
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers