Extend assertions by checking passed in proplib type.

This commit is contained in:
Juan RP 2011-10-19 16:53:38 +02:00
parent a80df68b15
commit 9fb3c38aa2
17 changed files with 55 additions and 31 deletions

View File

@ -46,6 +46,8 @@ xbps_init_virtual_pkgs(struct xbps_handle *xh)
prop_string_t vpkgdir;
char *vpkgfile;
assert(xh != NULL);
if (prop_object_type(xh->confdir) != PROP_TYPE_STRING) {
vpkgdir = prop_string_create_cstring(XBPS_SYSCONF_PATH);
prop_string_append_cstring(vpkgdir, "/");

View File

@ -42,7 +42,7 @@ xbps_entry_is_a_conf_file(prop_dictionary_t propsd,
char *cffile;
int rv = 0;
assert(propsd != NULL);
assert(prop_object_type(propsd) == PROP_TYPE_DICTIONARY);
assert(entry_pname != NULL);
if (!prop_dictionary_get(propsd, "conf_files"))
@ -89,7 +89,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
char *buf, *sha256_cur = NULL, *sha256_orig = NULL;
int rv = 0;
assert(filesd != NULL);
assert(prop_object_type(filesd) == PROP_TYPE_DICTIONARY);
assert(entry != NULL);
assert(entry_pname != NULL);
assert(pkgname != NULL);

View File

@ -55,6 +55,7 @@ remove_pkg_metadata(const char *pkgname, const char *rootdir)
int rv = 0;
assert(pkgname != NULL);
assert(rootdir != NULL);
metadir = xbps_xasprintf("%s/%s/metadata/%s", rootdir,
XBPS_META_PATH, pkgname);

View File

@ -50,6 +50,8 @@ xbps_register_pkg(prop_dictionary_t pkgrd)
int rv = 0;
bool autoinst = false;
assert(prop_object_type(pkgrd) == PROP_TYPE_DICTIONARY);
xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s",
prop_string_cstring_nocopy(xhp->rootdir),

View File

@ -81,7 +81,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
char *path = NULL;
int rv = 0;
assert(dict != NULL);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(key != NULL);
xhp = xbps_handle_get();

View File

@ -48,8 +48,8 @@ xbps_remove_obsoletes(prop_dictionary_t oldd, prop_dictionary_t newd)
int rv = 0;
bool found, dodirs = false, dolinks = false;
assert(oldd != NULL);
assert(newd != NULL);
assert(prop_object_type(oldd) == PROP_TYPE_DICTIONARY);
assert(prop_object_type(newd) == PROP_TYPE_DICTIONARY);
again:
iter = xbps_array_iter_from_dict(oldd, array_str);

View File

@ -43,6 +43,9 @@ xbps_repository_pkg_replaces(prop_dictionary_t transd,
const char *pattern, *pkgname, *curpkgname;
bool instd_auto = false;
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY);
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
replaces = prop_dictionary_get(pkg_repod, "replaces");
if (replaces == NULL || prop_array_count(replaces) == 0)
return 0;

View File

@ -38,6 +38,8 @@ add_pkg_into_reqby(prop_dictionary_t pkgd, const char *pkgver)
prop_string_t reqstr;
bool alloc = false;
assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY);
if ((reqby = prop_dictionary_get(pkgd, "requiredby")) == NULL) {
alloc = true;
if ((reqby = prop_array_create()) == NULL)
@ -150,8 +152,8 @@ xbps_requiredby_pkg_add(prop_array_t pkgs_array, prop_dictionary_t pkgd)
const char *pkgver, *str;
int rv = 0;
assert(pkgs_array != NULL);
assert(pkgd != NULL);
assert(prop_object_type(pkgs_array) == PROP_TYPE_ARRAY);
assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY);
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
pkg_rdeps = prop_dictionary_get(pkgd, "run_depends");

View File

@ -59,7 +59,7 @@ set_new_state(prop_dictionary_t dict, pkg_state_t state)
const struct state *stp;
const char *pkgname;
assert(dict != NULL);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
for (stp = states; stp->string != NULL; stp++)
if (state == stp->number)
@ -85,7 +85,7 @@ get_state(prop_dictionary_t dict)
const struct state *stp;
const char *state_str;
assert(dict != NULL);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
if (!prop_dictionary_get_cstring_nocopy(dict,
"state", &state_str))
@ -121,7 +121,7 @@ xbps_pkg_state_installed(const char *pkgname, pkg_state_t *state)
int
xbps_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t *state)
{
assert(dict != NULL);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(state != NULL);
if ((*state = get_state(dict)) == 0)
@ -133,7 +133,7 @@ xbps_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t *state)
int
xbps_set_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t state)
{
assert(dict != NULL);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
return set_new_state(dict, state);
}

View File

@ -165,8 +165,8 @@ unpack_archive(prop_dictionary_t pkg_repod,
int rv, flags;
bool preserve, update;
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
assert(ar != NULL);
assert(pkg_repod != NULL);
assert(pkgname != NULL);
assert(version != NULL);
@ -467,7 +467,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
char *bpkg;
int rv = 0;
assert(pkg_repod != NULL);
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &version);

View File

@ -50,7 +50,7 @@ find_pkg_in_array(prop_array_t array,
prop_object_t obj = NULL;
const char *pkgver, *dpkgn;
assert(array != NULL);
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(str != NULL);
iter = prop_array_iterator(array);
@ -172,7 +172,7 @@ find_virtualpkg_user_in_array(prop_array_t array,
prop_object_iterator_t iter;
const char *pkgver, *virtualpkg;
assert(array != NULL);
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(str != NULL);
virtualpkg = find_virtualpkg_user_in_conf(str, bypattern);
@ -201,7 +201,7 @@ find_virtualpkg_user_in_dict(prop_dictionary_t d,
{
prop_array_t array;
assert(d != NULL);
assert(prop_object_type(d) == PROP_TYPE_DICTIONARY);
assert(str != NULL);
assert(key != NULL);
@ -221,7 +221,7 @@ find_pkg_in_dict(prop_dictionary_t d,
{
prop_array_t array;
assert(d != NULL);
assert(prop_object_type(d) == PROP_TYPE_DICTIONARY);
assert(str != NULL);
assert(key != NULL);

View File

@ -47,6 +47,8 @@ xbps_match_virtual_pkg_in_dict(prop_dictionary_t d,
prop_array_t provides;
bool found = false;
assert(prop_object_type(d) == PROP_TYPE_DICTIONARY);
if ((provides = prop_dictionary_get(d, "provides"))) {
if (bypattern)
found = xbps_match_pkgpattern_in_array(provides, str);
@ -65,7 +67,7 @@ match_string_in_array(prop_array_t array, const char *str, int mode)
char *curpkgname;
bool found = false;
assert(array != NULL);
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(str != NULL);
iter = prop_array_iterator(array);

View File

@ -48,6 +48,8 @@ remove_string_from_array(prop_array_t array, const char *str, int mode)
size_t i, idx = 0;
bool found = false;
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
for (i = 0; i < prop_array_count(array); i++) {
obj = prop_array_get(array, i);
if (mode == 0) {
@ -111,7 +113,7 @@ xbps_remove_pkg_from_dict_by_name(prop_dictionary_t dict,
{
prop_array_t array;
assert(dict != NULL);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(key != NULL);
assert(pkgname != NULL);

View File

@ -39,8 +39,8 @@ store_dependency(prop_dictionary_t transd, prop_dictionary_t repo_pkgd)
int rv = 0;
pkg_state_t state = 0;
assert(transd != NULL);
assert(repo_pkgd != NULL);
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY);
assert(prop_object_type(repo_pkgd) == PROP_TYPE_DICTIONARY);
/*
* Get some info about dependencies and current repository.
*/
@ -122,7 +122,7 @@ add_missing_reqdep(prop_array_t missing_rdeps, const char *reqpkg)
bool add_pkgdep, pkgfound, update_pkgdep;
int rv = 0;
assert(missing_rdeps != NULL);
assert(prop_object_type(missing_rdeps) == PROP_TYPE_ARRAY);
assert(reqpkg != NULL);
add_pkgdep = update_pkgdep = pkgfound = false;
@ -214,6 +214,10 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
char *pkgname;
int rv = 0;
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY);
assert(prop_object_type(mrdeps) == PROP_TYPE_ARRAY);
assert(prop_object_type(pkg_rdeps_array) == PROP_TYPE_ARRAY);
if (depth >= MAX_DEPTH)
return ELOOP;
@ -445,9 +449,9 @@ xbps_repository_find_pkg_deps(prop_dictionary_t transd,
const char *pkgver;
int rv = 0;
assert(transd != NULL);
assert(mdeps != NULL);
assert(repo_pkgd != NULL);
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY);
assert(prop_object_type(mdeps) == PROP_TYPE_ARRAY);
assert(prop_object_type(repo_pkgd) == PROP_TYPE_DICTIONARY);
pkg_rdeps = prop_dictionary_get(repo_pkgd, "run_depends");
if (pkg_rdeps == NULL)

View File

@ -48,6 +48,8 @@ repo_find_virtualpkg_cb(struct repository_pool_index *rpi, void *arg, bool *done
{
struct repo_pool_fpkg *rpf = arg;
assert(rpi != NULL);
if (rpf->bypattern) {
rpf->pkgd =
xbps_find_virtualpkg_conf_in_dict_by_pattern(rpi->rpi_repod,
@ -77,6 +79,8 @@ repo_find_pkg_cb(struct repository_pool_index *rpi, void *arg, bool *done)
{
struct repo_pool_fpkg *rpf = arg;
assert(rpi != NULL);
if (rpf->bypattern) {
rpf->pkgd = xbps_find_pkg_in_dict_by_pattern(rpi->rpi_repod,
"packages", rpf->pattern);
@ -122,6 +126,8 @@ repo_find_best_pkg_cb(struct repository_pool_index *rpi,
prop_dictionary_t instpkgd;
const char *instver, *repover;
assert(rpi != NULL);
rpf->pkgd = xbps_find_pkg_in_dict_by_name(rpi->rpi_repod,
"packages", rpf->pattern);
if (rpf->pkgd == NULL) {

View File

@ -248,7 +248,7 @@ xbps_path_from_repository_uri(prop_dictionary_t pkg_repod, const char *repoloc)
const char *filen, *arch;
char *lbinpkg = NULL;
assert(pkg_repod != NULL);
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
assert(repoloc != NULL);
if (!prop_dictionary_get_cstring_nocopy(pkg_repod,
@ -278,13 +278,13 @@ xbps_path_from_repository_uri(prop_dictionary_t pkg_repod, const char *repoloc)
}
bool
xbps_pkg_has_rundeps(prop_dictionary_t pkg)
xbps_pkg_has_rundeps(prop_dictionary_t pkgd)
{
prop_array_t array;
assert(pkg != NULL);
assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY);
array = prop_dictionary_get(pkg, "run_depends");
array = prop_dictionary_get(pkgd, "run_depends");
if (array && prop_array_count(array) > 0)
return true;

View File

@ -145,7 +145,7 @@ xbps_file_hash_dictionary(prop_dictionary_t d,
prop_object_iterator_t iter;
const char *curfile, *sha256;
assert(d != NULL);
assert(prop_object_type(d) == PROP_TYPE_DICTIONARY);
assert(key != NULL);
assert(file != NULL);
@ -181,7 +181,7 @@ xbps_file_hash_check_dictionary(prop_dictionary_t d,
const char *sha256d;
int rv;
assert(d != NULL);
assert(prop_object_type(d) == PROP_TYPE_DICTIONARY);
assert(key != NULL);
assert(file != NULL);