From owner-p4-projects@FreeBSD.ORG Mon Aug 17 18:35:50 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 0E7D7106568D; Mon, 17 Aug 2009 18:35:50 +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 C709C106568B for ; Mon, 17 Aug 2009 18:35:49 +0000 (UTC) (envelope-from dforsyth@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id B528A8FC59 for ; Mon, 17 Aug 2009 18:35:49 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n7HIZnwG001988 for ; Mon, 17 Aug 2009 18:35:49 GMT (envelope-from dforsyth@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n7HIZn8Y001986 for perforce@freebsd.org; Mon, 17 Aug 2009 18:35:49 GMT (envelope-from dforsyth@FreeBSD.org) Date: Mon, 17 Aug 2009 18:35:49 GMT Message-Id: <200908171835.n7HIZn8Y001986@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to dforsyth@FreeBSD.org using -f From: David Forsythe To: Perforce Change Reviews Cc: Subject: PERFORCE change 167453 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: Mon, 17 Aug 2009 18:35:50 -0000 http://perforce.freebsd.org/chv.cgi?CH=167453 Change 167453 by dforsyth@squirrel on 2009/08/17 18:35:47 Macro list realloc Affected files ... .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb_read.c#7 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest.c#7 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest_plist.c#8 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.h#16 edit Differences ... ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_db_hierdb_read.c#7 (text+ko) ==== @@ -228,11 +228,17 @@ if (!pkg_db_hierdb_file_exists(db, p, REQUIRED_BY_FILE)) return (PKG_OK); /* +REQUIRED_BY doesn't have to exist. */ - + + list = NULL; reqdby_stream = pkg_db_hierdb_open_file_stream_read(db, p, REQUIRED_BY_FILE); for (count = 0, reqdby = NULL; fgets(line, FILENAME_MAX, reqdby_stream) != NULL;) { pkg_util_trim_newline(line); - STRING_LIST_APPEND(reqdby, line, list, count, 10); + LIST_FACTOR_REALLOC(reqdby, list, count, 10); + if (reqdby == NULL) { + for (reqdby = list; count; count--) + free(reqdby[count - 1]); + return (PKG_MEMORY_ERR | PKG_NOT_OK); + } } fclose(reqdby_stream); ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest.c#7 (text+ko) ==== @@ -340,82 +340,79 @@ /* Add command strings to a package. Do not sort. */ -/* Add an exec command to a manifest, which will be run at install time. Returns the - * status of the operation. */ +/* Add an exec command to a manifest, which will be run at install time. Returns + * index of new cmd if successful, -1 otherwise. */ int pkg_manifest_add_exec_cmd(struct pkg_manifest *pm, const char *cmd) { - int status; char **list; pkg_error_null_argument("command", cmd, __func__); + + list = NULL; + LIST_FACTOR_REALLOC(pm->exec_list, list, pm->exec_count, 10); + if (pm->exec_list == NULL) { + pm->exec_list = list; + return (-1); + } + if (pkg_util_strdup(cmd, &pm->exec_list[pm->exec_count - 1]) != PKG_OK) + return (-1); - if (pm->exec_count % 10 == 0) { - list = pm->exec_list; - pm->exec_list = realloc(list, sizeof(*list) * (pm->exec_count + 11)); - if (pm->exec_list == NULL) { - pm->exec_list = list; - return (PKG_MEMORY_ERR | PKG_NOT_OK); - } - } - - status = pkg_util_strdup(cmd, &pm->exec_list[pm->exec_count++]); pm->exec_list[pm->exec_count] = NULL; - return (status); + return (pm->exec_count - 1); } /* Add an unexec command to a manifest, which will be executed at deinstall time. - * Returns the status of the operation. */ + * Return index of new cmd if successful, -1 otherwise. */ int pkg_manifest_add_unexec_cmd(struct pkg_manifest *pm, const char *cmd) { - int status; char **list; pkg_error_null_argument("command", cmd, __func__); - if (pm->unexec_count % 10 == 0) { - list = pm->unexec_list; - pm->unexec_list = realloc(list, sizeof(*list) * (pm->unexec_count + 11)); - if (pm->unexec_list == NULL) { - pm->unexec_list = list; - return (PKG_MEMORY_ERR | PKG_NOT_OK); - } + list = NULL; + LIST_FACTOR_REALLOC(pm->unexec_list, list, pm->unexec_count, 10); + if (pm->unexec_list == NULL) { + pm->unexec_list = list; + return (-1); } - status = pkg_util_strdup(cmd, &pm->unexec_list[pm->unexec_count++]); + if (pkg_util_strdup(cmd, &pm->unexec_list[pm->unexec_count - 1]) != PKG_OK) + return (-1); + pm->unexec_list[pm->unexec_count] = NULL; - return (status); + return (pm->unexec_count - 1); } /* Add a dirrm command to a manifest that will remove the directory dir at deinstall - * time. Returns the status of the operation. */ + * time. Return index of new cmd if successful, -1 otherwise. */ int pkg_manifest_add_dirrm_cmd(struct pkg_manifest *pm, const char *dir) { - int status; char **list; pkg_error_null_argument("directory", dir, __func__); + + list = NULL; + LIST_FACTOR_REALLOC(pm->dirrm_list, list, pm->dirrm_count, 10); + if (pm->dirrm_list == NULL) { + pm->dirrm_list = list; + return (-1); + } - if (pm->dirrm_count % 10 == 0) { - list = pm->dirrm_list; - pm->dirrm_list = realloc(list, sizeof(*list) * (pm->dirrm_count + 11)); - if (pm->dirrm_list == NULL) { - pm->dirrm_list = list; - return (PKG_MEMORY_ERR | PKG_NOT_OK); - } - } + + if (pkg_util_strdup(dir, &pm->dirrm_list[pm->dirrm_count - 1]) != PKG_OK) + return (-1); - status = pkg_util_strdup(dir, &pm->dirrm_list[pm->dirrm_count++]); pm->dirrm_list[pm->dirrm_count] = NULL; - return (status); + return (pm->dirrm_count - 1); } void ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_manifest_plist.c#8 (text+ko) ==== @@ -253,7 +253,7 @@ status = PKG_NOT_OK; break; } - status = pkg_manifest_add_exec_cmd(pm, argument); + pkg_manifest_add_exec_cmd(pm, argument); break; case (PM_UNEXEC): if (strlen(argument) == 0) { @@ -261,7 +261,7 @@ status = PKG_NOT_OK; break; } - status = pkg_manifest_add_unexec_cmd(pm, argument); + pkg_manifest_add_unexec_cmd(pm, argument); break; case (PM_MODE): status = (strlen(isolate) == 0) ? @@ -317,7 +317,7 @@ status = PKG_NOT_OK; break; } - status = pkg_manifest_add_dirrm_cmd(pm, isolate); + pkg_manifest_add_dirrm_cmd(pm, isolate); break; case (PM_MTREE): if (strlen(isolate) == 0) { ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_util.h#16 (text+ko) ==== @@ -19,15 +19,13 @@ void rage_quit(void); -#define STRING_LIST_APPEND(list, append, tmp_list, list_sz, factor) \ +#define LIST_FACTOR_REALLOC(list, tmp_list, list_sz, factor) \ if (list_sz % factor == 0) { \ tmp_list = list; \ list = realloc(tmp_list, sizeof(*tmp_list) * (list_sz + factor + 1)); \ } \ - if (list != NULL) { \ - list[list_sz++] = strdup(append); \ - list[list_sz] = NULL; \ - } + if (list != NULL) \ + list_sz++ #define ARRAY_FACTOR_REALLOC(array, tmp_array, array_sz, factor) \ if (array_sz % factor == 0) { \