Date: Sun, 30 Dec 2007 00:46:23 GMT From: Garrett Cooper <gcooper@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 131999 for review Message-ID: <200712300046.lBU0kNTH019730@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=131999 Change 131999 by gcooper@shiina-ibook on 2007/12/30 00:45:36 1. Scratch one more todo from turner. 2. Add a few more checks (stuff seems missing). 3. Add a very funny comment (or at least I thought it was funny -- ok, ok, just confused / frustrated. lol). Affected files ... .. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db_match.c#4 edit Differences ... ==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db_match.c#4 (text+ko) ==== @@ -145,11 +145,9 @@ if (regex == NULL) return NULL; - /* Count the number of regex's */ - for (rex.count = 0; regex[rex.count] != NULL; rex.count++) - continue; + rex.count = (sizeof(regex) / sizeof(const char **)) - 1; + rex.rex = malloc(rex.count * sizeof(regex_t)); - rex.rex = malloc(rex.count * sizeof(regex_t)); if (rex.rex == NULL) return NULL; @@ -187,11 +185,8 @@ if (patterns == NULL) return NULL; - /* Count the number of globs */ - for (the_glob.count = 0; patterns[the_glob.count] != NULL; - the_glob.count++) - continue; - + the_glob.count = (sizeof(patterns) / sizeof(const char**)) - 1; + /* patterns is NULL terminated already. No worries.. */ the_glob.patterns = patterns; pkgs = pkg_db_get_installed_match(db, pkg_match_glob, &the_glob); @@ -217,7 +212,10 @@ * @brief Function to match all packages with one of the given names * @return 0 if the package matches * @return -1 otherwise - */ + * + * @todo: Verify this does as promised; this doesn't seem functionally + * correct in the least.. + */ static int pkg_match_name(struct pkg *pkg, const void *data) { @@ -269,16 +267,29 @@ static int pkg_match_glob(struct pkg *pkg, const void *data) { - /** @todo Fix to just take a null terminated array of strings */ + /* + * Andrew Turner: + * @todo Fix to just take a null terminated array of strings + * Garrett Cooper: + * Agh... make up your mind. Are you going to use the count + * data member or a temporary variable, per fn, per struct + * (this applies not only to struct glob_or, but also struct + * regex_or)? + * + * Using count eats up more memory, but not too much, whereas + * calculating it on the fly requires some time for determining + * the NULL terminated length, but blah.. this is just plain, + * silly.. + */ unsigned int i; const struct glob_or *the_glob; - + assert(pkg != NULL); assert(data != NULL); - the_glob = data; + the_glob = (const struct glob_or*) data; for(i=0; i < the_glob->count; i++) { - /* This should use the csh_match from FreeBSD pkg_info */ + /* @todo: This should use the csh_match from FreeBSD pkg_info */ if (fnmatch(the_glob->patterns[i], pkg_get_name(pkg), 0) == 0) return 0; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200712300046.lBU0kNTH019730>