static inline void range_shrink(struct ashmem_range *range, size_t start, size_t end) { size_t pre = range_size(range); range->pgstart = start; range->pgend = end; if(range_on_lru(range)) { lru_count -= pre - range_size(range); } }
void DexInstruction::verify_encoding() const { auto test = m_count ? new DexInstruction(opcode()) : new DexInstruction(opcode(), 0); if (dests_size()) { test->set_dest(dest()); } for (unsigned i = 0; i < srcs_size(); i++) { test->set_src(i, src(i)); } if (has_range_base()) test->set_range_base(range_base()); if (has_range_size()) test->set_range_size(range_size()); if (has_arg_word_count()) test->set_arg_word_count(arg_word_count()); if (has_literal()) test->set_literal(literal()); if (has_offset()) test->set_offset(offset()); assert_log(m_opcode == test->m_opcode, "%x %x\n", m_opcode, test->m_opcode); for (unsigned i = 0; i < m_count; i++) { assert_log(m_arg[i] == test->m_arg[i], "(%x %x) (%x %x)", m_opcode, m_arg[i], test->m_opcode, test->m_arg[i]); } delete test; }
static VALUE range_enum_size(VALUE range, VALUE args, VALUE eobj) { return range_size(range); }
static char* test_range() { SemVersion ver; parse_version("1.2.3", &ver); VersionRange* range = init_version_range(); mu_assert("Range intialized", range != NULL); mu_assert("Range empty", range_size(range) == 0); add_version(range, &ver, 0); mu_assert("Range empty after adding invalid item", range_size(range) == 0); ver.cmp = COMPARE_GREATER; add_version(range, &ver, 0); int sz = range_size(range); mu_assert("Range after adding correct item", sz == 1); add_version(range, &ver, 0); sz = range_size(range); mu_assert("Range after adding another correct item", sz == 2); VersionRange* r = get_range_item(range, 0); mu_assert("First item min only", r != NULL && r->min_ver != NULL && r->max_ver == NULL); r = get_range_item(range, 1); mu_assert("Second item min only", r != NULL && r->min_ver != NULL && r->max_ver == NULL); r = get_range_item(range, 2); mu_assert("No third item", r == NULL); ver.cmp = COMPARE_LESSOREQUAL; add_version(range, &ver, 0); sz = range_size(range); mu_assert("Range after adding another pair", sz == 2); r = get_range_item(range, 0); mu_assert("First item full only", r != NULL && r->min_ver != NULL && r->max_ver != NULL); r = get_range_item(range, 1); mu_assert("Second item min only", r != NULL && r->min_ver != NULL && r->max_ver == NULL); r = get_range_item(range, 2); mu_assert("No third item", r == NULL); ver.cmp = COMPARE_GREATER; add_version(range, &ver, 0); sz = range_size(range); mu_assert("Range after adding extra min", sz == 3); ver.cmp = COMPARE_LESSOREQUAL; VersionRange* forth = add_version(range, &ver, 1); sz = range_size(range); mu_assert("Range after adding as new pair", sz == 4); r = get_range_item(range, 0); mu_assert("First item full only", r != NULL && r->min_ver != NULL && r->max_ver != NULL); r = get_range_item(range, 1); mu_assert("Second item min only", r != NULL && r->min_ver != NULL && r->max_ver == NULL); r = get_range_item(range, 3); mu_assert("Forth item maxonly", r != NULL && r->min_ver == NULL && r->max_ver != NULL); ver.cmp = COMPARE_LESS; int ok = complete_version_range(forth, &ver); mu_assert("No way to complete with the same condition", ok == SEMVER_ITEM_FULL); ver.cmp = COMPARE_GREATEROREQUAL; ok = complete_version_range(forth, &ver); mu_assert("Complete with the opposite condition", ok == SEMVER_OK); ok = complete_version_range(forth, &ver); mu_assert("No way to complete with the same condition 2", ok == SEMVER_ITEM_FULL); r = get_range_item(range, 3); mu_assert("Forth item full", r != NULL && r->min_ver != NULL && r->max_ver != NULL); sz = range_size(range); mu_assert("Size did not change", sz == 4); ver.cmp = COMPARE_LESS; add_version(range, &ver, 0); sz = range_size(range); mu_assert("Size no chage 2", sz == 4); r = get_range_item(range, 0); mu_assert("First item full", r != NULL && r->min_ver != NULL && r->max_ver != NULL); r = get_range_item(range, 1); mu_assert("Second item full", r != NULL && r->min_ver != NULL && r->max_ver != NULL); r = get_range_item(range, 2); mu_assert("Third item min only", r != NULL && r->min_ver != NULL && r->max_ver == NULL); free_version_range(&range); mu_assert("Range empty", range_size(range) == 0); return 0; }
int match_num_groups(match_t* match) { assert(match); return range_size(match->groups);; }
static inline void lru_del(struct ashmem_range *range) { list_del(&range->lru); lru_count -= range_size(range); }
static inline void lru_add(struct ashmem_range *range) { list_add_before(ashmem_lru_list, &range->lru); lru_count += range_size(range); }