solver: increase score fields to 32-bits (from 16-bits)

We are having so many packages that they might overflow otherwise.
"ERROR: Preference overflow" was already reported.
cute-signatures
Timo Teräs 2013-04-29 14:13:25 +03:00
parent 4c08eca3bb
commit 84bfef1a6b
2 changed files with 31 additions and 39 deletions

View File

@ -17,24 +17,10 @@
#include "apk_provider_data.h" #include "apk_provider_data.h"
struct apk_score { struct apk_score {
union { uint32_t unsatisfied;
struct { uint32_t non_preferred_actions;
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ uint32_t non_preferred_pinnings;
unsigned short preference; uint32_t preference;
unsigned short non_preferred_pinnings;
unsigned short non_preferred_actions;
unsigned short unsatisfied;
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
unsigned short unsatisfied;
unsigned short non_preferred_actions;
unsigned short non_preferred_pinnings;
unsigned short preference;
#else
#error Unknown endianess.
#endif
};
uint64_t score;
};
}; };
struct apk_solver_name_state { struct apk_solver_name_state {

View File

@ -129,11 +129,15 @@ static solver_result_t push_decision(struct apk_solver_state *ss,
int branching_point, int branching_point,
int topology_position); int topology_position);
#ifdef DEBUG_CHECKS
static void addscore(struct apk_score *a, struct apk_score *b) static void addscore(struct apk_score *a, struct apk_score *b)
{ {
struct apk_score orig = *a; struct apk_score orig = *a;
a->score += b->score;
a->unsatisfied += b->unsatisfied;
a->non_preferred_actions += b->non_preferred_actions;
a->non_preferred_pinnings += b->non_preferred_pinnings;
a->preference += b->preference;
ASSERT(a->unsatisfied >= orig.unsatisfied, "Unsatisfied overflow"); ASSERT(a->unsatisfied >= orig.unsatisfied, "Unsatisfied overflow");
ASSERT(a->non_preferred_actions >= orig.non_preferred_actions, "Preferred action overflow"); ASSERT(a->non_preferred_actions >= orig.non_preferred_actions, "Preferred action overflow");
ASSERT(a->non_preferred_pinnings >= orig.non_preferred_pinnings, "Preferred pinning overflow"); ASSERT(a->non_preferred_pinnings >= orig.non_preferred_pinnings, "Preferred pinning overflow");
@ -143,38 +147,36 @@ static void addscore(struct apk_score *a, struct apk_score *b)
static void subscore(struct apk_score *a, struct apk_score *b) static void subscore(struct apk_score *a, struct apk_score *b)
{ {
struct apk_score orig = *a; struct apk_score orig = *a;
a->score -= b->score;
a->unsatisfied -= b->unsatisfied;
a->non_preferred_actions -= b->non_preferred_actions;
a->non_preferred_pinnings -= b->non_preferred_pinnings;
a->preference -= b->preference;
ASSERT(a->unsatisfied <= orig.unsatisfied, "Unsatisfied underflow"); ASSERT(a->unsatisfied <= orig.unsatisfied, "Unsatisfied underflow");
ASSERT(a->non_preferred_actions <= orig.non_preferred_actions, "Preferred action underflow"); ASSERT(a->non_preferred_actions <= orig.non_preferred_actions, "Preferred action underflow");
ASSERT(a->non_preferred_pinnings <= orig.non_preferred_pinnings, "Preferred pinning overflow"); ASSERT(a->non_preferred_pinnings <= orig.non_preferred_pinnings, "Preferred pinning overflow");
ASSERT(a->preference <= orig.preference, "Preference underflow"); ASSERT(a->preference <= orig.preference, "Preference underflow");
} }
#else
static void addscore(struct apk_score *a, struct apk_score *b)
{
a->score += b->score;
}
static void subscore(struct apk_score *a, struct apk_score *b)
{
a->score -= b->score;
}
#endif
static inline int cmpscore(struct apk_score *a, struct apk_score *b) static inline int cmpscore(struct apk_score *a, struct apk_score *b)
{ {
if (a->score < b->score) return -1; if (a->unsatisfied != b->unsatisfied)
if (a->score > b->score) return 1; return a->unsatisfied < b->unsatisfied ? -1 : 1;
if (a->non_preferred_actions != b->non_preferred_actions)
return a->non_preferred_actions < b->non_preferred_actions ? -1 : 1;
if (a->non_preferred_pinnings != b->non_preferred_pinnings)
return a->non_preferred_pinnings < b->non_preferred_pinnings ? -1 : 1;
if (a->preference != b->preference)
return a->preference < b->preference ? -1 : 1;
return 0; return 0;
} }
static inline int cmpscore2(struct apk_score *a1, struct apk_score *a2, struct apk_score *b) static inline int cmpscore2(struct apk_score *a1, struct apk_score *a2, struct apk_score *b)
{ {
struct apk_score a; struct apk_score a = *a1;
a.score = a1->score + a2->score; addscore(&a, a2);
if (a.score < b->score) return -1; return cmpscore(&a, b);
if (a.score > b->score) return 1;
return 0;
} }
static struct apk_package_state *pkg_to_ps(struct apk_package *pkg) static struct apk_package_state *pkg_to_ps(struct apk_package *pkg)
@ -1986,6 +1988,10 @@ void apk_solver_print_errors(struct apk_database *db,
char pkgtext[256]; char pkgtext[256];
int i, j; int i, j;
/* negative for hard failure without partial solution */
if (unsatisfiable <= 0)
return;
apk_name_array_init(&names); apk_name_array_init(&names);
apk_error("%d unsatisfiable dependencies:", unsatisfiable); apk_error("%d unsatisfiable dependencies:", unsatisfiable);