Blame test/wideidx2.awk

Packit 575503
# Date: Thu, 27 Apr 2006 20:59:03 +0100
Packit 575503
# From: Lee Haywood <ljhaywood2@googlemail.com>
Packit 575503
# Subject: gawk multi-byte support bugs, assertion bug and fix.
Packit 575503
# To: bug-gawk@gnu.org
Packit 575503
# Message-id: <60962be00604271259na0d8fdayb9d0c69a853216e8@mail.gmail.com>
Packit 575503
# MIME-version: 1.0
Packit 575503
# Content-type: multipart/alternative;
Packit 575503
#  boundary="----=_Part_10136_920879.1146167943492"
Packit 575503
# Status: RO
Packit 575503
# 
Packit 575503
# ------=_Part_10136_920879.1146167943492
Packit 575503
# Content-Type: text/plain; charset=ISO-8859-1
Packit 575503
# Content-Transfer-Encoding: quoted-printable
Packit 575503
# Content-Disposition: inline
Packit 575503
# 
Packit 575503
# 
Packit 575503
# Firstly, I have been getting the following error from version 3.1.5.
Packit 575503
# 
Packit 575503
#     awk: node.c:515: unref: Assertion `(tmp->flags & 4096) !=3D 0' failed.
Packit 575503
# 
Packit 575503
# In mk_number() in node.c the MBS_SUPPORT code is inside the GAWKDEBUG
Packit 575503
# section - moving it outside explicitly clears the string values, which
Packit 575503
# prevents the assertion error from occurring.  The corrected version is
Packit 575503
# shown at the end of this message.
Packit 575503
# 
Packit 575503
# As an aside, I also noticed that n->wstptr is not cleared by
Packit 575503
# set_field() and set_record() in field.c when the flags are set to
Packit 575503
# exclude WSTRCUR.  However, I do not have a test case to show if
Packit 575503
# changing them makes any difference.
Packit 575503
# 
Packit 575503
# A second problem also occurs when gawk 3.1.5 is compiled with
Packit 575503
# multi-byte character support (MBS_SUPPORT).  The following code should
Packit 575503
# change the index of the substring "bc" from 2 to 3, but it gets
Packit 575503
# reported as 2 in both cases - which is obviously disastrous.
Packit 575503
# 
Packit 575503
#     awk 'BEGIN {
Packit 575503
#             Value =3D "abc"
Packit 575503
# 
Packit 575503
#             print "Before <" Value "> ",
Packit 575503
#                   index( Value, "bc" )
Packit 575503
# 
Packit 575503
#             sub( /bc/, "bbc", Value )
Packit 575503
# 
Packit 575503
#             print "After  <" Value ">",
Packit 575503
#                   index( Value, "bc" )
Packit 575503
#         }'
Packit 575503
# 
Packit 575503
# Compiling with MBS_SUPPORT undefined makes these problems go away.
Packit 575503
# 
Packit 575503
# /* mk_number --- allocate a node with defined number */
Packit 575503
# 
Packit 575503
# NODE *
Packit 575503
# mk_number(AWKNUM x, unsigned int flags)
Packit 575503
# {
Packit 575503
#         register NODE *r;
Packit 575503
# 
Packit 575503
#         getnode(r);
Packit 575503
#         r->type =3D Node_val;
Packit 575503
#         r->numbr =3D x;
Packit 575503
#         r->flags =3D flags;
Packit 575503
# #if defined MBS_SUPPORT
Packit 575503
#         r->wstptr =3D NULL;
Packit 575503
#         r->wstlen =3D 0;
Packit 575503
# #endif /* MBS_SUPPORT */
Packit 575503
# #ifdef GAWKDEBUG
Packit 575503
#         r->stref =3D 1;
Packit 575503
#         r->stptr =3D NULL;
Packit 575503
#         r->stlen =3D 0;
Packit 575503
# #if defined MBS_SUPPORT
Packit 575503
#         r->flags &=3D ~WSTRCUR;
Packit 575503
# #endif /* MBS_SUPPORT */
Packit 575503
# #endif /* GAWKDEBUG */
Packit 575503
#         return r;
Packit 575503
# }
Packit 575503
# 
Packit 575503
# Thanks.
Packit 575503
# 
Packit 575503
# --
Packit 575503
# Lee Haywood.
Packit 575503
Packit 575503
BEGIN {
Packit 575503
	Value = "abc"
Packit 575503
Packit 575503
	print "Before <" Value "> ", index( Value, "bc" )
Packit 575503
 
Packit 575503
	sub( /bc/, "bbc", Value )
Packit 575503
Packit 575503
	print "After  <" Value ">", index( Value, "bc" )
Packit 575503
}