From owner-p4-projects@FreeBSD.ORG Sun Dec 30 00:46:23 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A9DBF16A419; Sun, 30 Dec 2007 00:46:23 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6FB5716A417 for ; Sun, 30 Dec 2007 00:46:23 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 46F7113C461 for ; Sun, 30 Dec 2007 00:46:23 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id lBU0kNt1019733 for ; Sun, 30 Dec 2007 00:46:23 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id lBU0kNTH019730 for perforce@freebsd.org; Sun, 30 Dec 2007 00:46:23 GMT (envelope-from gcooper@FreeBSD.org) Date: Sun, 30 Dec 2007 00:46:23 GMT Message-Id: <200712300046.lBU0kNTH019730@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Cc: Subject: PERFORCE change 131999 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Dec 2007 00:46:24 -0000 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; }