[PPL-devel] [GIT] ppl/ppl(master): Added static method Coefficient.ppl_bits() to Java interface.

Enea Zaffanella zaffanella at cs.unipr.it
Sun Apr 11 16:21:06 CEST 2010


Module: ppl/ppl
Branch: master
Commit: 96df33856cdb2d98f0117f8dc99c12dacb922a03
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=96df33856cdb2d98f0117f8dc99c12dacb922a03

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Sun Apr 11 16:17:44 2010 +0200

Added static method Coefficient.ppl_bits() to Java interface.
test04 in PIP_Problem_test1.java overflows when using 8-bit checked integers.
Fixed method PIP_TREE_Node.toString().

---

 interfaces/Java/jni/ppl_java_globals.cc            |   16 ++++++++++++++++
 .../Java/parma_polyhedra_library/Coefficient.java  |    3 +++
 .../parma_polyhedra_library/PIP_Tree_Node.java     |    3 +++
 .../Parma_Polyhedra_Library.java                   |    4 ----
 interfaces/Java/tests/PIP_Problem_test1.java       |   18 ++++++++++++++++++
 5 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/interfaces/Java/jni/ppl_java_globals.cc b/interfaces/Java/jni/ppl_java_globals.cc
index 8b28785..467ac21 100644
--- a/interfaces/Java/jni/ppl_java_globals.cc
+++ b/interfaces/Java/jni/ppl_java_globals.cc
@@ -96,6 +96,11 @@ Java_parma_1polyhedra_1library_By_1Reference_initIDs
   cached_FMIDs.By_Reference_init_ID = mID;
 }
 
+JNIEXPORT jint JNICALL
+Java_parma_1polyhedra_1library_Coefficient_ppl_1bits(JNIEnv*, jclass) {
+  return PPL_COEFFICIENT_BITS;
+}
+
 JNIEXPORT void JNICALL
 Java_parma_1polyhedra_1library_Coefficient_initIDs
 (JNIEnv* env, jclass j_coeff_class) {
@@ -2010,6 +2015,17 @@ Java_parma_1polyhedra_1library_PIP_1Tree_1Node_artificials
   return null;
 }
 
+JNIEXPORT jstring JNICALL
+Java_parma_1polyhedra_1library_PIP_1Tree_1Node_toString
+(JNIEnv* env, jobject j_this) {
+  PIP_Tree_Node* this_ptr
+    = reinterpret_cast<PIP_Tree_Node*>(get_ptr(env, j_this));
+  using namespace Parma_Polyhedra_Library::IO_Operators;
+  std::ostringstream s;
+  s << *this_ptr;
+  return env->NewStringUTF(s.str().c_str());
+}
+
 JNIEXPORT jobject JNICALL
 Java_parma_1polyhedra_1library_PIP_1Decision_1Node_child_1node
 (JNIEnv* env, jobject j_this, jboolean j_branch) {
diff --git a/interfaces/Java/parma_polyhedra_library/Coefficient.java b/interfaces/Java/parma_polyhedra_library/Coefficient.java
index 61aaf0f..4b89bcb 100644
--- a/interfaces/Java/parma_polyhedra_library/Coefficient.java
+++ b/interfaces/Java/parma_polyhedra_library/Coefficient.java
@@ -74,6 +74,9 @@ public class Coefficient {
 	return value;
     }
 
+    //! Returns the number of bits of PPL coefficients; 0 if unbounded.
+    public static native int ppl_bits();
+
     private static native void initIDs();
     static {
         initIDs();
diff --git a/interfaces/Java/parma_polyhedra_library/PIP_Tree_Node.java b/interfaces/Java/parma_polyhedra_library/PIP_Tree_Node.java
index e332188..433c442 100644
--- a/interfaces/Java/parma_polyhedra_library/PIP_Tree_Node.java
+++ b/interfaces/Java/parma_polyhedra_library/PIP_Tree_Node.java
@@ -75,4 +75,7 @@ public class PIP_Tree_Node extends PPL_Object {
     */
     public native Constraint_System constraints();
 
+    //! Returns a string representation of \p this.
+    public native String toString();
+
 }
diff --git a/interfaces/Java/parma_polyhedra_library/Parma_Polyhedra_Library.java b/interfaces/Java/parma_polyhedra_library/Parma_Polyhedra_Library.java
index 9c99cc1..e1738da 100644
--- a/interfaces/Java/parma_polyhedra_library/Parma_Polyhedra_Library.java
+++ b/interfaces/Java/parma_polyhedra_library/Parma_Polyhedra_Library.java
@@ -190,10 +190,6 @@ public class Parma_Polyhedra_Library {
       information.
     */
     public static native String banner();
-/*
-    public static native boolean
-      ppl_Termination_MS(C_Polyhedron p);
-*/
 
     //@} // Version Checking
 
diff --git a/interfaces/Java/tests/PIP_Problem_test1.java b/interfaces/Java/tests/PIP_Problem_test1.java
index d36b8e7..1140207 100644
--- a/interfaces/Java/tests/PIP_Problem_test1.java
+++ b/interfaces/Java/tests/PIP_Problem_test1.java
@@ -356,6 +356,19 @@ static {
         cs.add(c_4);
 
 	PIP_Problem pip = new PIP_Problem(4, cs, params);
+
+        // Known to overflow if PPL uses 8-bits checked integers.
+        try {
+            pip.solve();
+        }
+        catch (Overflow_Error_Exception ex) {
+            if (Coefficient.ppl_bits() != 8)
+                throw ex;
+            PPL_Test.println_if_noisy("Expected overflow exception caught:");
+            PPL_Test.println_if_noisy(ex.getMessage());
+            return true;
+        }
+
         PIP_Problem_Status pip_status = pip.solve();
         boolean ok = (pip_status == PIP_Problem_Status.OPTIMIZED_PIP_PROBLEM);
         if (!ok)
@@ -365,6 +378,11 @@ static {
         if (!ok)
           return false;
 
+        PPL_Test.println_if_noisy();
+        PPL_Test.println_if_noisy("Testing toString():");
+        PPL_Test.println_if_noisy(solution.toString());
+        PPL_Test.println_if_noisy();
+
         PIP_Decision_Node root = solution.as_decision();
         if (root == null || !root.OK())
           return false;




More information about the PPL-devel mailing list