bug-make
[Top][All Lists]
Advanced

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

some snippets from make381


From: Markus Mauhart
Subject: some snippets from make381
Date: Wed, 9 Mar 2005 22:15:00 +0100

Hi,


during some long ago experiments with make381beta1 sources I've
gathered some questionable code snippets, some maybe bugs, but
didnt find the time to discuss them, now I thought better now
than even later.
If necessary I can file something to savannah.
A few others are still to be extracted from my archive.



Regards,
Markus.

*********************************************************
* dir.c

    static unsigned long
    directory_contents_hash_2 (const void *key_0)
    {
    struct directory_contents const *key = (struct directory_contents const *) 
key_0;
    unsigned long hash;
    ....

return is ulong, hash is ulong, but all ~10 assignments in the next ~10 lines
cast down to uint.
-> IMHO each (unsigned int)-cast to be replaced with (unsigned long)-cast.


*********************************************************
* dir.c

    static int
    directory_contents_hash_cmp (const void *xv, const void *yv)
    {
    struct directory_contents const *x = (struct directory_contents const *) xv;
    struct directory_contents const *y = (struct directory_contents const *) yv;
    int result;

    #ifdef WINDOWS32
    ISTRING_COMPARE (x->path_key, y->path_key, result);
    if (result)
        return result;
    result = x->ctime - y->ctime;
    if (result)
        return result;
    #else
    # ifdef VMS
    result = x->ino[0] - y->ino[0];
    if (result)
        return result;
    result = x->ino[1] - y->ino[1];
    if (result)
        return result;
    result = x->ino[2] - y->ino[2];
    if (result)
        return result;
    # else
    result = x->ino - y->ino;
    if (result)
        return result;
    # endif
    #endif /* WINDOWS32 */

    return x->dev - y->dev;
    }

My old comment to this function says ...
/*
  int result;

  Bug ? Is this large enough to hold all necessary differences
  of type dev_t and ino_t ? If in doubt better use good old BOOL.
*/
.. and my replacement function is ...

    /* return nonzero <-> entries are different */
    static int
    directory_contents_hash_cmp (const void *xv, const void *yv)
    {
    struct directory_contents const *x = (struct directory_contents const *) xv;
    struct directory_contents const *y = (struct directory_contents const *) yv;

    #if defined(WINDOWS32)
    if (x->ctime != y->ctime || x->dev != y->dev)
        return true;

    return_ISTRING_COMPARE (x->path_key, y->path_key);

    #elif defined(VMS)
    return   x->dev != y->dev
       || x->ino[0] != y->ino[0]
       || x->ino[1] != y->ino[1]
       || x->ino[2] != y->ino[2];

    #else
    return (x->dev != y->dev) || (x->ino != y->ino);

    #endif
    }

*********************************************************
* expand.c:

variable_expand_for_file ... I was convinced this is wrong, and I added
3 lines ("!>"), removed one line ("<!"):

    char *
    variable_expand_for_file (char *line, struct file *file)
    {
      char *result;
      struct variable_set_list *save;
 !>   const struct floc* curfile;

      if (file == 0)
        return variable_expand (line);

 !>   curfile = reading_file;
      save = current_variable_set_list;
      current_variable_set_list = file->variables;
      if (file->cmds && file->cmds->fileinfo.filenm)
        reading_file = &file->cmds->fileinfo;
      else
        reading_file = 0;
      result = variable_expand (line);
      current_variable_set_list = save;
 <!   reading_file = 0;
 !>   reading_file = curfile;

      return result;
    }


*********************************************************
* lindex() is redundant.

grep'ing this function in current CVS gives me ...

make\expand.c(250):         p1 = lindex (beg, end, '$');
make\expand.c(283):         colon = lindex (beg, end, ':');
make\expand.c(290):             subst_end = lindex (subst_beg, end, '=');
make\make.h(425):extern char *lindex PARAMS ((const char *, const char *, int));
make\misc.c(423):lindex (const char *s, const char *limit, int c)

AFAICS, "lindex (beg, end, (char)what)" is 100% equivalent to
"memchr (beg, (char)what, end-beg)".
IOW, as long as you only use lindex() to search for real chars (not for
non-"char"s like EOF), lindex() is redundant.

So IMO lindex() can be removed from make.h and misc.c, and its 3 lines
in expand.c then would be replaced with ...

make\expand.c(250):         p1 = memchr (beg, '$', end - beg);
make\expand.c(283):         colon = memchr (beg, ':', end - beg);
make\expand.c(290):             subst_end = memchr (subst_beg, '=', end - 
subst_beg);







reply via email to

[Prev in Thread] Current Thread [Next in Thread]