Патчи на AWK из NetBSD

Any discussions about UNIX OS (include Linux)

Moderator: sva

Патчи на AWK из NetBSD

Postby Aleksey Cheusov on Thu Feb 18, 2010 5:22 pm

Я так понимаю, здесь гуляют разработчики FreeBSD.

Думаю, большинство багов из NetBSD на awk воспроизведутся и во FreeBSD. Пользовали и разработчики,
проверьте воспроизводятся ли, и если что, пинайте своих.

С Брайном Керниганом я разговаривал. Если вкратце, он ответил так: "у меня так работает 30 лет и я не буду ничего менять" (PR/39133 и др.)
или "это не баг" (PR/33392) или "я пытался, но не смог, и не буду больше пытаться" (PR/36394). Короче, не собирается он ничего фиксить и даже
спасибо не скажет :-/

- fixed: serious bug with regular expression, PR/33392
- fixed: support for multibyte charsets in tolower/toupper functions, PR/36394
- fixed: there is a hardcoded limit on a number of open files, PR/37205
- fixed: incorrect handling of \ at the end of line in awk script, PR/37212
- fixed: incorrect matching of [:cntrl:], PR/38737
- fixed: warning about non-portable escape sequences, PR/39002
- fixed: free(): warning: junk pointer, too low to make sense, PR/39132
- fixed: -Ft is broken, PR/39133
- fixed: segfaults when "nextfile" is in BEGIN {...}, bin/39134
- fixed: nawk doesn't handle RS as a RE but as a single character, PR/30294
- fixed: awk(1) crash with RE and ^ anchor, PR/40689

Others are not fixed:
- Bizarre behavior in awk with invalid numeric constants, PR/42463
- LC_NUMERIC in awk is not POSIX compliant, PR/42320
- NetBSD awk/nawk concatenation op. is much slower than that of GNU awk, PR/39759
- /usr/bin/awk: formatting issues in printf, PR/39135
- regexps should treat { and } as {n,m}, but as regular characters, PR/38127
Aleksey Cheusov
 

Re: Патчи на AWK из NetBSD

Postby Mikolaj Golub on Thu Feb 18, 2010 5:26 pm

> - fixed: serious bug with regular expression, PR/33392

http://www.freebsd.org/cgi/query-pr.cgi?pr=143362

но без патча (только со ссылкой на NetBSD-шный PR), т.к. судя по PR в NetBSD сразу неудачно пофиксили, потом еще долечивали
и я запутался в конечном счете какие диффы тянуть.

Если подскажешь как или сам сгенерируешь дифф для NetBSD, я могу наложить на FreeBSD-шный, проверить и добавить к pr.

> > - fixed: support for multibyte charsets in tolower/toupper functions, PR/36394

http://www.freebsd.org/cgi/query-pr.cgi?pr=143373

> > - fixed: there is a hardcoded limit on a number of open files, PR/37205

http://www.freebsd.org/cgi/query-pr.cgi?pr=143368

> > - fixed: incorrect handling of \ at the end of line in awk script, PR/37212

http://www.freebsd.org/cgi/query-pr.cgi?pr=143363

> > - fixed: incorrect matching of [:cntrl:], PR/38737

http://www.freebsd.org/cgi/query-pr.cgi?pr=143365

> > - fixed: warning about non-portable escape sequences, PR/39002

Тут не все однозначно :-), поэтому пока не репорчу, погляжу сначала как с другими дело пойдет.

> > - fixed: free(): warning: junk pointer, too low to make sense, PR/39132

не воспроизводится, нету варнингов:

Code: Select all
[mikolaj@kopusha ~/freebsd/awk]$ cat 39132.awk
#!/usr/bin/awk -f


function func2 (flag){
        flag = 0
}


BEGIN {
        func2(1)
        func2(2)
        func2(3)
}
[mikolaj@kopusha ~/freebsd/awk]$ ./39132.awk
[mikolaj@kopusha ~/freebsd/awk]$


> > - fixed: -Ft is broken, PR/39133

http://www.freebsd.org/cgi/query-pr.cgi?pr=143367

> > - fixed: segfaults when "nextfile" is in BEGIN {...}, bin/39134

не воспроизводится. Ведет себя как и в свежем NetBSD:

kopusha:~% awk 'BEGIN {nextfile}' foo
awk: illegal break, continue, next or nextfile from BEGIN
source line number 1

> > - fixed: nawk doesn't handle RS as a RE but as a single character, PR/30294

http://www.freebsd.org/cgi/query-pr.cgi?pr=143369

> > - fixed: awk(1) crash with RE and ^ anchor, PR/40689

http://www.freebsd.org/cgi/query-pr.cgi?pr=143375

Остальные (т.к. непофикшенные :-) не репортил, только глянул

> > Others are not fixed:
> > - Bizarre behavior in awk with invalid numeric constants, PR/42463

тоже самое под FreeBSD

> > - LC_NUMERIC in awk is not POSIX compliant, PR/42320

тут по идее все нормально:

zhuzha:~% echo xxxx | LC_NUMERIC=ru_RU.KOI8-R /usr/bin/awk '{print 0.01}' 0,01

> > - NetBSD awk/nawk concatenation op. is much slower than that of GNU awk, PR/39759

то же самое

zhuzha:/tmp% cat 39759.awk
Code: Select all
{
    accu = accu "\n" $0
}
NF == 0 {
    print accu
    accu = ""
    next
}
zhuzha:/tmp% wc ~/procmail.log                               
   14317   66290  604677 /home/golub/procmail.log
zhuzha:/tmp% time gawk -f 39759.awk ~/procmail.log > /dev/null
gawk -f 39759.awk ~/procmail.log > /dev/null  0.66s user 0.01s system 99% cpu
   0.670 total
zhuzha:/tmp% time awk -f 39759.awk ~/procmail.log > /dev/null
awk -f 39759.awk ~/procmail.log > /dev/null  30.97s user 0.32s system 99% cpu
   31.315 total


> > - /usr/bin/awk: formatting issues in printf, PR/39135

воспроизводится

zhuzha:~% awk 'BEGIN {printf "%llu\n", 123}' 35184372088955

> > - regexps should treat { and } as {n,m}, but as regular
> > characters, PR/38127

похоже зарепорчен уже
http://www.freebsd.org/cgi/query-pr.cgi ... ards/54410
Mikolaj Golub
 

Re: Патчи на AWK из NetBSD

Postby Mikolaj Golub on Thu Feb 18, 2010 5:28 pm

огда-то репортили вот такой баг

http://www.freebsd.org/cgi/query-pr.cgi?pr=104795

# awk 'function f(x) {x=""} BEGIN {f(1)}'
awk in free(): error: junk pointer, too low to make sense
Abort trap (core dumped)

Который выглядит очень похожим. И там был фикс, но другой чем в NetBSD.

Fix a bug converting a variable from the numeric type to a string.

Code: Select all
--- src/contrib/one-true-awk/tran.c   2005/05/16 19:11:35 1.1.1.4
+++ src/contrib/one-true-awk/tran.c   2007/10/25 12:38:02 1.1.1.5
@@ -332,10 +332,10 @@ char *setsval(Cell *vp, const char *s)    /
           donerec = 1;
           }
           t = tostring(s);     /* in case it's self-assign */
-          vp->tval &= ~NUM;
-          vp->tval |= STR;
           if (freeable(vp))
              xfree(vp->sval);
+             vp->tval &= ~NUM;
+             vp->tval |= STR;
              vp->tval &= ~DONTFREE;
                 dprintf( ("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n",
                          vp, NN(vp->nval), t,t, vp->tval, donerec, donefld)
                          );

Позже этот патч попал в мейнстрим.

Revision 1.1.1.5
Thu Oct 25 12:38:02 2007 UTC (2 years, 3 months ago) by obrien

Vendor import of bwk's 23-Oct-2007 release.
This includes fixes for FreeBSD PR's: bin/104795, bin/100443

В NetBSD фикс был такой:

PR/39132: cheusov at tut dot by: When copying an OCELL, make sure you make
a copy of its string and deal with DONTFREE properly, so that we don't try
to free the OCELL pointer later which points to a literal string in the text
segment.

Index: src/dist/nawk/run.c
diff -u src/dist/nawk/run.c:1.19 src/dist/nawk/run.c:1.20
--- src/dist/nawk/run.c:1.19    Sun May 25 14:51:49 2008
+++ src/dist/nawk/run.c Fri Jul 11 22:11:24 2008
@@ -323,15 +323,18 @@
Cell *copycell(Cell *x)        /* make a copy of a cell in a temp */
{
        Cell *y;
+       int flags = CON|FLD|REC|DONTFREE;
+       /* copy is not constant or field */

        y = gettemp();
        y->csub = CCOPY;        /* prevents freeing until call is over */
        y->nval = x->nval;      /* BUG? */
-       if (isstr(x))
+       if (isstr(x) || x->ctype == OCELL) {
                y->sval = tostring(x->sval);
+               flags &= ~DONTFREE;
+       }
        y->fval = x->fval;
-       y->tval = x->tval & ~(CON|FLD|REC|DONTFREE);    /* copy is not
-       constant or field */
-                                                       /* is DONTFREE right?
-       */
+       y->tval = x->tval & ~flags;
        return y;
}


Я не разбирался в коде, действительно ли лечится та же самая проблема (похоже что да) и насколько правильно в обоих случаях,
поэкспериментировал только чуть-чуть:

1) откатил FreeBSD-шный патч -- начало крашиться (в том как раз месте где патчили -- на xfree()):

zhuzha:/usr/src/contrib/one-true-awk% ./a.out 'function f(x) {x="";} BEGIN {f(1)}'
zsh: segmentation fault (core dumped) ./a.out 'function f(x) {x="";} BEGIN {f(1)}'
zhuzha:/usr/src/contrib/one-true-awk% ./a.out 'function f(x) {x=0;} BEGIN {f(1)}'
zsh: segmentation fault (core dumped) ./a.out 'function f(x) {x=0;} BEGIN {f(1)}'

2) наложил NetBSD-шный патч -- перестало:

zhuzha:/usr/src/contrib/one-true-awk% ./a.out 'function f(x) {x=0;} BEGIN {f(1)}'
zhuzha:/usr/src/contrib/one-true-awk% ./a.out 'function f(x) {x="";} BEGIN {f(1)}'
zhuzha:/usr/src/contrib/one-true-awk%

Можно считать что в FreeBSD этой проблемы нету? :-)
Mikolaj Golub
 


Return to UNIX

Who is online

Users browsing this forum: No registered users and 2 guests