diff options
author | Ethan Vrhel <ethanvrhel@gmail.com> | 2021-12-03 14:43:12 -0800 |
---|---|---|
committer | Ethan Vrhel <ethanvrhel@gmail.com> | 2021-12-03 14:52:33 -0800 |
commit | 31a34ce0b6b944cc9a4ce6e6c4014f091e8338c5 (patch) | |
tree | a6e77f7d59539dc60ffedcea42784f9a7e3f035b /demos | |
parent | 668f84f1d260c4a1dc915624079c28fe845b5843 (diff) | |
download | ghostpdl-31a34ce0b6b944cc9a4ce6e6c4014f091e8338c5.tar.gz |
Fixed an init_with_args issue in Java
Diffstat (limited to 'demos')
-rw-r--r-- | demos/java/gsjava/src/com/artifex/gsjava/GSAPI.java | 10 | ||||
-rw-r--r-- | demos/java/gsjava/src/com/artifex/gsjava/GSInstance.java | 3 | ||||
-rw-r--r-- | demos/java/jni/gs_jni/com_artifex_gsjava_GSAPI.cpp | 11 | ||||
-rw-r--r-- | demos/java/mtdemo/Main.java | 12 | ||||
-rw-r--r-- | demos/java/mtdemo/Worker.java | 6 |
5 files changed, 30 insertions, 12 deletions
diff --git a/demos/java/gsjava/src/com/artifex/gsjava/GSAPI.java b/demos/java/gsjava/src/com/artifex/gsjava/GSAPI.java index 652d43562..6ab49bb2c 100644 --- a/demos/java/gsjava/src/com/artifex/gsjava/GSAPI.java +++ b/demos/java/gsjava/src/com/artifex/gsjava/GSAPI.java @@ -59,7 +59,7 @@ public class GSAPI { public static final long GS_NULL = 0L; /** - * Error codes + * Level 1 error codes */ public static final int GS_ERROR_OK = 0, GS_ERROR_UNKNOWNERROR = -1, @@ -89,7 +89,7 @@ public class GSAPI { GS_ERROR_VMERROR = -25; /** - * Error codes + * Level 2 error codes */ public static final int GS_ERROR_CONFIGURATION_ERROR = -26, GS_ERROR_UNDEFINEDRESOURCE = -27, @@ -97,6 +97,12 @@ public class GSAPI { GS_ERROR_INVALIDCONTEXT = -29, GS_ERROR_INVALID = -30; + /** + * Psuedo-errors used internally + */ + public static final int GS_ERROR_HIT_DETECTED = -59, + GS_ERROR_FATAL = -100; + public static final int GS_COLORS_NATIVE = (1 << 0), GS_COLORS_GRAY = (1 << 1), GS_COLORS_RGB = (1 << 2), diff --git a/demos/java/gsjava/src/com/artifex/gsjava/GSInstance.java b/demos/java/gsjava/src/com/artifex/gsjava/GSInstance.java index 0059e2cca..ff3dbafaa 100644 --- a/demos/java/gsjava/src/com/artifex/gsjava/GSInstance.java +++ b/demos/java/gsjava/src/com/artifex/gsjava/GSInstance.java @@ -106,9 +106,8 @@ public class GSInstance implements Iterable<GSInstance.GSParam<?>> { } public void delete_instance() { - if (instance != GS_NULL) - gsapi_delete_instance(instance); if (instance != GS_NULL) { + gsapi_delete_instance(instance); instance = GS_NULL; INSTANCES--; } diff --git a/demos/java/jni/gs_jni/com_artifex_gsjava_GSAPI.cpp b/demos/java/jni/gs_jni/com_artifex_gsjava_GSAPI.cpp index e6ce9f1d7..500f540a5 100644 --- a/demos/java/jni/gs_jni/com_artifex_gsjava_GSAPI.cpp +++ b/demos/java/jni/gs_jni/com_artifex_gsjava_GSAPI.cpp @@ -246,12 +246,16 @@ JNIEXPORT jint JNICALL Java_com_artifex_gsjava_GSAPI_gsapi_1init_1with_1args return throwNullPointerException(env, "argv"); char **cargv = jbyteArray2DToCharArray(env, argv); + callbacks::setJNIEnv(idata, env); int code = gsapi_init_with_args((void *)instance, argc, cargv); delete2DByteArray(argc, cargv); - idata->hasinit = true; - storeDispalyHandle(idata); + if (code == 0) + { + idata->hasinit = true; + storeDispalyHandle(idata); + } return code; } @@ -670,6 +674,9 @@ void storeDispalyHandle(GSInstanceData *idata) { static const char PARAM_NAME[] = "DisplayHandle"; + assert(idata); + assert(idata->instance); + char *param = NULL; int bytes = gsapi_get_param(idata->instance, PARAM_NAME, NULL, gs_spt_string); if (bytes == com_artifex_gsjava_GSAPI_GS_ERROR_UNDEFINED) diff --git a/demos/java/mtdemo/Main.java b/demos/java/mtdemo/Main.java index f91e5f9f8..4563388db 100644 --- a/demos/java/mtdemo/Main.java +++ b/demos/java/mtdemo/Main.java @@ -2,6 +2,8 @@ import com.artifex.gsjava.GSInstance; import java.io.File; +import java.util.Scanner; + public class Main { // The file we will read from @@ -10,13 +12,19 @@ public class Main { // The output directory public static final String OUTDIR = "pdfout"; + public static final boolean WAIT_FOR_INPUT = false; + public static void main(String[] args) { + if (WAIT_FOR_INPUT) { + System.out.print("Awaiting input: "); + new Scanner(System.in).nextLine(); + } // For multithreading, call this before any GSInstance objects // are created. GSInstance.setAllowMultithreading(true); // Parse first command line argument as thread count - int workerCount = 10; + int workerCount = 2; if (args.length > 0) { try { workerCount = Integer.parseInt(args[0]); @@ -46,4 +54,4 @@ public class Main { workers[i].start(); } } -}
\ No newline at end of file +} diff --git a/demos/java/mtdemo/Worker.java b/demos/java/mtdemo/Worker.java index 874eae957..53393cbad 100644 --- a/demos/java/mtdemo/Worker.java +++ b/demos/java/mtdemo/Worker.java @@ -77,10 +77,8 @@ public class Worker implements Runnable { // init_with_args will perform all the conversions int code = gsInstance.init_with_args(args); - if (code != GS_ERROR_OK) { - gsInstance.delete_instance(); + if (code != GS_ERROR_OK) throw new IllegalStateException("Failed to init with args (code = " + code + ")"); - } System.out.println("Worker " + thread.getName() + " completed."); } catch (Exception e) { @@ -126,4 +124,4 @@ public class Worker implements Runnable { } } } -}
\ No newline at end of file +} |