Skip to content

Commit 5e4f35b

Browse files
committed
Fix term component projection JNI errors
1 parent 9de2cb2 commit 5e4f35b

3 files changed

Lines changed: 131 additions & 13 deletions

File tree

src/main/java/com/sri/yices/Yices.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public static int mkRationalConstant(BigInteger num, BigInteger den) {
396396

397397
public static SumComponent<?> sumComponent(int x, int idx) {
398398
SumComponent<?> result = null;
399-
if (Yices.termIsArithmetic(x)) {
399+
if (Yices.termIsSum(x)) {
400400
byte[] num = sumComponentNumAsBytes(x, idx);
401401
byte[] den = sumComponentDenAsBytes(x, idx);
402402
int term = sumComponentTerm(x, idx);
@@ -405,7 +405,7 @@ public static SumComponent<?> sumComponent(int x, int idx) {
405405
result = new SumComponent<>(new BigRational(num, den), term);
406406
}
407407
}
408-
if (Yices.termIsBitvector(x)) {
408+
if (Yices.termIsBvSum(x)) {
409409
boolean[] factor = bvSumComponentFactor(x, idx);
410410
int term = bvSumComponentTerm(x, idx);
411411

src/main/java/com/sri/yices/yicesJNI.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,7 +2659,7 @@ JNIEXPORT jbyteArray JNICALL Java_com_sri_yices_Yices_sumComponentDenAsBytes(JNI
26592659
}
26602660

26612661
JNIEXPORT jint JNICALL Java_com_sri_yices_Yices_sumComponentTerm(JNIEnv *env, jclass, jint x, jint idx) {
2662-
jint result;
2662+
jint result = -1;
26632663
mpq_t q;
26642664

26652665
mpq_init(q);
@@ -2674,21 +2674,25 @@ JNIEXPORT jbooleanArray JNICALL Java_com_sri_yices_Yices_bvSumComponentFactor(JN
26742674
jint t = -1;
26752675

26762676
int32_t n = yices_term_bitsize(x);
2677-
assert(n >= 0);
2677+
if (n < 0) {
2678+
return NULL;
2679+
}
26782680

26792681
if (n <= 64) {
26802682
// this should be the common case
26812683
int32_t a[64];
26822684
int32_t code = yices_bvsum_component(x, idx, a, &t);
2683-
assert(code >= 0);
2684-
result = convertToBoolArray(env, n, a);
2685+
if (code >= 0) {
2686+
result = convertToBoolArray(env, n, a);
2687+
}
26852688

26862689
} else {
26872690
try {
26882691
int32_t *tmp = new int32_t[n];
26892692
int32_t code = yices_bvsum_component(x, idx, tmp, &t);
2690-
assert(code >= 0);
2691-
result = convertToBoolArray(env, n, tmp);
2693+
if (code >= 0) {
2694+
result = convertToBoolArray(env, n, tmp);
2695+
}
26922696
delete [] tmp;
26932697
} catch (std::bad_alloc&) {
26942698
out_of_mem_exception(env);
@@ -2702,19 +2706,19 @@ JNIEXPORT jint JNICALL Java_com_sri_yices_Yices_bvSumComponentTerm(JNIEnv *env,
27022706
jint result = -1;
27032707

27042708
int32_t n = yices_term_bitsize(x);
2705-
assert(n >= 0);
2709+
if (n < 0) {
2710+
return result;
2711+
}
27062712

27072713
if (n <= 64) {
27082714
// this should be the common case
27092715
int32_t a[64];
2710-
int32_t code = yices_bvsum_component(x, idx, a, &result);
2711-
assert(code >= 0);
2716+
yices_bvsum_component(x, idx, a, &result);
27122717

27132718
} else {
27142719
try {
27152720
int32_t *tmp = new int32_t[n];
2716-
int32_t code = yices_bvsum_component(x, idx, tmp, &result);
2717-
assert(code >= 0);
2721+
yices_bvsum_component(x, idx, tmp, &result);
27182722
delete [] tmp;
27192723
} catch (std::bad_alloc&) {
27202724
out_of_mem_exception(env);

src/main/java/com/sri/yices/yicesJNIforWindows.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,120 @@ JNIEXPORT jint JNICALL Java_com_sri_yices_Yices_termProjArg(JNIEnv *env, jclass,
26302630
return yices_proj_arg(x);
26312631
}
26322632

2633+
JNIEXPORT jbyteArray JNICALL Java_com_sri_yices_Yices_sumComponentNumAsBytes(JNIEnv *env, jclass, jint x, jint idx) {
2634+
jbyteArray result = NULL;
2635+
mpq_t q;
2636+
jint t = -1;
2637+
2638+
mpq_init(q);
2639+
if (yices_sum_component(x, idx, q, &t) >= 0) {
2640+
result = mpz_to_byte_array(env, mpq_numref(q));
2641+
}
2642+
mpq_clear(q);
2643+
2644+
return result;
2645+
}
2646+
2647+
JNIEXPORT jbyteArray JNICALL Java_com_sri_yices_Yices_sumComponentDenAsBytes(JNIEnv *env, jclass, jint x, jint idx) {
2648+
jbyteArray result = NULL;
2649+
mpq_t q;
2650+
jint t = -1;
2651+
2652+
mpq_init(q);
2653+
if (yices_sum_component(x, idx, q, &t) >= 0) {
2654+
result = mpz_to_byte_array(env, mpq_denref(q));
2655+
}
2656+
mpq_clear(q);
2657+
2658+
return result;
2659+
}
2660+
2661+
JNIEXPORT jint JNICALL Java_com_sri_yices_Yices_sumComponentTerm(JNIEnv *env, jclass, jint x, jint idx) {
2662+
jint result = -1;
2663+
mpq_t q;
2664+
2665+
mpq_init(q);
2666+
yices_sum_component(x, idx, q, &result);
2667+
mpq_clear(q);
2668+
2669+
return result;
2670+
}
2671+
2672+
JNIEXPORT jbooleanArray JNICALL Java_com_sri_yices_Yices_bvSumComponentFactor(JNIEnv *env, jclass, jint x, jint idx) {
2673+
jbooleanArray result = NULL;
2674+
jint t = -1;
2675+
2676+
int32_t n = yices_term_bitsize(x);
2677+
if (n < 0) {
2678+
return NULL;
2679+
}
2680+
2681+
if (n <= 64) {
2682+
// this should be the common case
2683+
int32_t a[64];
2684+
int32_t code = yices_bvsum_component(x, idx, a, &t);
2685+
if (code >= 0) {
2686+
result = convertToBoolArray(env, n, a);
2687+
}
2688+
2689+
} else {
2690+
try {
2691+
int32_t *tmp = new int32_t[n];
2692+
int32_t code = yices_bvsum_component(x, idx, tmp, &t);
2693+
if (code >= 0) {
2694+
result = convertToBoolArray(env, n, tmp);
2695+
}
2696+
delete [] tmp;
2697+
} catch (std::bad_alloc&) {
2698+
out_of_mem_exception(env);
2699+
}
2700+
}
2701+
2702+
return result;
2703+
}
2704+
2705+
JNIEXPORT jint JNICALL Java_com_sri_yices_Yices_bvSumComponentTerm(JNIEnv *env, jclass, jint x, jint idx) {
2706+
jint result = -1;
2707+
2708+
int32_t n = yices_term_bitsize(x);
2709+
if (n < 0) {
2710+
return result;
2711+
}
2712+
2713+
if (n <= 64) {
2714+
// this should be the common case
2715+
int32_t a[64];
2716+
yices_bvsum_component(x, idx, a, &result);
2717+
2718+
} else {
2719+
try {
2720+
int32_t *tmp = new int32_t[n];
2721+
yices_bvsum_component(x, idx, tmp, &result);
2722+
delete [] tmp;
2723+
} catch (std::bad_alloc&) {
2724+
out_of_mem_exception(env);
2725+
}
2726+
}
2727+
2728+
return result;
2729+
}
2730+
2731+
JNIEXPORT jint JNICALL Java_com_sri_yices_Yices_productComponentTerm(JNIEnv *env, jclass, jint x, jint idx) {
2732+
uint32_t p = 0;
2733+
jint t = -1;
2734+
2735+
yices_product_component(x, idx, &t, &p);
2736+
return t;
2737+
}
2738+
2739+
JNIEXPORT jint JNICALL Java_com_sri_yices_Yices_productComponentPower(JNIEnv *env, jclass, jint x, jint idx) {
2740+
uint32_t p = 0;
2741+
jint t = -1;
2742+
2743+
yices_product_component(x, idx, &t, &p);
2744+
return p;
2745+
}
2746+
26332747
JNIEXPORT jint JNICALL Java_com_sri_yices_Yices_boolConstValue(JNIEnv *env, jclass, jint x) {
26342748
int32_t val;
26352749
jint result;

0 commit comments

Comments
 (0)