tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pdksh



http://www.netbsd.org/~richard/pdksh.patch

The above patch is the pkgsrc specific WIP of a tiny bit of discussion in tech-userlevel@

I'd like to sollicit any comments/observations prior to committing.
I've been using this for a bit now.

-------- Message transféré --------
Sujet : pdksh
Date : Sun, 17 May 2015 13:26:58 +0200
De : Richard PALO <richard%netbsd.org@localhost>
Pour : tech-userlevel%netbsd.org@localhost
Groupes de discussion : gmane.os.netbsd.devel.userlevel

After first soliciting Amitai's and Tobias' opinion, it was felt best to start here.

First the problem statement:

I came across some issues with pkgsrc using pdksh as primary TOOLS_PLATFORM sh/ksh
under SunOS (illumos).

For example, it segfaults in configure when trying to build ffmpeg010 on i386 (ABI=32).

I isolated it to a problem in the function 'tenter' found in table.c.

In 'struct table' both size and nfree are 'short', so for grins I first tried
simply 'min' with INT32_MAX then decided on setting size & nsize as unsigned shorts 
(avoiding for the moment changing the size of the structure):

> richard@omnis:/home/richard/src/pkgsrc/shells/pdksh$ git diff files/table.c
> diff --git a/shells/pdksh/files/table.c b/shells/pdksh/files/table.c
> index 1ac8fc3..9a9e459 100644
> --- a/shells/pdksh/files/table.c
> +++ b/shells/pdksh/files/table.c
> @@ -7,6 +7,9 @@
>  #include "sh.h"
>  
>  #define        INIT_TBLS       8       /* initial table size (power of 2) */
> +#ifndef min
> +#define        min(a, b)       ((a) > (b) ? (b) : (a))
> +#endif
>  
>  static void     texpand     ARGS((struct table *tp, int nsize));
>  static int      tnamecmp    ARGS((void *p1, void *p2));
> @@ -116,7 +119,7 @@ tenter(tp, n, h)
>         }
>  
>         if (tp->nfree <= 0) {   /* too full */
> -               texpand(tp, 2*tp->size);
> +               texpand(tp, min(UINT16_MAX,2*tp->size));
>                 goto Search;
>         }

This works fine, but why make it difficult? 

I'd simply prefer to patch table.h as follows:
> diff --git a/shells/pdksh/files/table.h b/shells/pdksh/files/table.h
> index 637d1c8..ec20352 100644
> --- a/shells/pdksh/files/table.h
> +++ b/shells/pdksh/files/table.h
> @@ -6,7 +6,7 @@
>  
>  struct table {
>         Area   *areap;          /* area to allocate entries */
> -       short   size, nfree;    /* hash size (always 2^^n), free entries */
> +       int size, nfree;        /* hash size (always 2^^n), free entries */
>         struct  tbl **tbls;     /* hashed table items */
>  };
 
that gives plenty of headroom. (ie leave the errors to the malloc handling part)

It seems to build and run fine as well and rather avoids needing to patch table.c at all.

But I noticed two other things in addition.  

1. upstream pdksh-5.2.14-patches.2.gz doesn't seem to be applied, so I took the liberty of applying
this simple patch on exec.c for rv being propagated or not.

BTW, this patch dates back to 2001, no idea why it is neither applied in pkgsrc nor in NetBSD?

2. There are a number of simple patches in NetBSD not applied [yet] in pkgsrc that seem harmless
enough (outside of lint).

-- 
Richard PALO




Home | Main Index | Thread Index | Old Index