[pacman-dev] [RFC, PATCHES]: Very preliminary work towards clean build with clang -Weverything
First of all, don't worry; I'm under no illusion that the pie-in-the-sky Subject line is anything that will happen in the near future, nor even necessarily a goal for the project (given just how finicky -Weverything is). Basically, I'm wondering whether sporadic patches addressing the sorts of things "clang -Weverything" gripes about would be considered welcome contributions, or nitpicking. By "sporadic patches", I mean that any of this sort from me would come when I felt like working on a coding project but didn't have anything particularly in mind. As a sample, I've made two patches addressing some of its earliest warnings. The first changes several headers to (say) #define IDENTIFIERS rather than _IDENTIFIERS. The second adds ALPM_ERR_OK = 0 to the _alpm_err_t enum. Some functions which return an _alpm_err_t return value were returning 0 on success, but there was no 0 value enumerated--not actively harmful, but still an oddity. If this sort of thing isn't of interest, I definitely get it. I just figured that an RFC with patches attached would provide something more concrete to discuss than one without. Cheers, Ivy
From: Ivy Foster <ivy.foster@gmail.com> Signed-off-by: Ivy Foster <ivy.foster@gmail.com> --- lib/libalpm/add.h | 6 +++--- lib/libalpm/alpm.h | 6 +++--- lib/libalpm/alpm_list.h | 6 +++--- lib/libalpm/backup.h | 6 +++--- lib/libalpm/base64.h | 4 ++-- lib/libalpm/conflict.h | 6 +++--- lib/libalpm/db.h | 6 +++--- lib/libalpm/delta.h | 6 +++--- lib/libalpm/deps.h | 6 +++--- lib/libalpm/diskspace.h | 6 +++--- lib/libalpm/dload.h | 6 +++--- lib/libalpm/filelist.h | 6 +++--- lib/libalpm/graph.h | 6 +++--- lib/libalpm/group.h | 6 +++--- lib/libalpm/handle.h | 6 +++--- lib/libalpm/hook.h | 6 +++--- lib/libalpm/libarchive-compat.h | 6 +++--- lib/libalpm/log.h | 6 +++--- lib/libalpm/md5.h | 4 ++-- lib/libalpm/package.h | 6 +++--- lib/libalpm/pkghash.h | 6 +++--- lib/libalpm/remove.h | 6 +++--- lib/libalpm/sha2.h | 4 ++-- lib/libalpm/signing.h | 6 +++--- lib/libalpm/sync.h | 6 +++--- lib/libalpm/trans.h | 6 +++--- lib/libalpm/util.h | 6 +++--- src/common/ini.h | 6 +++--- src/common/util-common.h | 6 +++--- src/pacman/callback.h | 6 +++--- src/pacman/check.h | 6 +++--- src/pacman/conf.h | 6 +++--- src/pacman/package.h | 6 +++--- src/pacman/pacman.h | 6 +++--- src/pacman/sighandler.h | 6 +++--- src/pacman/util.h | 6 +++--- 36 files changed, 105 insertions(+), 105 deletions(-) diff --git a/lib/libalpm/add.h b/lib/libalpm/add.h index aa707fa..c1ab62a 100644 --- a/lib/libalpm/add.h +++ b/lib/libalpm/add.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_ADD_H -#define _ALPM_ADD_H +#ifndef ALPM_ADD_H +#define ALPM_ADD_H #include "db.h" #include "alpm_list.h" @@ -26,6 +26,6 @@ int _alpm_upgrade_packages(alpm_handle_t *handle); -#endif /* _ALPM_ADD_H */ +#endif /* ALPM_ADD_H */ /* vim: set noet: */ diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 168d71b..7955585 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -20,8 +20,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_H -#define _ALPM_H +#ifndef ALPM_H +#define ALPM_H #ifdef __cplusplus extern "C" { @@ -1624,6 +1624,6 @@ void alpm_conflict_free(alpm_conflict_t *conflict); #ifdef __cplusplus } #endif -#endif /* _ALPM_H */ +#endif /* ALPM_H */ /* vim: set noet: */ diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h index 5af84e1..cf7d463 100644 --- a/lib/libalpm/alpm_list.h +++ b/lib/libalpm/alpm_list.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_LIST_H -#define _ALPM_LIST_H +#ifndef ALPM_LIST_H +#define ALPM_LIST_H #include <stdlib.h> /* size_t */ @@ -90,6 +90,6 @@ void *alpm_list_to_array(const alpm_list_t *list, size_t n, size_t size); #ifdef __cplusplus } #endif -#endif /* _ALPM_LIST_H */ +#endif /* ALPM_LIST_H */ /* vim: set noet: */ diff --git a/lib/libalpm/backup.h b/lib/libalpm/backup.h index 2e11dbc..5cf3f90 100644 --- a/lib/libalpm/backup.h +++ b/lib/libalpm/backup.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_BACKUP_H -#define _ALPM_BACKUP_H +#ifndef ALPM_BACKUP_H +#define ALPM_BACKUP_H #include "alpm_list.h" #include "alpm.h" @@ -28,6 +28,6 @@ alpm_backup_t *_alpm_needbackup(const char *file, alpm_pkg_t *pkg); void _alpm_backup_free(alpm_backup_t *backup); alpm_backup_t *_alpm_backup_dup(const alpm_backup_t *backup); -#endif /* _ALPM_BACKUP_H */ +#endif /* ALPM_BACKUP_H */ /* vim: set noet: */ diff --git a/lib/libalpm/base64.h b/lib/libalpm/base64.h index df684ab..9edb864 100644 --- a/lib/libalpm/base64.h +++ b/lib/libalpm/base64.h @@ -22,8 +22,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _BASE64_H -#define _BASE64_H +#ifndef BASE64_H +#define BASE64_H #include <string.h> diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h index e17d552..801c201 100644 --- a/lib/libalpm/conflict.h +++ b/lib/libalpm/conflict.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_CONFLICT_H -#define _ALPM_CONFLICT_H +#ifndef ALPM_CONFLICT_H +#define ALPM_CONFLICT_H #include "alpm.h" #include "db.h" @@ -30,6 +30,6 @@ alpm_list_t *_alpm_outerconflicts(alpm_db_t *db, alpm_list_t *packages); alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, alpm_list_t *upgrade, alpm_list_t *remove); -#endif /* _ALPM_CONFLICT_H */ +#endif /* ALPM_CONFLICT_H */ /* vim: set noet: */ diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index 05ef43e..e696298 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -19,8 +19,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_DB_H -#define _ALPM_DB_H +#ifndef ALPM_DB_H +#define ALPM_DB_H /* libarchive */ #include <archive.h> @@ -107,6 +107,6 @@ alpm_pkg_t *_alpm_db_get_pkgfromcache(alpm_db_t *db, const char *target); alpm_list_t *_alpm_db_get_groupcache(alpm_db_t *db); alpm_group_t *_alpm_db_get_groupfromcache(alpm_db_t *db, const char *target); -#endif /* _ALPM_DB_H */ +#endif /* ALPM_DB_H */ /* vim: set noet: */ diff --git a/lib/libalpm/delta.h b/lib/libalpm/delta.h index c7bbade..26c3c4c 100644 --- a/lib/libalpm/delta.h +++ b/lib/libalpm/delta.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_DELTA_H -#define _ALPM_DELTA_H +#ifndef ALPM_DELTA_H +#define ALPM_DELTA_H #include <sys/types.h> /* off_t */ @@ -30,6 +30,6 @@ alpm_delta_t *_alpm_delta_dup(const alpm_delta_t *delta); off_t _alpm_shortest_delta_path(alpm_handle_t *handle, alpm_list_t *deltas, const char *to, alpm_list_t **path); -#endif /* _ALPM_DELTA_H */ +#endif /* ALPM_DELTA_H */ /* vim: set noet: */ diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h index 691f505..91c6eb6 100644 --- a/lib/libalpm/deps.h +++ b/lib/libalpm/deps.h @@ -19,8 +19,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_DEPS_H -#define _ALPM_DEPS_H +#ifndef ALPM_DEPS_H +#define ALPM_DEPS_H #include "db.h" #include "sync.h" @@ -38,6 +38,6 @@ int _alpm_depcmp_literal(alpm_pkg_t *pkg, alpm_depend_t *dep); int _alpm_depcmp_provides(alpm_depend_t *dep, alpm_list_t *provisions); int _alpm_depcmp(alpm_pkg_t *pkg, alpm_depend_t *dep); -#endif /* _ALPM_DEPS_H */ +#endif /* ALPM_DEPS_H */ /* vim: set noet: */ diff --git a/lib/libalpm/diskspace.h b/lib/libalpm/diskspace.h index acda05a..8c0e4e6 100644 --- a/lib/libalpm/diskspace.h +++ b/lib/libalpm/diskspace.h @@ -17,8 +17,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_DISKSPACE_H -#define _ALPM_DISKSPACE_H +#ifndef ALPM_DISKSPACE_H +#define ALPM_DISKSPACE_H #if defined(HAVE_SYS_MOUNT_H) #include <sys/mount.h> @@ -60,6 +60,6 @@ int _alpm_check_diskspace(alpm_handle_t *handle); int _alpm_check_downloadspace(alpm_handle_t *handle, const char *cachedir, size_t num_files, off_t *file_sizes); -#endif /* _ALPM_DISKSPACE_H */ +#endif /* ALPM_DISKSPACE_H */ /* vim: set noet: */ diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h index 60843bd..427c486 100644 --- a/lib/libalpm/dload.h +++ b/lib/libalpm/dload.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_DLOAD_H -#define _ALPM_DLOAD_H +#ifndef ALPM_DLOAD_H +#define ALPM_DLOAD_H #include "alpm_list.h" #include "alpm.h" @@ -51,6 +51,6 @@ void _alpm_dload_payload_reset(struct dload_payload *payload); int _alpm_download(struct dload_payload *payload, const char *localpath, char **final_file, const char **final_url); -#endif /* _ALPM_DLOAD_H */ +#endif /* ALPM_DLOAD_H */ /* vim: set noet: */ diff --git a/lib/libalpm/filelist.h b/lib/libalpm/filelist.h index 5560ea0..a74bdea 100644 --- a/lib/libalpm/filelist.h +++ b/lib/libalpm/filelist.h @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_FILELIST_H -#define _ALPM_FILELIST_H +#ifndef ALPM_FILELIST_H +#define ALPM_FILELIST_H #include "alpm.h" @@ -29,6 +29,6 @@ alpm_list_t *_alpm_filelist_intersection(alpm_filelist_t *filesA, int _alpm_files_cmp(const void *f1, const void *f2); -#endif /* _ALPM_FILELIST_H */ +#endif /* ALPM_FILELIST_H */ /* vim: set noet: */ diff --git a/lib/libalpm/graph.h b/lib/libalpm/graph.h index 76a268a..22f0aa9 100644 --- a/lib/libalpm/graph.h +++ b/lib/libalpm/graph.h @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_GRAPH_H -#define _ALPM_GRAPH_H +#ifndef ALPM_GRAPH_H +#define ALPM_GRAPH_H #include <sys/types.h> /* off_t */ @@ -35,6 +35,6 @@ typedef struct __alpm_graph_t { alpm_graph_t *_alpm_graph_new(void); void _alpm_graph_free(void *data); -#endif /* _ALPM_GRAPH_H */ +#endif /* ALPM_GRAPH_H */ /* vim: set noet: */ diff --git a/lib/libalpm/group.h b/lib/libalpm/group.h index 1db4e36..aa33076 100644 --- a/lib/libalpm/group.h +++ b/lib/libalpm/group.h @@ -17,14 +17,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_GROUP_H -#define _ALPM_GROUP_H +#ifndef ALPM_GROUP_H +#define ALPM_GROUP_H #include "alpm.h" alpm_group_t *_alpm_group_new(const char *name); void _alpm_group_free(alpm_group_t *grp); -#endif /* _ALPM_GROUP_H */ +#endif /* ALPM_GROUP_H */ /* vim: set noet: */ diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index a1d0f9a..ecbe837 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_HANDLE_H -#define _ALPM_HANDLE_H +#ifndef ALPM_HANDLE_H +#define ALPM_HANDLE_H #include <stdio.h> #include <sys/types.h> @@ -123,6 +123,6 @@ int _alpm_handle_unlock(alpm_handle_t *handle); alpm_errno_t _alpm_set_directory_option(const char *value, char **storage, int must_exist); -#endif /* _ALPM_HANDLE_H */ +#endif /* ALPM_HANDLE_H */ /* vim: set noet: */ diff --git a/lib/libalpm/hook.h b/lib/libalpm/hook.h index 01eb3ed..f33dfe1 100644 --- a/lib/libalpm/hook.h +++ b/lib/libalpm/hook.h @@ -17,13 +17,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_HOOK_H -#define _ALPM_HOOK_H +#ifndef ALPM_HOOK_H +#define ALPM_HOOK_H #include "alpm.h" int _alpm_hook_run(alpm_handle_t *handle, alpm_hook_when_t when); -#endif /* _ALPM_HOOK_H */ +#endif /* ALPM_HOOK_H */ /* vim: set noet: */ diff --git a/lib/libalpm/libarchive-compat.h b/lib/libalpm/libarchive-compat.h index 3b46a5a..d4aa4fa 100644 --- a/lib/libalpm/libarchive-compat.h +++ b/lib/libalpm/libarchive-compat.h @@ -1,5 +1,5 @@ -#ifndef _LIBARCHIVE_COMPAT_H -#define _LIBARCHIVE_COMPAT_H +#ifndef LIBARCHIVE_COMPAT_H +#define LIBARCHIVE_COMPAT_H /* * libarchive-compat.h @@ -68,6 +68,6 @@ static inline int _alpm_archive_read_support_filter_all(struct archive *archive) #endif } -#endif /* _LIBARCHIVE_COMPAT_H */ +#endif /* LIBARCHIVE_COMPAT_H */ /* vim: set noet: */ diff --git a/lib/libalpm/log.h b/lib/libalpm/log.h index 3fd6196..79074fc 100644 --- a/lib/libalpm/log.h +++ b/lib/libalpm/log.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_LOG_H -#define _ALPM_LOG_H +#ifndef ALPM_LOG_H +#define ALPM_LOG_H #include "alpm.h" @@ -27,6 +27,6 @@ void _alpm_log(alpm_handle_t *handle, alpm_loglevel_t flag, const char *fmt, ...) __attribute__((format(printf,3,4))); -#endif /* _ALPM_LOG_H */ +#endif /* ALPM_LOG_H */ /* vim: set noet: */ diff --git a/lib/libalpm/md5.h b/lib/libalpm/md5.h index d03013a..4a6fe4d 100644 --- a/lib/libalpm/md5.h +++ b/lib/libalpm/md5.h @@ -21,8 +21,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _MD5_H -#define _MD5_H +#ifndef MD5_H +#define MD5_H #include <string.h> diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index 31add9a..114d225 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -21,8 +21,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_PACKAGE_H -#define _ALPM_PACKAGE_H +#ifndef ALPM_PACKAGE_H +#define ALPM_PACKAGE_H #include <sys/types.h> /* off_t */ @@ -153,6 +153,6 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, int _alpm_pkg_cmp(const void *p1, const void *p2); int _alpm_pkg_compare_versions(alpm_pkg_t *local_pkg, alpm_pkg_t *pkg); -#endif /* _ALPM_PACKAGE_H */ +#endif /* ALPM_PACKAGE_H */ /* vim: set noet: */ diff --git a/lib/libalpm/pkghash.h b/lib/libalpm/pkghash.h index c843a43..be064f6 100644 --- a/lib/libalpm/pkghash.h +++ b/lib/libalpm/pkghash.h @@ -17,8 +17,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_PKGHASH_H -#define _ALPM_PKGHASH_H +#ifndef ALPM_PKGHASH_H +#define ALPM_PKGHASH_H #include <stdlib.h> @@ -57,4 +57,4 @@ void _alpm_pkghash_free(alpm_pkghash_t *hash); alpm_pkg_t *_alpm_pkghash_find(alpm_pkghash_t *hash, const char *name); -#endif /* _ALPM_PKGHASH_H */ +#endif /* ALPM_PKGHASH_H */ diff --git a/lib/libalpm/remove.h b/lib/libalpm/remove.h index e6e1b22..b26ea60 100644 --- a/lib/libalpm/remove.h +++ b/lib/libalpm/remove.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_REMOVE_H -#define _ALPM_REMOVE_H +#ifndef ALPM_REMOVE_H +#define ALPM_REMOVE_H #include "db.h" #include "alpm_list.h" @@ -31,6 +31,6 @@ int _alpm_remove_single_package(alpm_handle_t *handle, alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg, size_t targ_count, size_t pkg_count); -#endif /* _ALPM_REMOVE_H */ +#endif /* ALPM_REMOVE_H */ /* vim: set noet: */ diff --git a/lib/libalpm/sha2.h b/lib/libalpm/sha2.h index 887b9c6..99267de 100644 --- a/lib/libalpm/sha2.h +++ b/lib/libalpm/sha2.h @@ -21,8 +21,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _SHA2_H -#define _SHA2_H +#ifndef SHA2_H +#define SHA2_H #include <string.h> diff --git a/lib/libalpm/signing.h b/lib/libalpm/signing.h index 9e12cfa..960b644 100644 --- a/lib/libalpm/signing.h +++ b/lib/libalpm/signing.h @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_SIGNING_H -#define _ALPM_SIGNING_H +#ifndef ALPM_SIGNING_H +#define ALPM_SIGNING_H #include "alpm.h" @@ -34,6 +34,6 @@ int _alpm_process_siglist(alpm_handle_t *handle, const char *identifier, int _alpm_key_in_keychain(alpm_handle_t *handle, const char *fpr); int _alpm_key_import(alpm_handle_t *handle, const char *fpr); -#endif /* _ALPM_SIGNING_H */ +#endif /* ALPM_SIGNING_H */ /* vim: set noet: */ diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h index f6c610e..1aa48b7 100644 --- a/lib/libalpm/sync.h +++ b/lib/libalpm/sync.h @@ -19,8 +19,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_SYNC_H -#define _ALPM_SYNC_H +#ifndef ALPM_SYNC_H +#define ALPM_SYNC_H #include "alpm.h" @@ -29,6 +29,6 @@ int _alpm_sync_load(alpm_handle_t *handle, alpm_list_t **data); int _alpm_sync_check(alpm_handle_t *handle, alpm_list_t **data); int _alpm_sync_commit(alpm_handle_t *handle); -#endif /* _ALPM_SYNC_H */ +#endif /* ALPM_SYNC_H */ /* vim: set noet: */ diff --git a/lib/libalpm/trans.h b/lib/libalpm/trans.h index d2eb681..73111be 100644 --- a/lib/libalpm/trans.h +++ b/lib/libalpm/trans.h @@ -20,8 +20,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_TRANS_H -#define _ALPM_TRANS_H +#ifndef ALPM_TRANS_H +#define ALPM_TRANS_H #include "alpm.h" @@ -50,6 +50,6 @@ int _alpm_trans_init(alpm_trans_t *trans, alpm_transflag_t flags); int _alpm_runscriptlet(alpm_handle_t *handle, const char *filepath, const char *script, const char *ver, const char *oldver, int is_archive); -#endif /* _ALPM_TRANS_H */ +#endif /* ALPM_TRANS_H */ /* vim: set noet: */ diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 9494986..5a2c105 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -21,8 +21,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_UTIL_H -#define _ALPM_UTIL_H +#ifndef ALPM_UTIL_H +#define ALPM_UTIL_H #include "alpm_list.h" #include "alpm.h" @@ -156,6 +156,6 @@ char *strsep(char **, const char *); #define UNUSED __attribute__((unused)) -#endif /* _ALPM_UTIL_H */ +#endif /* ALPM_UTIL_H */ /* vim: set noet: */ diff --git a/src/common/ini.h b/src/common/ini.h index 2b4f79d..e03a83f 100644 --- a/src/common/ini.h +++ b/src/common/ini.h @@ -17,14 +17,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_INI_H -#define _PM_INI_H +#ifndef PM_INI_H +#define PM_INI_H typedef int (ini_parser_fn)(const char *file, int line, const char *section, char *key, char *value, void *data); int parse_ini(const char *file, ini_parser_fn cb, void *data); -#endif /* _PM_CONF_H */ +#endif /* PM_INI_H */ /* vim: set noet: */ diff --git a/src/common/util-common.h b/src/common/util-common.h index 9df6a70..1452094 100644 --- a/src/common/util-common.h +++ b/src/common/util-common.h @@ -17,8 +17,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_UTIL_COMMON_H -#define _PM_UTIL_COMMON_H +#ifndef PM_UTIL_COMMON_H +#define PM_UTIL_COMMON_H #include <stdio.h> #include <sys/stat.h> /* struct stat */ @@ -38,6 +38,6 @@ char *strndup(const char *s, size_t n); #define ARRAYSIZE(a) (sizeof (a) / sizeof (a[0])) -#endif /* _PM_UTIL_COMMON_H */ +#endif /* PM_UTIL_COMMON_H */ /* vim: set noet: */ diff --git a/src/pacman/callback.h b/src/pacman/callback.h index fc83fb7..ad395e9 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_CALLBACK_H -#define _PM_CALLBACK_H +#ifndef PM_CALLBACK_H +#define PM_CALLBACK_H #include <sys/types.h> /* off_t */ @@ -43,6 +43,6 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total); __attribute__((format(printf, 2, 0))) void cb_log(alpm_loglevel_t level, const char *fmt, va_list args); -#endif /* _PM_CALLBACK_H */ +#endif /* PM_CALLBACK_H */ /* vim: set noet: */ diff --git a/src/pacman/check.h b/src/pacman/check.h index 362a352..5052376 100644 --- a/src/pacman/check.h +++ b/src/pacman/check.h @@ -17,14 +17,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_CHECK_H -#define _PM_CHECK_H +#ifndef PM_CHECK_H +#define PM_CHECK_H #include <alpm.h> int check_pkg_fast(alpm_pkg_t *pkg); int check_pkg_full(alpm_pkg_t *pkg); -#endif /* _PM_CHECK_H */ +#endif /* PM_CHECK_H */ /* vim: set noet: */ diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 2aba8bf..2ddeadb 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_CONF_H -#define _PM_CONF_H +#ifndef PM_CONF_H +#define PM_CONF_H #include <alpm.h> @@ -234,6 +234,6 @@ void config_repo_free(config_repo_t *repo); int config_set_arch(const char *arch); int parseconfig(const char *file); -#endif /* _PM_CONF_H */ +#endif /* PM_CONF_H */ /* vim: set noet: */ diff --git a/src/pacman/package.h b/src/pacman/package.h index e369330..3129a73 100644 --- a/src/pacman/package.h +++ b/src/pacman/package.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_PACKAGE_H -#define _PM_PACKAGE_H +#ifndef PM_PACKAGE_H +#define PM_PACKAGE_H #include <alpm.h> @@ -31,6 +31,6 @@ void dump_pkg_changelog(alpm_pkg_t *pkg); void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg); int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status); -#endif /* _PM_PACKAGE_H */ +#endif /* PM_PACKAGE_H */ /* vim: set noet: */ diff --git a/src/pacman/pacman.h b/src/pacman/pacman.h index edb81b1..84f70a6 100644 --- a/src/pacman/pacman.h +++ b/src/pacman/pacman.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_PACMAN_H -#define _PM_PACMAN_H +#ifndef PM_PACMAN_H +#define PM_PACMAN_H #include <alpm_list.h> @@ -40,6 +40,6 @@ int sync_prepare_execute(void); /* upgrade.c */ int pacman_upgrade(alpm_list_t *targets); -#endif /* _PM_PACMAN_H */ +#endif /* PM_PACMAN_H */ /* vim: set noet: */ diff --git a/src/pacman/sighandler.h b/src/pacman/sighandler.h index 3fddaee..108a7e0 100644 --- a/src/pacman/sighandler.h +++ b/src/pacman/sighandler.h @@ -17,14 +17,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_SIGHANDLER_H -#define _PM_SIGHANDLER_H +#ifndef PM_SIGHANDLER_H +#define PM_SIGHANDLER_H void install_segv_handler(void); void install_winch_handler(void); void install_soft_interrupt_handler(void); void remove_soft_interrupt_handler(void); -#endif /* _PM_SIGHANDLER_H */ +#endif /* PM_SIGHANDLER_H */ /* vim: set noet: */ diff --git a/src/pacman/util.h b/src/pacman/util.h index f5e37c8..74ce4cb 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_UTIL_H -#define _PM_UTIL_H +#ifndef PM_UTIL_H +#define PM_UTIL_H #include <stdlib.h> #include <stdarg.h> @@ -82,6 +82,6 @@ int pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, va_list int pm_sprintf(char **string, alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,3,4))); int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); -#endif /* _PM_UTIL_H */ +#endif /* PM_UTIL_H */ /* vim: set noet: */ -- 2.9.3
From: Ivy Foster <ivy.foster@gmail.com> Functions that expect an _alpm_err_t can now get a true one, even on success. Since previous practice was to return 0 (not included in the _alpm_err_t enum type), anything that just checks !err or (err == 0) should work as is. Signed-off-by: Ivy Foster <ivy.foster@gmail.com> --- lib/libalpm/alpm.h | 3 +- lib/libalpm/be_package.c | 2 +- lib/libalpm/be_sync.c | 4 +-- lib/libalpm/db.c | 18 +++++------ lib/libalpm/dload.c | 2 +- lib/libalpm/package.c | 78 ++++++++++++++++++++++++------------------------ lib/libalpm/signing.c | 6 ++-- lib/libalpm/sync.c | 8 ++--- lib/libalpm/util.h | 2 +- 9 files changed, 62 insertions(+), 61 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 7955585..0f8274b 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -53,7 +53,8 @@ typedef struct __alpm_trans_t alpm_trans_t; * @{ */ typedef enum _alpm_errno_t { - ALPM_ERR_MEMORY = 1, + ALPM_ERR_OK = 0, + ALPM_ERR_MEMORY, ALPM_ERR_SYSTEM, ALPM_ERR_BADPERMS, ALPM_ERR_NOT_A_FILE, diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index 430d2ae..befcba3 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -274,7 +274,7 @@ int _alpm_pkg_validate_internal(alpm_handle_t *handle, alpm_siglist_t **sigdata, alpm_pkgvalidation_t *validation) { int has_sig; - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; if(pkgfile == NULL || strlen(pkgfile) == 0) { RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1); diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 32a669d..2cd722e 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -186,7 +186,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) /* Sanity checks */ ASSERT(db != NULL, return -1); handle = db->handle; - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; ASSERT(db != handle->db_local, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1)); ASSERT(db->servers != NULL, RET_ERR(handle, ALPM_ERR_SERVER_NONE, -1)); @@ -320,7 +320,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) _alpm_log(handle, ALPM_LOG_DEBUG, "failed to sync db: %s\n", alpm_strerror(handle->pm_errno)); } else { - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; } _alpm_handle_unlock(handle); diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index f70f83c..6e04adb 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -112,7 +112,7 @@ int SYMEXPORT alpm_db_unregister(alpm_db_t *db) ASSERT(db != NULL, return -1); /* Do not unregister a database if a transaction is on-going */ handle = db->handle; - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, -1)); if(db == handle->db_local) { @@ -179,7 +179,7 @@ int SYMEXPORT alpm_db_add_server(alpm_db_t *db, const char *url) /* Sanity checks */ ASSERT(db != NULL, return -1); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1)); newurl = sanitize_url(url); @@ -206,7 +206,7 @@ int SYMEXPORT alpm_db_remove_server(alpm_db_t *db, const char *url) /* Sanity checks */ ASSERT(db != NULL, return -1); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1)); newurl = sanitize_url(url); @@ -249,7 +249,7 @@ alpm_siglevel_t SYMEXPORT alpm_db_get_siglevel(alpm_db_t *db) int SYMEXPORT alpm_db_get_valid(alpm_db_t *db) { ASSERT(db != NULL, return -1); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return db->ops->validate(db); } @@ -258,7 +258,7 @@ alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const char *name) { alpm_pkg_t *pkg; ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(name != NULL && strlen(name) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL)); @@ -273,7 +273,7 @@ alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const char *name) alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(alpm_db_t *db) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return _alpm_db_get_pkgcache(db); } @@ -281,7 +281,7 @@ alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(alpm_db_t *db) alpm_group_t SYMEXPORT *alpm_db_get_group(alpm_db_t *db, const char *name) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(name != NULL && strlen(name) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL)); @@ -292,7 +292,7 @@ alpm_group_t SYMEXPORT *alpm_db_get_group(alpm_db_t *db, const char *name) alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t *db) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return _alpm_db_get_groupcache(db); } @@ -301,7 +301,7 @@ alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t *db) alpm_list_t SYMEXPORT *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return _alpm_db_search(db, needles); } diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index f4e6a27..10e4a0d 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -412,7 +412,7 @@ static int curl_download_internal(struct dload_payload *payload, /* shortcut to our handle within the payload */ alpm_handle_t *handle = payload->handle; CURL *curl = get_libcurl_handle(handle); - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; /* make sure these are NULL */ FREE(payload->tempfile_name); diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index f08df8b..a666bf0 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -60,7 +60,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg) int retval; ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; /* We only inspect packages from sync repositories */ ASSERT(pkg->origin == ALPM_PKG_FROM_SYNCDB, RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1)); @@ -184,196 +184,196 @@ struct pkg_operations default_pkg_ops = { const char SYMEXPORT *alpm_pkg_get_filename(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->filename; } const char SYMEXPORT *alpm_pkg_get_base(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_base(pkg); } const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->name; } const char SYMEXPORT *alpm_pkg_get_version(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->version; } alpm_pkgfrom_t SYMEXPORT alpm_pkg_get_origin(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->origin; } const char SYMEXPORT *alpm_pkg_get_desc(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_desc(pkg); } const char SYMEXPORT *alpm_pkg_get_url(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_url(pkg); } alpm_time_t SYMEXPORT alpm_pkg_get_builddate(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_builddate(pkg); } alpm_time_t SYMEXPORT alpm_pkg_get_installdate(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_installdate(pkg); } const char SYMEXPORT *alpm_pkg_get_packager(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_packager(pkg); } const char SYMEXPORT *alpm_pkg_get_md5sum(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->md5sum; } const char SYMEXPORT *alpm_pkg_get_sha256sum(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->sha256sum; } const char SYMEXPORT *alpm_pkg_get_base64_sig(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->base64_sig; } const char SYMEXPORT *alpm_pkg_get_arch(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_arch(pkg); } off_t SYMEXPORT alpm_pkg_get_size(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->size; } off_t SYMEXPORT alpm_pkg_get_isize(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_isize(pkg); } alpm_pkgreason_t SYMEXPORT alpm_pkg_get_reason(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_reason(pkg); } alpm_pkgvalidation_t SYMEXPORT alpm_pkg_get_validation(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_validation(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_licenses(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_licenses(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_groups(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_groups(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_depends(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_depends(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_optdepends(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_optdepends(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_conflicts(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_conflicts(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_provides(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_provides(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_replaces(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_replaces(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_deltas(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->deltas; } alpm_filelist_t SYMEXPORT *alpm_pkg_get_files(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_files(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_backup(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_backup(pkg); } @@ -382,7 +382,7 @@ alpm_db_t SYMEXPORT *alpm_pkg_get_db(alpm_pkg_t *pkg) /* Sanity checks */ ASSERT(pkg != NULL, return NULL); ASSERT(pkg->origin != ALPM_PKG_FROM_FILE, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->origin_data.db; } @@ -391,7 +391,7 @@ alpm_db_t SYMEXPORT *alpm_pkg_get_db(alpm_pkg_t *pkg) void SYMEXPORT *alpm_pkg_changelog_open(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->changelog_open(pkg); } @@ -400,7 +400,7 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, const alpm_pkg_t *pkg, void *fp) { ASSERT(pkg != NULL, return 0); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->changelog_read(ptr, size, pkg, fp); } @@ -408,7 +408,7 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, int SYMEXPORT alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->changelog_close(pkg, fp); } @@ -416,7 +416,7 @@ int SYMEXPORT alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp) struct archive SYMEXPORT *alpm_pkg_mtree_open(alpm_pkg_t * pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->mtree_open(pkg); } @@ -425,7 +425,7 @@ int SYMEXPORT alpm_pkg_mtree_next(const alpm_pkg_t * pkg, struct archive *archiv struct archive_entry **entry) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->mtree_next(pkg, archive, entry); } @@ -433,14 +433,14 @@ int SYMEXPORT alpm_pkg_mtree_next(const alpm_pkg_t * pkg, struct archive *archiv int SYMEXPORT alpm_pkg_mtree_close(const alpm_pkg_t * pkg, struct archive *archive) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->mtree_close(pkg, archive); } int SYMEXPORT alpm_pkg_has_scriptlet(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->has_scriptlet(pkg); } @@ -448,7 +448,7 @@ static void find_requiredby(alpm_pkg_t *pkg, alpm_db_t *db, alpm_list_t **reqs, int optional) { const alpm_list_t *i; - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { alpm_pkg_t *cachepkg = i->data; @@ -478,7 +478,7 @@ static alpm_list_t *compute_requiredby(alpm_pkg_t *pkg, int optional) alpm_db_t *db; ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; if(pkg->origin == ALPM_PKG_FROM_FILE) { /* The sane option; search locally for things that require this. */ diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c index 6557c20..527e763 100644 --- a/lib/libalpm/signing.c +++ b/lib/libalpm/signing.c @@ -771,7 +771,7 @@ int _alpm_check_pgp_helper(alpm_handle_t *handle, const char *path, if(ret && handle->pm_errno == ALPM_ERR_SIG_MISSING) { if(optional) { _alpm_log(handle, ALPM_LOG_DEBUG, "missing optional signature\n"); - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; ret = 0; } else { _alpm_log(handle, ALPM_LOG_DEBUG, "missing required signature\n"); @@ -931,7 +931,7 @@ int SYMEXPORT alpm_pkg_check_pgp_signature(alpm_pkg_t *pkg, { ASSERT(pkg != NULL, return -1); ASSERT(siglist != NULL, RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1)); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return _alpm_gpgme_checksig(pkg->handle, pkg->filename, pkg->base64_sig, siglist); @@ -948,7 +948,7 @@ int SYMEXPORT alpm_db_check_pgp_signature(alpm_db_t *db, { ASSERT(db != NULL, return -1); ASSERT(siglist != NULL, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1)); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return _alpm_gpgme_checksig(db->handle, _alpm_db_path(db), NULL, siglist); } diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 00b68d0..65c1bbc 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -57,7 +57,7 @@ alpm_pkg_t SYMEXPORT *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_syn alpm_pkg_t *spkg = NULL; ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; for(i = dbs_sync; !spkg && i; i = i->next) { alpm_db_t *db = i->data; @@ -460,7 +460,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) transaction. The packages will be removed from the actual transaction when the transaction packages are replaced with a dependency-reordered list below */ - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; if(data) { alpm_list_free_inner(*data, (alpm_list_fn_free)alpm_depmissing_free); @@ -1195,7 +1195,7 @@ static int check_validity(alpm_handle_t *handle, } alpm_list_free(errors); - if(!handle->pm_errno) { + if(handle->pm_errno == ALPM_ERR_OK) { RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1); } return -1; @@ -1280,7 +1280,7 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data, EVENT(handle, &event); if(errors) { - if(!handle->pm_errno) { + if(handle->pm_errno == ALPM_ERR_OK) { RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1); } return -1; diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 5a2c105..b9c5c17 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -77,7 +77,7 @@ void _alpm_alloc_fail(size_t size); #define DOUBLE_EQ(x, y) (fabs((x) - (y)) < DBL_EPSILON) -#define CHECK_HANDLE(handle, action) do { if(!(handle)) { action; } (handle)->pm_errno = 0; } while(0) +#define CHECK_HANDLE(handle, action) do { if(!(handle)) { action; } (handle)->pm_errno = ALPM_ERR_OK; } while(0) /** Standard buffer size used throughout the library. */ #ifdef BUFSIZ -- 2.9.3
All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use. All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces. (ISO 9899:1999, 7.1.3) Don't use such identifiers. As a matter of fact, typedefs, struct names and function names fall under this terminology. Despite the fact that the compiler accepts leading underscores, per standard they are explicitly discouraged. So, what we should consider is to move _alpm_errno_t along with all other names in the source tree away from leading underscores. Their visibility should be controlled by the presence of a static keyword, -fvisibility and such instead. You might want to write a sed script for this, and it looks like a major invasion into the codebase. The last word is with the developers, though, hence I'm not sure this is going to be accepted for traditional reasons. cheers! mar77i
On 03/09/16 12:08, ivy.foster@gmail.com wrote:
First of all, don't worry; I'm under no illusion that the pie-in-the-sky Subject line is anything that will happen in the near future, nor even necessarily a goal for the project (given just how finicky -Weverything is).
Basically, I'm wondering whether sporadic patches addressing the sorts of things "clang -Weverything" gripes about would be considered welcome contributions, or nitpicking. By "sporadic patches", I mean that any of this sort from me would come when I felt like working on a coding project but didn't have anything particularly in mind.
As a sample, I've made two patches addressing some of its earliest warnings. The first changes several headers to (say) #define IDENTIFIERS rather than _IDENTIFIERS. The second adds ALPM_ERR_OK = 0 to the _alpm_err_t enum. Some functions which return an _alpm_err_t return value were returning 0 on success, but there was no 0 value enumerated--not actively harmful, but still an oddity.
If this sort of thing isn't of interest, I definitely get it. I just figured that an RFC with patches attached would provide something more concrete to discuss than one without.
I am happy to accept these. When you fix a specific set of warnings from clang/gcc, you can add that specific warning flag (i.e. not -Weverything...) to our configure.ac at this section: # Enable or disable compiler warning flags AC_MSG_CHECKING(for excessive compiler warning flags) if test "x$warningflags" = "xyes" ; then AC_MSG_RESULT(yes) CFLAGS_ADD([-Wcast-align], [WARNING_CFLAGS]) CFLAGS_ADD([-Wclobbered], [WARNING_CFLAGS]) ... That way we will not regress in the future. Thanks, Allan
I've had another go at the patches from yesterday. The first patch, which eliminates use of #define _RESERVED_IDENTIFIERS, has one problem keeping me from adding -Wreserved-id-macro to configure.ac: the autoconf-generated file config.h.in contains one, _DARWIN_USE_64_BIT_INODE. I'm honestly not sure how to prevent autoconf from adding this, or how to make it print it at the very bottom after a "#pragma GCC system_header". The second is a much more complete version of the patch that added ALPM_ERR_OK. This version handles *every* enum type that is used by functions that return either a member of that enum or an error, and allows building cleanly with clang -Wassign-enum. The RFC in the subject is because for patch #2, I discovered that a common code pattern in pacman is using enum types to generate bitfields. Technically, the resulting bitfield isn't a member of the enum*, which caused many a warning with -Wassign-enum. As a quick and dirty solution, I declared these bitfield variables to be ints rather than (say) _alpm_siglevel_t. It encodes less information than declaring them as the enum type, but is technically more accurate. Would it be better to use unions or something? Comments welcome. Cheers. Ivy *: enum foo { BAR = 1 << 0, /* 01 */ BAZ = 1 << 1; /* 10 */ /* Not included: 11 */ }
From: Ivy Foster <ivy.foster@gmail.com> Signed-off-by: Ivy Foster <ivy.foster@gmail.com> --- lib/libalpm/add.h | 6 +++--- lib/libalpm/alpm.h | 6 +++--- lib/libalpm/alpm_list.h | 6 +++--- lib/libalpm/backup.h | 6 +++--- lib/libalpm/base64.h | 4 ++-- lib/libalpm/conflict.h | 6 +++--- lib/libalpm/db.h | 6 +++--- lib/libalpm/delta.h | 6 +++--- lib/libalpm/deps.h | 6 +++--- lib/libalpm/diskspace.h | 6 +++--- lib/libalpm/dload.h | 6 +++--- lib/libalpm/filelist.h | 6 +++--- lib/libalpm/graph.h | 6 +++--- lib/libalpm/group.h | 6 +++--- lib/libalpm/handle.h | 6 +++--- lib/libalpm/hook.h | 6 +++--- lib/libalpm/libarchive-compat.h | 6 +++--- lib/libalpm/log.h | 6 +++--- lib/libalpm/md5.h | 4 ++-- lib/libalpm/package.h | 6 +++--- lib/libalpm/pkghash.h | 6 +++--- lib/libalpm/remove.h | 6 +++--- lib/libalpm/sha2.h | 4 ++-- lib/libalpm/signing.h | 6 +++--- lib/libalpm/sync.h | 6 +++--- lib/libalpm/trans.h | 6 +++--- lib/libalpm/util.h | 6 +++--- src/common/ini.h | 6 +++--- src/common/util-common.h | 6 +++--- src/pacman/callback.h | 6 +++--- src/pacman/check.h | 6 +++--- src/pacman/conf.h | 6 +++--- src/pacman/package.h | 6 +++--- src/pacman/pacman.h | 6 +++--- src/pacman/sighandler.h | 6 +++--- src/pacman/util.h | 6 +++--- 36 files changed, 105 insertions(+), 105 deletions(-) diff --git a/lib/libalpm/add.h b/lib/libalpm/add.h index aa707fa..c1ab62a 100644 --- a/lib/libalpm/add.h +++ b/lib/libalpm/add.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_ADD_H -#define _ALPM_ADD_H +#ifndef ALPM_ADD_H +#define ALPM_ADD_H #include "db.h" #include "alpm_list.h" @@ -26,6 +26,6 @@ int _alpm_upgrade_packages(alpm_handle_t *handle); -#endif /* _ALPM_ADD_H */ +#endif /* ALPM_ADD_H */ /* vim: set noet: */ diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 168d71b..7955585 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -20,8 +20,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_H -#define _ALPM_H +#ifndef ALPM_H +#define ALPM_H #ifdef __cplusplus extern "C" { @@ -1624,6 +1624,6 @@ void alpm_conflict_free(alpm_conflict_t *conflict); #ifdef __cplusplus } #endif -#endif /* _ALPM_H */ +#endif /* ALPM_H */ /* vim: set noet: */ diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h index 5af84e1..cf7d463 100644 --- a/lib/libalpm/alpm_list.h +++ b/lib/libalpm/alpm_list.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_LIST_H -#define _ALPM_LIST_H +#ifndef ALPM_LIST_H +#define ALPM_LIST_H #include <stdlib.h> /* size_t */ @@ -90,6 +90,6 @@ void *alpm_list_to_array(const alpm_list_t *list, size_t n, size_t size); #ifdef __cplusplus } #endif -#endif /* _ALPM_LIST_H */ +#endif /* ALPM_LIST_H */ /* vim: set noet: */ diff --git a/lib/libalpm/backup.h b/lib/libalpm/backup.h index 2e11dbc..5cf3f90 100644 --- a/lib/libalpm/backup.h +++ b/lib/libalpm/backup.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_BACKUP_H -#define _ALPM_BACKUP_H +#ifndef ALPM_BACKUP_H +#define ALPM_BACKUP_H #include "alpm_list.h" #include "alpm.h" @@ -28,6 +28,6 @@ alpm_backup_t *_alpm_needbackup(const char *file, alpm_pkg_t *pkg); void _alpm_backup_free(alpm_backup_t *backup); alpm_backup_t *_alpm_backup_dup(const alpm_backup_t *backup); -#endif /* _ALPM_BACKUP_H */ +#endif /* ALPM_BACKUP_H */ /* vim: set noet: */ diff --git a/lib/libalpm/base64.h b/lib/libalpm/base64.h index df684ab..9edb864 100644 --- a/lib/libalpm/base64.h +++ b/lib/libalpm/base64.h @@ -22,8 +22,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _BASE64_H -#define _BASE64_H +#ifndef BASE64_H +#define BASE64_H #include <string.h> diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h index e17d552..801c201 100644 --- a/lib/libalpm/conflict.h +++ b/lib/libalpm/conflict.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_CONFLICT_H -#define _ALPM_CONFLICT_H +#ifndef ALPM_CONFLICT_H +#define ALPM_CONFLICT_H #include "alpm.h" #include "db.h" @@ -30,6 +30,6 @@ alpm_list_t *_alpm_outerconflicts(alpm_db_t *db, alpm_list_t *packages); alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle, alpm_list_t *upgrade, alpm_list_t *remove); -#endif /* _ALPM_CONFLICT_H */ +#endif /* ALPM_CONFLICT_H */ /* vim: set noet: */ diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index 05ef43e..e696298 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -19,8 +19,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_DB_H -#define _ALPM_DB_H +#ifndef ALPM_DB_H +#define ALPM_DB_H /* libarchive */ #include <archive.h> @@ -107,6 +107,6 @@ alpm_pkg_t *_alpm_db_get_pkgfromcache(alpm_db_t *db, const char *target); alpm_list_t *_alpm_db_get_groupcache(alpm_db_t *db); alpm_group_t *_alpm_db_get_groupfromcache(alpm_db_t *db, const char *target); -#endif /* _ALPM_DB_H */ +#endif /* ALPM_DB_H */ /* vim: set noet: */ diff --git a/lib/libalpm/delta.h b/lib/libalpm/delta.h index c7bbade..26c3c4c 100644 --- a/lib/libalpm/delta.h +++ b/lib/libalpm/delta.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_DELTA_H -#define _ALPM_DELTA_H +#ifndef ALPM_DELTA_H +#define ALPM_DELTA_H #include <sys/types.h> /* off_t */ @@ -30,6 +30,6 @@ alpm_delta_t *_alpm_delta_dup(const alpm_delta_t *delta); off_t _alpm_shortest_delta_path(alpm_handle_t *handle, alpm_list_t *deltas, const char *to, alpm_list_t **path); -#endif /* _ALPM_DELTA_H */ +#endif /* ALPM_DELTA_H */ /* vim: set noet: */ diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h index 691f505..91c6eb6 100644 --- a/lib/libalpm/deps.h +++ b/lib/libalpm/deps.h @@ -19,8 +19,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_DEPS_H -#define _ALPM_DEPS_H +#ifndef ALPM_DEPS_H +#define ALPM_DEPS_H #include "db.h" #include "sync.h" @@ -38,6 +38,6 @@ int _alpm_depcmp_literal(alpm_pkg_t *pkg, alpm_depend_t *dep); int _alpm_depcmp_provides(alpm_depend_t *dep, alpm_list_t *provisions); int _alpm_depcmp(alpm_pkg_t *pkg, alpm_depend_t *dep); -#endif /* _ALPM_DEPS_H */ +#endif /* ALPM_DEPS_H */ /* vim: set noet: */ diff --git a/lib/libalpm/diskspace.h b/lib/libalpm/diskspace.h index acda05a..8c0e4e6 100644 --- a/lib/libalpm/diskspace.h +++ b/lib/libalpm/diskspace.h @@ -17,8 +17,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_DISKSPACE_H -#define _ALPM_DISKSPACE_H +#ifndef ALPM_DISKSPACE_H +#define ALPM_DISKSPACE_H #if defined(HAVE_SYS_MOUNT_H) #include <sys/mount.h> @@ -60,6 +60,6 @@ int _alpm_check_diskspace(alpm_handle_t *handle); int _alpm_check_downloadspace(alpm_handle_t *handle, const char *cachedir, size_t num_files, off_t *file_sizes); -#endif /* _ALPM_DISKSPACE_H */ +#endif /* ALPM_DISKSPACE_H */ /* vim: set noet: */ diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h index 60843bd..427c486 100644 --- a/lib/libalpm/dload.h +++ b/lib/libalpm/dload.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_DLOAD_H -#define _ALPM_DLOAD_H +#ifndef ALPM_DLOAD_H +#define ALPM_DLOAD_H #include "alpm_list.h" #include "alpm.h" @@ -51,6 +51,6 @@ void _alpm_dload_payload_reset(struct dload_payload *payload); int _alpm_download(struct dload_payload *payload, const char *localpath, char **final_file, const char **final_url); -#endif /* _ALPM_DLOAD_H */ +#endif /* ALPM_DLOAD_H */ /* vim: set noet: */ diff --git a/lib/libalpm/filelist.h b/lib/libalpm/filelist.h index 5560ea0..a74bdea 100644 --- a/lib/libalpm/filelist.h +++ b/lib/libalpm/filelist.h @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_FILELIST_H -#define _ALPM_FILELIST_H +#ifndef ALPM_FILELIST_H +#define ALPM_FILELIST_H #include "alpm.h" @@ -29,6 +29,6 @@ alpm_list_t *_alpm_filelist_intersection(alpm_filelist_t *filesA, int _alpm_files_cmp(const void *f1, const void *f2); -#endif /* _ALPM_FILELIST_H */ +#endif /* ALPM_FILELIST_H */ /* vim: set noet: */ diff --git a/lib/libalpm/graph.h b/lib/libalpm/graph.h index 76a268a..22f0aa9 100644 --- a/lib/libalpm/graph.h +++ b/lib/libalpm/graph.h @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_GRAPH_H -#define _ALPM_GRAPH_H +#ifndef ALPM_GRAPH_H +#define ALPM_GRAPH_H #include <sys/types.h> /* off_t */ @@ -35,6 +35,6 @@ typedef struct __alpm_graph_t { alpm_graph_t *_alpm_graph_new(void); void _alpm_graph_free(void *data); -#endif /* _ALPM_GRAPH_H */ +#endif /* ALPM_GRAPH_H */ /* vim: set noet: */ diff --git a/lib/libalpm/group.h b/lib/libalpm/group.h index 1db4e36..aa33076 100644 --- a/lib/libalpm/group.h +++ b/lib/libalpm/group.h @@ -17,14 +17,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_GROUP_H -#define _ALPM_GROUP_H +#ifndef ALPM_GROUP_H +#define ALPM_GROUP_H #include "alpm.h" alpm_group_t *_alpm_group_new(const char *name); void _alpm_group_free(alpm_group_t *grp); -#endif /* _ALPM_GROUP_H */ +#endif /* ALPM_GROUP_H */ /* vim: set noet: */ diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index a1d0f9a..ecbe837 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_HANDLE_H -#define _ALPM_HANDLE_H +#ifndef ALPM_HANDLE_H +#define ALPM_HANDLE_H #include <stdio.h> #include <sys/types.h> @@ -123,6 +123,6 @@ int _alpm_handle_unlock(alpm_handle_t *handle); alpm_errno_t _alpm_set_directory_option(const char *value, char **storage, int must_exist); -#endif /* _ALPM_HANDLE_H */ +#endif /* ALPM_HANDLE_H */ /* vim: set noet: */ diff --git a/lib/libalpm/hook.h b/lib/libalpm/hook.h index 01eb3ed..f33dfe1 100644 --- a/lib/libalpm/hook.h +++ b/lib/libalpm/hook.h @@ -17,13 +17,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_HOOK_H -#define _ALPM_HOOK_H +#ifndef ALPM_HOOK_H +#define ALPM_HOOK_H #include "alpm.h" int _alpm_hook_run(alpm_handle_t *handle, alpm_hook_when_t when); -#endif /* _ALPM_HOOK_H */ +#endif /* ALPM_HOOK_H */ /* vim: set noet: */ diff --git a/lib/libalpm/libarchive-compat.h b/lib/libalpm/libarchive-compat.h index 3b46a5a..d4aa4fa 100644 --- a/lib/libalpm/libarchive-compat.h +++ b/lib/libalpm/libarchive-compat.h @@ -1,5 +1,5 @@ -#ifndef _LIBARCHIVE_COMPAT_H -#define _LIBARCHIVE_COMPAT_H +#ifndef LIBARCHIVE_COMPAT_H +#define LIBARCHIVE_COMPAT_H /* * libarchive-compat.h @@ -68,6 +68,6 @@ static inline int _alpm_archive_read_support_filter_all(struct archive *archive) #endif } -#endif /* _LIBARCHIVE_COMPAT_H */ +#endif /* LIBARCHIVE_COMPAT_H */ /* vim: set noet: */ diff --git a/lib/libalpm/log.h b/lib/libalpm/log.h index 3fd6196..79074fc 100644 --- a/lib/libalpm/log.h +++ b/lib/libalpm/log.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_LOG_H -#define _ALPM_LOG_H +#ifndef ALPM_LOG_H +#define ALPM_LOG_H #include "alpm.h" @@ -27,6 +27,6 @@ void _alpm_log(alpm_handle_t *handle, alpm_loglevel_t flag, const char *fmt, ...) __attribute__((format(printf,3,4))); -#endif /* _ALPM_LOG_H */ +#endif /* ALPM_LOG_H */ /* vim: set noet: */ diff --git a/lib/libalpm/md5.h b/lib/libalpm/md5.h index d03013a..4a6fe4d 100644 --- a/lib/libalpm/md5.h +++ b/lib/libalpm/md5.h @@ -21,8 +21,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _MD5_H -#define _MD5_H +#ifndef MD5_H +#define MD5_H #include <string.h> diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index 31add9a..114d225 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -21,8 +21,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_PACKAGE_H -#define _ALPM_PACKAGE_H +#ifndef ALPM_PACKAGE_H +#define ALPM_PACKAGE_H #include <sys/types.h> /* off_t */ @@ -153,6 +153,6 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, int _alpm_pkg_cmp(const void *p1, const void *p2); int _alpm_pkg_compare_versions(alpm_pkg_t *local_pkg, alpm_pkg_t *pkg); -#endif /* _ALPM_PACKAGE_H */ +#endif /* ALPM_PACKAGE_H */ /* vim: set noet: */ diff --git a/lib/libalpm/pkghash.h b/lib/libalpm/pkghash.h index c843a43..be064f6 100644 --- a/lib/libalpm/pkghash.h +++ b/lib/libalpm/pkghash.h @@ -17,8 +17,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_PKGHASH_H -#define _ALPM_PKGHASH_H +#ifndef ALPM_PKGHASH_H +#define ALPM_PKGHASH_H #include <stdlib.h> @@ -57,4 +57,4 @@ void _alpm_pkghash_free(alpm_pkghash_t *hash); alpm_pkg_t *_alpm_pkghash_find(alpm_pkghash_t *hash, const char *name); -#endif /* _ALPM_PKGHASH_H */ +#endif /* ALPM_PKGHASH_H */ diff --git a/lib/libalpm/remove.h b/lib/libalpm/remove.h index e6e1b22..b26ea60 100644 --- a/lib/libalpm/remove.h +++ b/lib/libalpm/remove.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_REMOVE_H -#define _ALPM_REMOVE_H +#ifndef ALPM_REMOVE_H +#define ALPM_REMOVE_H #include "db.h" #include "alpm_list.h" @@ -31,6 +31,6 @@ int _alpm_remove_single_package(alpm_handle_t *handle, alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg, size_t targ_count, size_t pkg_count); -#endif /* _ALPM_REMOVE_H */ +#endif /* ALPM_REMOVE_H */ /* vim: set noet: */ diff --git a/lib/libalpm/sha2.h b/lib/libalpm/sha2.h index 887b9c6..99267de 100644 --- a/lib/libalpm/sha2.h +++ b/lib/libalpm/sha2.h @@ -21,8 +21,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _SHA2_H -#define _SHA2_H +#ifndef SHA2_H +#define SHA2_H #include <string.h> diff --git a/lib/libalpm/signing.h b/lib/libalpm/signing.h index 9e12cfa..960b644 100644 --- a/lib/libalpm/signing.h +++ b/lib/libalpm/signing.h @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_SIGNING_H -#define _ALPM_SIGNING_H +#ifndef ALPM_SIGNING_H +#define ALPM_SIGNING_H #include "alpm.h" @@ -34,6 +34,6 @@ int _alpm_process_siglist(alpm_handle_t *handle, const char *identifier, int _alpm_key_in_keychain(alpm_handle_t *handle, const char *fpr); int _alpm_key_import(alpm_handle_t *handle, const char *fpr); -#endif /* _ALPM_SIGNING_H */ +#endif /* ALPM_SIGNING_H */ /* vim: set noet: */ diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h index f6c610e..1aa48b7 100644 --- a/lib/libalpm/sync.h +++ b/lib/libalpm/sync.h @@ -19,8 +19,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_SYNC_H -#define _ALPM_SYNC_H +#ifndef ALPM_SYNC_H +#define ALPM_SYNC_H #include "alpm.h" @@ -29,6 +29,6 @@ int _alpm_sync_load(alpm_handle_t *handle, alpm_list_t **data); int _alpm_sync_check(alpm_handle_t *handle, alpm_list_t **data); int _alpm_sync_commit(alpm_handle_t *handle); -#endif /* _ALPM_SYNC_H */ +#endif /* ALPM_SYNC_H */ /* vim: set noet: */ diff --git a/lib/libalpm/trans.h b/lib/libalpm/trans.h index d2eb681..73111be 100644 --- a/lib/libalpm/trans.h +++ b/lib/libalpm/trans.h @@ -20,8 +20,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_TRANS_H -#define _ALPM_TRANS_H +#ifndef ALPM_TRANS_H +#define ALPM_TRANS_H #include "alpm.h" @@ -50,6 +50,6 @@ int _alpm_trans_init(alpm_trans_t *trans, alpm_transflag_t flags); int _alpm_runscriptlet(alpm_handle_t *handle, const char *filepath, const char *script, const char *ver, const char *oldver, int is_archive); -#endif /* _ALPM_TRANS_H */ +#endif /* ALPM_TRANS_H */ /* vim: set noet: */ diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 9494986..5a2c105 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -21,8 +21,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ALPM_UTIL_H -#define _ALPM_UTIL_H +#ifndef ALPM_UTIL_H +#define ALPM_UTIL_H #include "alpm_list.h" #include "alpm.h" @@ -156,6 +156,6 @@ char *strsep(char **, const char *); #define UNUSED __attribute__((unused)) -#endif /* _ALPM_UTIL_H */ +#endif /* ALPM_UTIL_H */ /* vim: set noet: */ diff --git a/src/common/ini.h b/src/common/ini.h index 2b4f79d..e03a83f 100644 --- a/src/common/ini.h +++ b/src/common/ini.h @@ -17,14 +17,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_INI_H -#define _PM_INI_H +#ifndef PM_INI_H +#define PM_INI_H typedef int (ini_parser_fn)(const char *file, int line, const char *section, char *key, char *value, void *data); int parse_ini(const char *file, ini_parser_fn cb, void *data); -#endif /* _PM_CONF_H */ +#endif /* PM_INI_H */ /* vim: set noet: */ diff --git a/src/common/util-common.h b/src/common/util-common.h index 9df6a70..1452094 100644 --- a/src/common/util-common.h +++ b/src/common/util-common.h @@ -17,8 +17,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_UTIL_COMMON_H -#define _PM_UTIL_COMMON_H +#ifndef PM_UTIL_COMMON_H +#define PM_UTIL_COMMON_H #include <stdio.h> #include <sys/stat.h> /* struct stat */ @@ -38,6 +38,6 @@ char *strndup(const char *s, size_t n); #define ARRAYSIZE(a) (sizeof (a) / sizeof (a[0])) -#endif /* _PM_UTIL_COMMON_H */ +#endif /* PM_UTIL_COMMON_H */ /* vim: set noet: */ diff --git a/src/pacman/callback.h b/src/pacman/callback.h index fc83fb7..ad395e9 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_CALLBACK_H -#define _PM_CALLBACK_H +#ifndef PM_CALLBACK_H +#define PM_CALLBACK_H #include <sys/types.h> /* off_t */ @@ -43,6 +43,6 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total); __attribute__((format(printf, 2, 0))) void cb_log(alpm_loglevel_t level, const char *fmt, va_list args); -#endif /* _PM_CALLBACK_H */ +#endif /* PM_CALLBACK_H */ /* vim: set noet: */ diff --git a/src/pacman/check.h b/src/pacman/check.h index 362a352..5052376 100644 --- a/src/pacman/check.h +++ b/src/pacman/check.h @@ -17,14 +17,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_CHECK_H -#define _PM_CHECK_H +#ifndef PM_CHECK_H +#define PM_CHECK_H #include <alpm.h> int check_pkg_fast(alpm_pkg_t *pkg); int check_pkg_full(alpm_pkg_t *pkg); -#endif /* _PM_CHECK_H */ +#endif /* PM_CHECK_H */ /* vim: set noet: */ diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 2aba8bf..2ddeadb 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_CONF_H -#define _PM_CONF_H +#ifndef PM_CONF_H +#define PM_CONF_H #include <alpm.h> @@ -234,6 +234,6 @@ void config_repo_free(config_repo_t *repo); int config_set_arch(const char *arch); int parseconfig(const char *file); -#endif /* _PM_CONF_H */ +#endif /* PM_CONF_H */ /* vim: set noet: */ diff --git a/src/pacman/package.h b/src/pacman/package.h index e369330..3129a73 100644 --- a/src/pacman/package.h +++ b/src/pacman/package.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_PACKAGE_H -#define _PM_PACKAGE_H +#ifndef PM_PACKAGE_H +#define PM_PACKAGE_H #include <alpm.h> @@ -31,6 +31,6 @@ void dump_pkg_changelog(alpm_pkg_t *pkg); void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg); int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status); -#endif /* _PM_PACKAGE_H */ +#endif /* PM_PACKAGE_H */ /* vim: set noet: */ diff --git a/src/pacman/pacman.h b/src/pacman/pacman.h index edb81b1..84f70a6 100644 --- a/src/pacman/pacman.h +++ b/src/pacman/pacman.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_PACMAN_H -#define _PM_PACMAN_H +#ifndef PM_PACMAN_H +#define PM_PACMAN_H #include <alpm_list.h> @@ -40,6 +40,6 @@ int sync_prepare_execute(void); /* upgrade.c */ int pacman_upgrade(alpm_list_t *targets); -#endif /* _PM_PACMAN_H */ +#endif /* PM_PACMAN_H */ /* vim: set noet: */ diff --git a/src/pacman/sighandler.h b/src/pacman/sighandler.h index 3fddaee..108a7e0 100644 --- a/src/pacman/sighandler.h +++ b/src/pacman/sighandler.h @@ -17,14 +17,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_SIGHANDLER_H -#define _PM_SIGHANDLER_H +#ifndef PM_SIGHANDLER_H +#define PM_SIGHANDLER_H void install_segv_handler(void); void install_winch_handler(void); void install_soft_interrupt_handler(void); void remove_soft_interrupt_handler(void); -#endif /* _PM_SIGHANDLER_H */ +#endif /* PM_SIGHANDLER_H */ /* vim: set noet: */ diff --git a/src/pacman/util.h b/src/pacman/util.h index f5e37c8..74ce4cb 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -17,8 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _PM_UTIL_H -#define _PM_UTIL_H +#ifndef PM_UTIL_H +#define PM_UTIL_H #include <stdlib.h> #include <stdarg.h> @@ -82,6 +82,6 @@ int pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, va_list int pm_sprintf(char **string, alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,3,4))); int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); -#endif /* _PM_UTIL_H */ +#endif /* PM_UTIL_H */ /* vim: set noet: */ -- 2.9.3
From: Ivy Foster <ivy.foster@gmail.com> In many cases, it was enough to add error or "none" values to enums, to account for cases where functions returned either an enumerated value or 0/-1. A common code pattern in pacman is to use enums to create bitfields representing various option combinations. Since they are not technically part of the enumerated type used to build them, these bitfields have been reassigned to type int. Signed-off-by: Ivy Foster <ivy.foster@gmail.com> --- configure.ac | 1 + lib/libalpm/alpm.c | 4 +-- lib/libalpm/alpm.h | 15 +++++++-- lib/libalpm/be_package.c | 2 +- lib/libalpm/be_sync.c | 4 +-- lib/libalpm/db.c | 20 ++++++------ lib/libalpm/db.h | 2 +- lib/libalpm/dload.c | 2 +- lib/libalpm/package.c | 84 ++++++++++++++++++++++++------------------------ lib/libalpm/package.h | 2 +- lib/libalpm/signing.c | 6 ++-- lib/libalpm/sync.c | 10 +++--- lib/libalpm/trans.c | 2 +- lib/libalpm/util.h | 2 +- src/pacman/conf.c | 4 +-- src/pacman/conf.h | 12 +++---- src/pacman/database.c | 2 +- src/util/cleanupdelta.c | 2 +- src/util/pactree.c | 2 +- src/util/testpkg.c | 2 +- 20 files changed, 96 insertions(+), 84 deletions(-) diff --git a/configure.ac b/configure.ac index 51288e7..2f9aeab 100644 --- a/configure.ac +++ b/configure.ac @@ -430,6 +430,7 @@ fi AC_MSG_CHECKING(for excessive compiler warning flags) if test "x$warningflags" = "xyes" ; then AC_MSG_RESULT(yes) + CFLAGS_ADD([-Wassign-enum], [WARNING_CFLAGS]) CFLAGS_ADD([-Wcast-align], [WARNING_CFLAGS]) CFLAGS_ADD([-Wclobbered], [WARNING_CFLAGS]) CFLAGS_ADD([-Wempty-body], [WARNING_CFLAGS]) diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 6b7fa7a..6338429 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -152,9 +152,9 @@ const char SYMEXPORT *alpm_version(void) /** Get the capabilities of the library. * @return a bitmask of the capabilities * */ -enum alpm_caps SYMEXPORT alpm_capabilities(void) +int SYMEXPORT alpm_capabilities(void) { - return 0 + return ALPM_CAPABILITY_NONE #ifdef ENABLE_NLS | ALPM_CAPABILITY_NLS #endif diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 7955585..cb3aa51 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -53,7 +53,8 @@ typedef struct __alpm_trans_t alpm_trans_t; * @{ */ typedef enum _alpm_errno_t { - ALPM_ERR_MEMORY = 1, + ALPM_ERR_OK = 0, + ALPM_ERR_MEMORY, ALPM_ERR_SYSTEM, ALPM_ERR_BADPERMS, ALPM_ERR_NOT_A_FILE, @@ -143,6 +144,7 @@ typedef int64_t alpm_time_t; /** Package install reasons. */ typedef enum _alpm_pkgreason_t { + ALPM_PKG_REASON_ERROR = -1, /** Explicitly requested by the user. */ ALPM_PKG_REASON_EXPLICIT = 0, /** Installed as a dependency for another package. */ @@ -151,6 +153,7 @@ typedef enum _alpm_pkgreason_t { /** Location a package object was loaded from. */ typedef enum _alpm_pkgfrom_t { + ALPM_PKG_FROM_ERROR = -1, ALPM_PKG_FROM_FILE = 1, ALPM_PKG_FROM_LOCALDB, ALPM_PKG_FROM_SYNCDB @@ -158,6 +161,7 @@ typedef enum _alpm_pkgfrom_t { /** Method used to validate a package. */ typedef enum _alpm_pkgvalidation_t { + ALPM_PKG_VALIDATION_ERROR = -1, ALPM_PKG_VALIDATION_UNKNOWN = 0, ALPM_PKG_VALIDATION_NONE = (1 << 0), ALPM_PKG_VALIDATION_MD5SUM = (1 << 1), @@ -193,6 +197,9 @@ typedef enum _alpm_fileconflicttype_t { /** PGP signature verification options */ typedef enum _alpm_siglevel_t { + ALPM_SIG_ERROR = -1, + ALPM_SIG_NONE = 0, + ALPM_SIG_PACKAGE = (1 << 0), ALPM_SIG_PACKAGE_OPTIONAL = (1 << 1), ALPM_SIG_PACKAGE_MARGINAL_OK = (1 << 2), @@ -1037,6 +1044,7 @@ alpm_list_t *alpm_db_get_groupcache(alpm_db_t *db); alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles); typedef enum _alpm_db_usage_ { + ALPM_DB_USAGE_NONE = 0, ALPM_DB_USAGE_SYNC = 1, ALPM_DB_USAGE_SEARCH = (1 << 1), ALPM_DB_USAGE_INSTALL = (1 << 2), @@ -1439,6 +1447,8 @@ alpm_pkg_t *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_sync); /** Transaction flags */ typedef enum _alpm_transflag_t { + ALPM_TRANS_FLAG_ERROR = -1, + ALPM_TRANS_FLAG_NONE = 0, /** Ignore dependency checks. */ ALPM_TRANS_FLAG_NODEPS = 1, /** Ignore file conflicts and overwrite files. */ @@ -1606,13 +1616,14 @@ int alpm_release(alpm_handle_t *handle); int alpm_unlock(alpm_handle_t *handle); enum alpm_caps { + ALPM_CAPABILITY_NONE = 0, ALPM_CAPABILITY_NLS = (1 << 0), ALPM_CAPABILITY_DOWNLOADER = (1 << 1), ALPM_CAPABILITY_SIGNATURES = (1 << 2) }; const char *alpm_version(void); -enum alpm_caps alpm_capabilities(void); +int alpm_capabilities(void); void alpm_fileconflict_free(alpm_fileconflict_t *conflict); void alpm_depmissing_free(alpm_depmissing_t *miss); diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index 430d2ae..befcba3 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -274,7 +274,7 @@ int _alpm_pkg_validate_internal(alpm_handle_t *handle, alpm_siglist_t **sigdata, alpm_pkgvalidation_t *validation) { int has_sig; - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; if(pkgfile == NULL || strlen(pkgfile) == 0) { RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1); diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 32a669d..2cd722e 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -186,7 +186,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) /* Sanity checks */ ASSERT(db != NULL, return -1); handle = db->handle; - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; ASSERT(db != handle->db_local, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1)); ASSERT(db->servers != NULL, RET_ERR(handle, ALPM_ERR_SERVER_NONE, -1)); @@ -320,7 +320,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) _alpm_log(handle, ALPM_LOG_DEBUG, "failed to sync db: %s\n", alpm_strerror(handle->pm_errno)); } else { - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; } _alpm_handle_unlock(handle); diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index f70f83c..913ea6a 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -112,7 +112,7 @@ int SYMEXPORT alpm_db_unregister(alpm_db_t *db) ASSERT(db != NULL, return -1); /* Do not unregister a database if a transaction is on-going */ handle = db->handle; - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, -1)); if(db == handle->db_local) { @@ -179,7 +179,7 @@ int SYMEXPORT alpm_db_add_server(alpm_db_t *db, const char *url) /* Sanity checks */ ASSERT(db != NULL, return -1); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1)); newurl = sanitize_url(url); @@ -206,7 +206,7 @@ int SYMEXPORT alpm_db_remove_server(alpm_db_t *db, const char *url) /* Sanity checks */ ASSERT(db != NULL, return -1); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1)); newurl = sanitize_url(url); @@ -237,7 +237,7 @@ const char SYMEXPORT *alpm_db_get_name(const alpm_db_t *db) /** Get the signature verification level for a database. */ alpm_siglevel_t SYMEXPORT alpm_db_get_siglevel(alpm_db_t *db) { - ASSERT(db != NULL, return -1); + ASSERT(db != NULL, return ALPM_SIG_ERROR); if(db->siglevel & ALPM_SIG_USE_DEFAULT) { return db->handle->siglevel; } else { @@ -249,7 +249,7 @@ alpm_siglevel_t SYMEXPORT alpm_db_get_siglevel(alpm_db_t *db) int SYMEXPORT alpm_db_get_valid(alpm_db_t *db) { ASSERT(db != NULL, return -1); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return db->ops->validate(db); } @@ -258,7 +258,7 @@ alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const char *name) { alpm_pkg_t *pkg; ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(name != NULL && strlen(name) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL)); @@ -273,7 +273,7 @@ alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const char *name) alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(alpm_db_t *db) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return _alpm_db_get_pkgcache(db); } @@ -281,7 +281,7 @@ alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(alpm_db_t *db) alpm_group_t SYMEXPORT *alpm_db_get_group(alpm_db_t *db, const char *name) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(name != NULL && strlen(name) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL)); @@ -292,7 +292,7 @@ alpm_group_t SYMEXPORT *alpm_db_get_group(alpm_db_t *db, const char *name) alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t *db) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return _alpm_db_get_groupcache(db); } @@ -301,7 +301,7 @@ alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t *db) alpm_list_t SYMEXPORT *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return _alpm_db_search(db, needles); } diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index e696298..ae21e75 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -72,7 +72,7 @@ struct __alpm_db_t { alpm_list_t *servers; struct db_operations *ops; /* flags determining validity, local, loaded caches, etc. */ - enum _alpm_dbstatus_t status; + int status; alpm_siglevel_t siglevel; alpm_db_usage_t usage; }; diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index f4e6a27..10e4a0d 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -412,7 +412,7 @@ static int curl_download_internal(struct dload_payload *payload, /* shortcut to our handle within the payload */ alpm_handle_t *handle = payload->handle; CURL *curl = get_libcurl_handle(handle); - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; /* make sure these are NULL */ FREE(payload->tempfile_name); diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index f08df8b..4cac2d1 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -60,7 +60,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg) int retval; ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; /* We only inspect packages from sync repositories */ ASSERT(pkg->origin == ALPM_PKG_FROM_SYNCDB, RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1)); @@ -184,196 +184,196 @@ struct pkg_operations default_pkg_ops = { const char SYMEXPORT *alpm_pkg_get_filename(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->filename; } const char SYMEXPORT *alpm_pkg_get_base(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_base(pkg); } const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->name; } const char SYMEXPORT *alpm_pkg_get_version(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->version; } alpm_pkgfrom_t SYMEXPORT alpm_pkg_get_origin(alpm_pkg_t *pkg) { - ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + ASSERT(pkg != NULL, return ALPM_PKG_FROM_ERROR); + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->origin; } const char SYMEXPORT *alpm_pkg_get_desc(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_desc(pkg); } const char SYMEXPORT *alpm_pkg_get_url(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_url(pkg); } alpm_time_t SYMEXPORT alpm_pkg_get_builddate(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_builddate(pkg); } alpm_time_t SYMEXPORT alpm_pkg_get_installdate(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_installdate(pkg); } const char SYMEXPORT *alpm_pkg_get_packager(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_packager(pkg); } const char SYMEXPORT *alpm_pkg_get_md5sum(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->md5sum; } const char SYMEXPORT *alpm_pkg_get_sha256sum(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->sha256sum; } const char SYMEXPORT *alpm_pkg_get_base64_sig(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->base64_sig; } const char SYMEXPORT *alpm_pkg_get_arch(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_arch(pkg); } off_t SYMEXPORT alpm_pkg_get_size(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->size; } off_t SYMEXPORT alpm_pkg_get_isize(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_isize(pkg); } alpm_pkgreason_t SYMEXPORT alpm_pkg_get_reason(alpm_pkg_t *pkg) { - ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + ASSERT(pkg != NULL, return ALPM_PKG_REASON_ERROR); + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_reason(pkg); } alpm_pkgvalidation_t SYMEXPORT alpm_pkg_get_validation(alpm_pkg_t *pkg) { - ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + ASSERT(pkg != NULL, return ALPM_PKG_VALIDATION_ERROR); + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_validation(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_licenses(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_licenses(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_groups(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_groups(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_depends(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_depends(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_optdepends(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_optdepends(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_conflicts(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_conflicts(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_provides(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_provides(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_replaces(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_replaces(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_deltas(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->deltas; } alpm_filelist_t SYMEXPORT *alpm_pkg_get_files(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_files(pkg); } alpm_list_t SYMEXPORT *alpm_pkg_get_backup(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_backup(pkg); } @@ -382,7 +382,7 @@ alpm_db_t SYMEXPORT *alpm_pkg_get_db(alpm_pkg_t *pkg) /* Sanity checks */ ASSERT(pkg != NULL, return NULL); ASSERT(pkg->origin != ALPM_PKG_FROM_FILE, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->origin_data.db; } @@ -391,7 +391,7 @@ alpm_db_t SYMEXPORT *alpm_pkg_get_db(alpm_pkg_t *pkg) void SYMEXPORT *alpm_pkg_changelog_open(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->changelog_open(pkg); } @@ -400,7 +400,7 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, const alpm_pkg_t *pkg, void *fp) { ASSERT(pkg != NULL, return 0); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->changelog_read(ptr, size, pkg, fp); } @@ -408,7 +408,7 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, int SYMEXPORT alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->changelog_close(pkg, fp); } @@ -416,7 +416,7 @@ int SYMEXPORT alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp) struct archive SYMEXPORT *alpm_pkg_mtree_open(alpm_pkg_t * pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->mtree_open(pkg); } @@ -425,7 +425,7 @@ int SYMEXPORT alpm_pkg_mtree_next(const alpm_pkg_t * pkg, struct archive *archiv struct archive_entry **entry) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->mtree_next(pkg, archive, entry); } @@ -433,14 +433,14 @@ int SYMEXPORT alpm_pkg_mtree_next(const alpm_pkg_t * pkg, struct archive *archiv int SYMEXPORT alpm_pkg_mtree_close(const alpm_pkg_t * pkg, struct archive *archive) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->mtree_close(pkg, archive); } int SYMEXPORT alpm_pkg_has_scriptlet(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->has_scriptlet(pkg); } @@ -448,7 +448,7 @@ static void find_requiredby(alpm_pkg_t *pkg, alpm_db_t *db, alpm_list_t **reqs, int optional) { const alpm_list_t *i; - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { alpm_pkg_t *cachepkg = i->data; @@ -478,7 +478,7 @@ static alpm_list_t *compute_requiredby(alpm_pkg_t *pkg, int optional) alpm_db_t *db; ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; if(pkg->origin == ALPM_PKG_FROM_FILE) { /* The sane option; search locally for things that require this. */ diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index 114d225..4dce542 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -130,7 +130,7 @@ struct __alpm_pkg_t { char *file; } origin_data; - alpm_dbinfrq_t infolevel; + int infolevel; alpm_pkgvalidation_t validation; alpm_pkgfrom_t origin; alpm_pkgreason_t reason; diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c index 6557c20..527e763 100644 --- a/lib/libalpm/signing.c +++ b/lib/libalpm/signing.c @@ -771,7 +771,7 @@ int _alpm_check_pgp_helper(alpm_handle_t *handle, const char *path, if(ret && handle->pm_errno == ALPM_ERR_SIG_MISSING) { if(optional) { _alpm_log(handle, ALPM_LOG_DEBUG, "missing optional signature\n"); - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; ret = 0; } else { _alpm_log(handle, ALPM_LOG_DEBUG, "missing required signature\n"); @@ -931,7 +931,7 @@ int SYMEXPORT alpm_pkg_check_pgp_signature(alpm_pkg_t *pkg, { ASSERT(pkg != NULL, return -1); ASSERT(siglist != NULL, RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1)); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return _alpm_gpgme_checksig(pkg->handle, pkg->filename, pkg->base64_sig, siglist); @@ -948,7 +948,7 @@ int SYMEXPORT alpm_db_check_pgp_signature(alpm_db_t *db, { ASSERT(db != NULL, return -1); ASSERT(siglist != NULL, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1)); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return _alpm_gpgme_checksig(db->handle, _alpm_db_path(db), NULL, siglist); } diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 00b68d0..41b95f6 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -57,7 +57,7 @@ alpm_pkg_t SYMEXPORT *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_syn alpm_pkg_t *spkg = NULL; ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; for(i = dbs_sync; !spkg && i; i = i->next) { alpm_db_t *db = i->data; @@ -460,7 +460,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) transaction. The packages will be removed from the actual transaction when the transaction packages are replaced with a dependency-reordered list below */ - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; if(data) { alpm_list_free_inner(*data, (alpm_list_fn_free)alpm_depmissing_free); @@ -1140,7 +1140,7 @@ static int check_validity(alpm_handle_t *handle, EVENT(handle, &event); for(i = handle->trans->add; i; i = i->next, current++) { - struct validity v = { i->data, NULL, NULL, 0, 0, 0 }; + struct validity v = { i->data, NULL, NULL, ALPM_SIG_NONE, 0, 0 }; int percent = (int)(((double)current_bytes / total_bytes) * 100); PROGRESS(handle, ALPM_PROGRESS_INTEGRITY_START, "", percent, @@ -1195,7 +1195,7 @@ static int check_validity(alpm_handle_t *handle, } alpm_list_free(errors); - if(!handle->pm_errno) { + if(handle->pm_errno == ALPM_ERR_OK) { RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1); } return -1; @@ -1280,7 +1280,7 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data, EVENT(handle, &event); if(errors) { - if(!handle->pm_errno) { + if(handle->pm_errno == ALPM_ERR_OK) { RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1); } return -1; diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 1398470..1d23864 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -418,7 +418,7 @@ cleanup: alpm_transflag_t SYMEXPORT alpm_trans_get_flags(alpm_handle_t *handle) { /* Sanity checks */ - CHECK_HANDLE(handle, return -1); + CHECK_HANDLE(handle, return ALPM_TRANS_FLAG_ERROR); ASSERT(handle->trans != NULL, RET_ERR(handle, ALPM_ERR_TRANS_NULL, -1)); return handle->trans->flags; diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 5a2c105..b9c5c17 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -77,7 +77,7 @@ void _alpm_alloc_fail(size_t size); #define DOUBLE_EQ(x, y) (fabs((x) - (y)) < DBL_EPSILON) -#define CHECK_HANDLE(handle, action) do { if(!(handle)) { action; } (handle)->pm_errno = 0; } while(0) +#define CHECK_HANDLE(handle, action) do { if(!(handle)) { action; } (handle)->pm_errno = ALPM_ERR_OK; } while(0) /** Standard buffer size used throughout the library. */ #ifdef BUFSIZ diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 25de7af..a2d5555 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -328,7 +328,7 @@ int config_set_arch(const char *arch) static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage, alpm_siglevel_t *storage_mask, const char *file, int linenum) { - alpm_siglevel_t level = *storage, mask = *storage_mask; + int level = *storage, mask = *storage_mask; alpm_list_t *i; int ret = 0; @@ -1005,7 +1005,7 @@ static int _parse_directive(const char *file, int linenum, const char *name, section->repo = calloc(sizeof(config_repo_t), 1); section->repo->name = strdup(name); section->repo->siglevel = ALPM_SIG_USE_DEFAULT; - section->repo->usage = 0; + section->repo->usage = ALPM_DB_USAGE_NONE; config->repos = alpm_list_add(config->repos, section->repo); } return 0; diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 2ddeadb..d7bc1bc 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -96,13 +96,13 @@ typedef struct __config_t { unsigned short noask; unsigned int ask; alpm_transflag_t flags; - alpm_siglevel_t siglevel; - alpm_siglevel_t localfilesiglevel; - alpm_siglevel_t remotefilesiglevel; + int siglevel; + int localfilesiglevel; + int remotefilesiglevel; - alpm_siglevel_t siglevel_mask; - alpm_siglevel_t localfilesiglevel_mask; - alpm_siglevel_t remotefilesiglevel_mask; + int siglevel_mask; + int localfilesiglevel_mask; + int remotefilesiglevel_mask; /* conf file options */ /* I Love Candy! */ diff --git a/src/pacman/database.c b/src/pacman/database.c index 0197903..a62c082 100644 --- a/src/pacman/database.c +++ b/src/pacman/database.c @@ -61,7 +61,7 @@ static int change_install_reason(alpm_list_t *targets) } /* Lock database */ - if(trans_init(0, 0) == -1) { + if(trans_init(ALPM_TRANS_FLAG_NONE, 0) == -1) { return 1; } diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index 043acf1..d107811 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -68,7 +68,7 @@ static void checkdbs(alpm_list_t *dbnames) { alpm_db_t *db = NULL; alpm_list_t *i; - const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; + const int level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; for(i = dbnames; i; i = alpm_list_next(i)) { const char *dbname = i->data; diff --git a/src/util/pactree.c b/src/util/pactree.c index 67be9f9..2463f40 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -128,7 +128,7 @@ static int register_syncs(void) FILE *fp; char *section = NULL; char line[LINE_MAX]; - const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; + const int level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; fp = fopen(configfile, "r"); if(!fp) { diff --git a/src/util/testpkg.c b/src/util/testpkg.c index 89e8dbd..b176e6b 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) alpm_handle_t *handle; alpm_errno_t err; alpm_pkg_t *pkg = NULL; - const alpm_siglevel_t level = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL; + const int level = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL; if(argc != 2) { fprintf(stderr, "testpkg (pacman) v" PACKAGE_VERSION "\n\n" -- 2.9.3
On 09/03/16 at 10:14pm, ivy.foster@gmail.com wrote:
From: Ivy Foster <ivy.foster@gmail.com>
In many cases, it was enough to add error or "none" values to enums, to account for cases where functions returned either an enumerated value or 0/-1.
A common code pattern in pacman is to use enums to create bitfields representing various option combinations. Since they are not technically part of the enumerated type used to build them, these bitfields have been reassigned to type int.
Signed-off-by: Ivy Foster <ivy.foster@gmail.com> --- configure.ac | 1 + lib/libalpm/alpm.c | 4 +-- lib/libalpm/alpm.h | 15 +++++++-- lib/libalpm/be_package.c | 2 +- lib/libalpm/be_sync.c | 4 +-- lib/libalpm/db.c | 20 ++++++------ lib/libalpm/db.h | 2 +- lib/libalpm/dload.c | 2 +- lib/libalpm/package.c | 84 ++++++++++++++++++++++++------------------------ lib/libalpm/package.h | 2 +- lib/libalpm/signing.c | 6 ++-- lib/libalpm/sync.c | 10 +++--- lib/libalpm/trans.c | 2 +- lib/libalpm/util.h | 2 +- src/pacman/conf.c | 4 +-- src/pacman/conf.h | 12 +++---- src/pacman/database.c | 2 +- src/util/cleanupdelta.c | 2 +- src/util/pactree.c | 2 +- src/util/testpkg.c | 2 +- 20 files changed, 96 insertions(+), 84 deletions(-)
Even though all of these changes are related our enum handling, there is a lot going on in this patch. I would prefer if it were broken up into more specific change sets. * converting bitfield values to int I think int is the correct type for bitfields, but it looks like you missed many. Enums like siglevel_t and usage_t are used exclusively in the construction of bitfields. I don't think we should really have any variables of those types anywhere. * adding ERR_OK OK - libarchive and libcurl do this and I think it makes sense. * adding NONE/ERROR to other enums The addition of NONE values to enums appears to be unnecessary to me. I only see them being used as empty bitfield values, and, once we change those to int, using a literal 0 for those is just fine. I'm not fond of adding ERROR values to every enum just so that we can return -1 for invalid input. Most of them look unnecessary because the relevant functions are actually returning bitfields and should be changed to return an int, making -1 a valid return value.
diff --git a/configure.ac b/configure.ac index 51288e7..2f9aeab 100644 --- a/configure.ac +++ b/configure.ac @@ -430,6 +430,7 @@ fi AC_MSG_CHECKING(for excessive compiler warning flags) if test "x$warningflags" = "xyes" ; then AC_MSG_RESULT(yes) + CFLAGS_ADD([-Wassign-enum], [WARNING_CFLAGS]) CFLAGS_ADD([-Wcast-align], [WARNING_CFLAGS]) CFLAGS_ADD([-Wclobbered], [WARNING_CFLAGS]) CFLAGS_ADD([-Wempty-body], [WARNING_CFLAGS]) diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 6b7fa7a..6338429 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -152,9 +152,9 @@ const char SYMEXPORT *alpm_version(void) /** Get the capabilities of the library. * @return a bitmask of the capabilities * */ -enum alpm_caps SYMEXPORT alpm_capabilities(void) +int SYMEXPORT alpm_capabilities(void) { - return 0 + return ALPM_CAPABILITY_NONE #ifdef ENABLE_NLS | ALPM_CAPABILITY_NLS #endif diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 7955585..cb3aa51 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -53,7 +53,8 @@ typedef struct __alpm_trans_t alpm_trans_t; * @{ */ typedef enum _alpm_errno_t { - ALPM_ERR_MEMORY = 1, + ALPM_ERR_OK = 0, + ALPM_ERR_MEMORY, ALPM_ERR_SYSTEM, ALPM_ERR_BADPERMS, ALPM_ERR_NOT_A_FILE, @@ -143,6 +144,7 @@ typedef int64_t alpm_time_t;
/** Package install reasons. */ typedef enum _alpm_pkgreason_t { + ALPM_PKG_REASON_ERROR = -1, /** Explicitly requested by the user. */ ALPM_PKG_REASON_EXPLICIT = 0, /** Installed as a dependency for another package. */ @@ -151,6 +153,7 @@ typedef enum _alpm_pkgreason_t {
/** Location a package object was loaded from. */ typedef enum _alpm_pkgfrom_t { + ALPM_PKG_FROM_ERROR = -1, ALPM_PKG_FROM_FILE = 1, ALPM_PKG_FROM_LOCALDB, ALPM_PKG_FROM_SYNCDB @@ -158,6 +161,7 @@ typedef enum _alpm_pkgfrom_t {
/** Method used to validate a package. */ typedef enum _alpm_pkgvalidation_t { + ALPM_PKG_VALIDATION_ERROR = -1, ALPM_PKG_VALIDATION_UNKNOWN = 0, ALPM_PKG_VALIDATION_NONE = (1 << 0), ALPM_PKG_VALIDATION_MD5SUM = (1 << 1), @@ -193,6 +197,9 @@ typedef enum _alpm_fileconflicttype_t {
/** PGP signature verification options */ typedef enum _alpm_siglevel_t { + ALPM_SIG_ERROR = -1, + ALPM_SIG_NONE = 0, + ALPM_SIG_PACKAGE = (1 << 0), ALPM_SIG_PACKAGE_OPTIONAL = (1 << 1), ALPM_SIG_PACKAGE_MARGINAL_OK = (1 << 2), @@ -1037,6 +1044,7 @@ alpm_list_t *alpm_db_get_groupcache(alpm_db_t *db); alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles);
typedef enum _alpm_db_usage_ { + ALPM_DB_USAGE_NONE = 0, ALPM_DB_USAGE_SYNC = 1, ALPM_DB_USAGE_SEARCH = (1 << 1), ALPM_DB_USAGE_INSTALL = (1 << 2), @@ -1439,6 +1447,8 @@ alpm_pkg_t *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_sync);
/** Transaction flags */ typedef enum _alpm_transflag_t { + ALPM_TRANS_FLAG_ERROR = -1, + ALPM_TRANS_FLAG_NONE = 0, /** Ignore dependency checks. */ ALPM_TRANS_FLAG_NODEPS = 1, /** Ignore file conflicts and overwrite files. */ @@ -1606,13 +1616,14 @@ int alpm_release(alpm_handle_t *handle); int alpm_unlock(alpm_handle_t *handle);
enum alpm_caps { + ALPM_CAPABILITY_NONE = 0, ALPM_CAPABILITY_NLS = (1 << 0), ALPM_CAPABILITY_DOWNLOADER = (1 << 1), ALPM_CAPABILITY_SIGNATURES = (1 << 2) };
const char *alpm_version(void); -enum alpm_caps alpm_capabilities(void); +int alpm_capabilities(void);
void alpm_fileconflict_free(alpm_fileconflict_t *conflict); void alpm_depmissing_free(alpm_depmissing_t *miss); diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index 430d2ae..befcba3 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -274,7 +274,7 @@ int _alpm_pkg_validate_internal(alpm_handle_t *handle, alpm_siglist_t **sigdata, alpm_pkgvalidation_t *validation) { int has_sig; - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK;
if(pkgfile == NULL || strlen(pkgfile) == 0) { RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1); diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 32a669d..2cd722e 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -186,7 +186,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) /* Sanity checks */ ASSERT(db != NULL, return -1); handle = db->handle; - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; ASSERT(db != handle->db_local, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1)); ASSERT(db->servers != NULL, RET_ERR(handle, ALPM_ERR_SERVER_NONE, -1));
@@ -320,7 +320,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) _alpm_log(handle, ALPM_LOG_DEBUG, "failed to sync db: %s\n", alpm_strerror(handle->pm_errno)); } else { - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; }
_alpm_handle_unlock(handle); diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index f70f83c..913ea6a 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -112,7 +112,7 @@ int SYMEXPORT alpm_db_unregister(alpm_db_t *db) ASSERT(db != NULL, return -1); /* Do not unregister a database if a transaction is on-going */ handle = db->handle; - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, -1));
if(db == handle->db_local) { @@ -179,7 +179,7 @@ int SYMEXPORT alpm_db_add_server(alpm_db_t *db, const char *url)
/* Sanity checks */ ASSERT(db != NULL, return -1); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
newurl = sanitize_url(url); @@ -206,7 +206,7 @@ int SYMEXPORT alpm_db_remove_server(alpm_db_t *db, const char *url)
/* Sanity checks */ ASSERT(db != NULL, return -1); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
newurl = sanitize_url(url); @@ -237,7 +237,7 @@ const char SYMEXPORT *alpm_db_get_name(const alpm_db_t *db) /** Get the signature verification level for a database. */ alpm_siglevel_t SYMEXPORT alpm_db_get_siglevel(alpm_db_t *db) { - ASSERT(db != NULL, return -1); + ASSERT(db != NULL, return ALPM_SIG_ERROR); if(db->siglevel & ALPM_SIG_USE_DEFAULT) { return db->handle->siglevel; } else { @@ -249,7 +249,7 @@ alpm_siglevel_t SYMEXPORT alpm_db_get_siglevel(alpm_db_t *db) int SYMEXPORT alpm_db_get_valid(alpm_db_t *db) { ASSERT(db != NULL, return -1); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return db->ops->validate(db); }
@@ -258,7 +258,7 @@ alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const char *name) { alpm_pkg_t *pkg; ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(name != NULL && strlen(name) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL));
@@ -273,7 +273,7 @@ alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const char *name) alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(alpm_db_t *db) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; return _alpm_db_get_pkgcache(db); }
@@ -281,7 +281,7 @@ alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(alpm_db_t *db) alpm_group_t SYMEXPORT *alpm_db_get_group(alpm_db_t *db, const char *name) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK; ASSERT(name != NULL && strlen(name) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL));
@@ -292,7 +292,7 @@ alpm_group_t SYMEXPORT *alpm_db_get_group(alpm_db_t *db, const char *name) alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t *db) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK;
return _alpm_db_get_groupcache(db); } @@ -301,7 +301,7 @@ alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t *db) alpm_list_t SYMEXPORT *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles) { ASSERT(db != NULL, return NULL); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK;
return _alpm_db_search(db, needles); } diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index e696298..ae21e75 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -72,7 +72,7 @@ struct __alpm_db_t { alpm_list_t *servers; struct db_operations *ops; /* flags determining validity, local, loaded caches, etc. */ - enum _alpm_dbstatus_t status; + int status; alpm_siglevel_t siglevel; alpm_db_usage_t usage; }; diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index f4e6a27..10e4a0d 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -412,7 +412,7 @@ static int curl_download_internal(struct dload_payload *payload, /* shortcut to our handle within the payload */ alpm_handle_t *handle = payload->handle; CURL *curl = get_libcurl_handle(handle); - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK;
/* make sure these are NULL */ FREE(payload->tempfile_name); diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index f08df8b..4cac2d1 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -60,7 +60,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg) int retval;
ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; /* We only inspect packages from sync repositories */ ASSERT(pkg->origin == ALPM_PKG_FROM_SYNCDB, RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1)); @@ -184,196 +184,196 @@ struct pkg_operations default_pkg_ops = { const char SYMEXPORT *alpm_pkg_get_filename(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->filename; }
const char SYMEXPORT *alpm_pkg_get_base(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_base(pkg); }
const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->name; }
const char SYMEXPORT *alpm_pkg_get_version(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->version; }
alpm_pkgfrom_t SYMEXPORT alpm_pkg_get_origin(alpm_pkg_t *pkg) { - ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + ASSERT(pkg != NULL, return ALPM_PKG_FROM_ERROR); + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->origin; }
const char SYMEXPORT *alpm_pkg_get_desc(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_desc(pkg); }
const char SYMEXPORT *alpm_pkg_get_url(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_url(pkg); }
alpm_time_t SYMEXPORT alpm_pkg_get_builddate(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_builddate(pkg); }
alpm_time_t SYMEXPORT alpm_pkg_get_installdate(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_installdate(pkg); }
const char SYMEXPORT *alpm_pkg_get_packager(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_packager(pkg); }
const char SYMEXPORT *alpm_pkg_get_md5sum(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->md5sum; }
const char SYMEXPORT *alpm_pkg_get_sha256sum(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->sha256sum; }
const char SYMEXPORT *alpm_pkg_get_base64_sig(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->base64_sig; }
const char SYMEXPORT *alpm_pkg_get_arch(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_arch(pkg); }
off_t SYMEXPORT alpm_pkg_get_size(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->size; }
off_t SYMEXPORT alpm_pkg_get_isize(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_isize(pkg); }
alpm_pkgreason_t SYMEXPORT alpm_pkg_get_reason(alpm_pkg_t *pkg) { - ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + ASSERT(pkg != NULL, return ALPM_PKG_REASON_ERROR); + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_reason(pkg); }
alpm_pkgvalidation_t SYMEXPORT alpm_pkg_get_validation(alpm_pkg_t *pkg) { - ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + ASSERT(pkg != NULL, return ALPM_PKG_VALIDATION_ERROR); + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_validation(pkg); }
alpm_list_t SYMEXPORT *alpm_pkg_get_licenses(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_licenses(pkg); }
alpm_list_t SYMEXPORT *alpm_pkg_get_groups(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_groups(pkg); }
alpm_list_t SYMEXPORT *alpm_pkg_get_depends(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_depends(pkg); }
alpm_list_t SYMEXPORT *alpm_pkg_get_optdepends(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_optdepends(pkg); }
alpm_list_t SYMEXPORT *alpm_pkg_get_conflicts(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_conflicts(pkg); }
alpm_list_t SYMEXPORT *alpm_pkg_get_provides(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_provides(pkg); }
alpm_list_t SYMEXPORT *alpm_pkg_get_replaces(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_replaces(pkg); }
alpm_list_t SYMEXPORT *alpm_pkg_get_deltas(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->deltas; }
alpm_filelist_t SYMEXPORT *alpm_pkg_get_files(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_files(pkg); }
alpm_list_t SYMEXPORT *alpm_pkg_get_backup(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->get_backup(pkg); }
@@ -382,7 +382,7 @@ alpm_db_t SYMEXPORT *alpm_pkg_get_db(alpm_pkg_t *pkg) /* Sanity checks */ ASSERT(pkg != NULL, return NULL); ASSERT(pkg->origin != ALPM_PKG_FROM_FILE, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK;
return pkg->origin_data.db; } @@ -391,7 +391,7 @@ alpm_db_t SYMEXPORT *alpm_pkg_get_db(alpm_pkg_t *pkg) void SYMEXPORT *alpm_pkg_changelog_open(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->changelog_open(pkg); }
@@ -400,7 +400,7 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, const alpm_pkg_t *pkg, void *fp) { ASSERT(pkg != NULL, return 0); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->changelog_read(ptr, size, pkg, fp); }
@@ -408,7 +408,7 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, int SYMEXPORT alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->changelog_close(pkg, fp); }
@@ -416,7 +416,7 @@ int SYMEXPORT alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp) struct archive SYMEXPORT *alpm_pkg_mtree_open(alpm_pkg_t * pkg) { ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->mtree_open(pkg); }
@@ -425,7 +425,7 @@ int SYMEXPORT alpm_pkg_mtree_next(const alpm_pkg_t * pkg, struct archive *archiv struct archive_entry **entry) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->mtree_next(pkg, archive, entry); }
@@ -433,14 +433,14 @@ int SYMEXPORT alpm_pkg_mtree_next(const alpm_pkg_t * pkg, struct archive *archiv int SYMEXPORT alpm_pkg_mtree_close(const alpm_pkg_t * pkg, struct archive *archive) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->mtree_close(pkg, archive); }
int SYMEXPORT alpm_pkg_has_scriptlet(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK; return pkg->ops->has_scriptlet(pkg); }
@@ -448,7 +448,7 @@ static void find_requiredby(alpm_pkg_t *pkg, alpm_db_t *db, alpm_list_t **reqs, int optional) { const alpm_list_t *i; - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK;
for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { alpm_pkg_t *cachepkg = i->data; @@ -478,7 +478,7 @@ static alpm_list_t *compute_requiredby(alpm_pkg_t *pkg, int optional) alpm_db_t *db;
ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK;
if(pkg->origin == ALPM_PKG_FROM_FILE) { /* The sane option; search locally for things that require this. */ diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index 114d225..4dce542 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -130,7 +130,7 @@ struct __alpm_pkg_t { char *file; } origin_data;
- alpm_dbinfrq_t infolevel; + int infolevel; alpm_pkgvalidation_t validation; alpm_pkgfrom_t origin; alpm_pkgreason_t reason; diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c index 6557c20..527e763 100644 --- a/lib/libalpm/signing.c +++ b/lib/libalpm/signing.c @@ -771,7 +771,7 @@ int _alpm_check_pgp_helper(alpm_handle_t *handle, const char *path, if(ret && handle->pm_errno == ALPM_ERR_SIG_MISSING) { if(optional) { _alpm_log(handle, ALPM_LOG_DEBUG, "missing optional signature\n"); - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; ret = 0; } else { _alpm_log(handle, ALPM_LOG_DEBUG, "missing required signature\n"); @@ -931,7 +931,7 @@ int SYMEXPORT alpm_pkg_check_pgp_signature(alpm_pkg_t *pkg, { ASSERT(pkg != NULL, return -1); ASSERT(siglist != NULL, RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1)); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK;
return _alpm_gpgme_checksig(pkg->handle, pkg->filename, pkg->base64_sig, siglist); @@ -948,7 +948,7 @@ int SYMEXPORT alpm_db_check_pgp_signature(alpm_db_t *db, { ASSERT(db != NULL, return -1); ASSERT(siglist != NULL, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1)); - db->handle->pm_errno = 0; + db->handle->pm_errno = ALPM_ERR_OK;
return _alpm_gpgme_checksig(db->handle, _alpm_db_path(db), NULL, siglist); } diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 00b68d0..41b95f6 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -57,7 +57,7 @@ alpm_pkg_t SYMEXPORT *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_syn alpm_pkg_t *spkg = NULL;
ASSERT(pkg != NULL, return NULL); - pkg->handle->pm_errno = 0; + pkg->handle->pm_errno = ALPM_ERR_OK;
for(i = dbs_sync; !spkg && i; i = i->next) { alpm_db_t *db = i->data; @@ -460,7 +460,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) transaction. The packages will be removed from the actual transaction when the transaction packages are replaced with a dependency-reordered list below */ - handle->pm_errno = 0; + handle->pm_errno = ALPM_ERR_OK; if(data) { alpm_list_free_inner(*data, (alpm_list_fn_free)alpm_depmissing_free); @@ -1140,7 +1140,7 @@ static int check_validity(alpm_handle_t *handle, EVENT(handle, &event);
for(i = handle->trans->add; i; i = i->next, current++) { - struct validity v = { i->data, NULL, NULL, 0, 0, 0 }; + struct validity v = { i->data, NULL, NULL, ALPM_SIG_NONE, 0, 0 }; int percent = (int)(((double)current_bytes / total_bytes) * 100);
PROGRESS(handle, ALPM_PROGRESS_INTEGRITY_START, "", percent, @@ -1195,7 +1195,7 @@ static int check_validity(alpm_handle_t *handle, } alpm_list_free(errors);
- if(!handle->pm_errno) { + if(handle->pm_errno == ALPM_ERR_OK) { RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1); } return -1; @@ -1280,7 +1280,7 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data, EVENT(handle, &event);
if(errors) { - if(!handle->pm_errno) { + if(handle->pm_errno == ALPM_ERR_OK) { RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1); } return -1; diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 1398470..1d23864 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -418,7 +418,7 @@ cleanup: alpm_transflag_t SYMEXPORT alpm_trans_get_flags(alpm_handle_t *handle) { /* Sanity checks */ - CHECK_HANDLE(handle, return -1); + CHECK_HANDLE(handle, return ALPM_TRANS_FLAG_ERROR); ASSERT(handle->trans != NULL, RET_ERR(handle, ALPM_ERR_TRANS_NULL, -1));
return handle->trans->flags; diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 5a2c105..b9c5c17 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -77,7 +77,7 @@ void _alpm_alloc_fail(size_t size);
#define DOUBLE_EQ(x, y) (fabs((x) - (y)) < DBL_EPSILON)
-#define CHECK_HANDLE(handle, action) do { if(!(handle)) { action; } (handle)->pm_errno = 0; } while(0) +#define CHECK_HANDLE(handle, action) do { if(!(handle)) { action; } (handle)->pm_errno = ALPM_ERR_OK; } while(0)
/** Standard buffer size used throughout the library. */ #ifdef BUFSIZ diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 25de7af..a2d5555 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -328,7 +328,7 @@ int config_set_arch(const char *arch) static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage, alpm_siglevel_t *storage_mask, const char *file, int linenum) { - alpm_siglevel_t level = *storage, mask = *storage_mask; + int level = *storage, mask = *storage_mask; alpm_list_t *i; int ret = 0;
@@ -1005,7 +1005,7 @@ static int _parse_directive(const char *file, int linenum, const char *name, section->repo = calloc(sizeof(config_repo_t), 1); section->repo->name = strdup(name); section->repo->siglevel = ALPM_SIG_USE_DEFAULT; - section->repo->usage = 0; + section->repo->usage = ALPM_DB_USAGE_NONE; config->repos = alpm_list_add(config->repos, section->repo); } return 0; diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 2ddeadb..d7bc1bc 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -96,13 +96,13 @@ typedef struct __config_t { unsigned short noask; unsigned int ask; alpm_transflag_t flags; - alpm_siglevel_t siglevel; - alpm_siglevel_t localfilesiglevel; - alpm_siglevel_t remotefilesiglevel; + int siglevel; + int localfilesiglevel; + int remotefilesiglevel;
- alpm_siglevel_t siglevel_mask; - alpm_siglevel_t localfilesiglevel_mask; - alpm_siglevel_t remotefilesiglevel_mask; + int siglevel_mask; + int localfilesiglevel_mask; + int remotefilesiglevel_mask;
/* conf file options */ /* I Love Candy! */ diff --git a/src/pacman/database.c b/src/pacman/database.c index 0197903..a62c082 100644 --- a/src/pacman/database.c +++ b/src/pacman/database.c @@ -61,7 +61,7 @@ static int change_install_reason(alpm_list_t *targets) }
/* Lock database */ - if(trans_init(0, 0) == -1) { + if(trans_init(ALPM_TRANS_FLAG_NONE, 0) == -1) { return 1; }
diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index 043acf1..d107811 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -68,7 +68,7 @@ static void checkdbs(alpm_list_t *dbnames) { alpm_db_t *db = NULL; alpm_list_t *i; - const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; + const int level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
for(i = dbnames; i; i = alpm_list_next(i)) { const char *dbname = i->data; diff --git a/src/util/pactree.c b/src/util/pactree.c index 67be9f9..2463f40 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -128,7 +128,7 @@ static int register_syncs(void) FILE *fp; char *section = NULL; char line[LINE_MAX]; - const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; + const int level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
fp = fopen(configfile, "r"); if(!fp) { diff --git a/src/util/testpkg.c b/src/util/testpkg.c index 89e8dbd..b176e6b 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) alpm_handle_t *handle; alpm_errno_t err; alpm_pkg_t *pkg = NULL; - const alpm_siglevel_t level = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL; + const int level = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL;
if(argc != 2) { fprintf(stderr, "testpkg (pacman) v" PACKAGE_VERSION "\n\n" -- 2.9.3
On 28 Sep 2016, at 1:28 pm -0400, Andrew Gregory wrote:
On 09/03/16 at 10:14pm, ivy.foster@gmail.com wrote:
From: Ivy Foster <ivy.foster@gmail.com>
In many cases, it was enough to add error or "none" values to enums, to account for cases where functions returned either an enumerated value or 0/-1.
A common code pattern in pacman is to use enums to create bitfields representing various option combinations. Since they are not technically part of the enumerated type used to build them, these bitfields have been reassigned to type int.
Even though all of these changes are related our enum handling, there is a lot going on in this patch. I would prefer if it were broken up into more specific change sets.
Fair enough! I'll start working on that tonight.
* converting bitfield values to int
I think int is the correct type for bitfields, but it looks like you missed many. Enums like siglevel_t and usage_t are used exclusively in the construction of bitfields. I don't think we should really have any variables of those types anywhere.
That makes sense. I like the consistency, too. I'll do a more fine-grained search for those for the bitfield-to-int patch.
* adding ERR_OK
OK - libarchive and libcurl do this and I think it makes sense.
* adding NONE/ERROR to other enums
The addition of NONE values to enums appears to be unnecessary to me. I only see them being used as empty bitfield values, and, once we change those to int, using a literal 0 for those is just fine.
I'm not fond of adding ERROR values to every enum just so that we can return -1 for invalid input. Most of them look unnecessary because the relevant functions are actually returning bitfields and should be changed to return an int, making -1 a valid return value.
Cool, I'll do it that way instead. Thanks for the feedback! Ivy
participants (5)
-
Allan McRae
-
Andrew Gregory
-
Ivy Foster
-
ivy.foster@gmail.com
-
Martin Kühne